mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-16 22:35:09 -05:00
Improve mbasename performance
Rather than roll our own, use strrchr() instead, which glibc may have a better implementation than the simple iteration method we were using. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
d16a5ae7dd
commit
4d291508c2
@ -109,8 +109,8 @@ static int query_fileowner(alpm_list_t *targets)
|
|||||||
for(t = targets; t; t = alpm_list_next(t)) {
|
for(t = targets; t; t = alpm_list_next(t)) {
|
||||||
int found = 0;
|
int found = 0;
|
||||||
filename = strdup(alpm_list_getdata(t));
|
filename = strdup(alpm_list_getdata(t));
|
||||||
char *bname, *dname, *rpath;
|
char *dname, *rpath;
|
||||||
const char *root;
|
const char *root, *bname;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
alpm_list_t *i, *j;
|
alpm_list_t *i, *j;
|
||||||
|
|
||||||
|
@ -157,25 +157,17 @@ int rmrf(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Parse the basename of a program from a path.
|
/** Parse the basename of a program from a path.
|
||||||
* Grabbed from the uClibc source.
|
|
||||||
* @param path path to parse basename from
|
* @param path path to parse basename from
|
||||||
*
|
*
|
||||||
* @return everything following the final '/'
|
* @return everything following the final '/'
|
||||||
*/
|
*/
|
||||||
char *mbasename(const char *path)
|
const char *mbasename(const char *path)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *last = strrchr(path, '/');
|
||||||
const char *p;
|
if(last) {
|
||||||
|
return(last + 1);
|
||||||
p = s = path;
|
|
||||||
|
|
||||||
while (*s) {
|
|
||||||
if (*s++ == '/') {
|
|
||||||
p = s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return(path);
|
||||||
return (char *)p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parse the dirname of a program from a path.
|
/** Parse the dirname of a program from a path.
|
||||||
|
@ -44,7 +44,7 @@ int trans_release(void);
|
|||||||
int needs_root(void);
|
int needs_root(void);
|
||||||
int getcols(void);
|
int getcols(void);
|
||||||
int rmrf(const char *path);
|
int rmrf(const char *path);
|
||||||
char *mbasename(const char *path);
|
const char *mbasename(const char *path);
|
||||||
char *mdirname(const char *path);
|
char *mdirname(const char *path);
|
||||||
void indentprint(const char *str, int indent);
|
void indentprint(const char *str, int indent);
|
||||||
char *strtoupper(char *str);
|
char *strtoupper(char *str);
|
||||||
|
Loading…
Reference in New Issue
Block a user