diff options
author | Dan McGee <dan@archlinux.org> | 2011-01-22 21:20:42 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-01-22 23:34:42 +0100 |
commit | 4d291508c2c24d058d0e00ca9588c6c81b24bc92 (patch) | |
tree | 2f37718b5fcc1a70eed069f459b5548a73eb7465 /src/pacman/util.c | |
parent | d16a5ae7ddf358c45280a56bc81ed67841a7476f (diff) | |
download | pacman-4d291508c2c24d058d0e00ca9588c6c81b24bc92.tar.gz pacman-4d291508c2c24d058d0e00ca9588c6c81b24bc92.tar.xz |
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>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index d91d1d43..0377bf79 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -157,25 +157,17 @@ int rmrf(const char *path) } /** Parse the basename of a program from a path. -* Grabbed from the uClibc source. * @param path path to parse basename from * * @return everything following the final '/' */ -char *mbasename(const char *path) +const char *mbasename(const char *path) { - const char *s; - const char *p; - - p = s = path; - - while (*s) { - if (*s++ == '/') { - p = s; - } + const char *last = strrchr(path, '/'); + if(last) { + return(last + 1); } - - return (char *)p; + return(path); } /** Parse the dirname of a program from a path. |