mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
_alpm_lstat: only duplicate string if necessary
The vast majority of the time we will just be passing the same string value on to the lstat() call. The only time we need to duplicate it is if the path ends in '/'. In one run using a profiler, only 400 of the 200,000 calls (0.2%) required the string to be copied first. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
451cd2c88d
commit
9d6568da0f
@ -631,17 +631,18 @@ const char *_alpm_filecache_setup(void)
|
||||
int _alpm_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
char *newpath = strdup(path);
|
||||
size_t len = strlen(newpath);
|
||||
size_t len = strlen(path);
|
||||
|
||||
/* strip the trailing slash if one exists */
|
||||
if(len != 0 && newpath[len - 1] == '/') {
|
||||
newpath[len - 1] = '\0';
|
||||
if(len != 0 && path[len - 1] == '/') {
|
||||
char *newpath = strdup(path);
|
||||
newpath[len - 1] = '\0';
|
||||
ret = lstat(newpath, buf);
|
||||
free(newpath);
|
||||
} else {
|
||||
ret = lstat(path, buf);
|
||||
}
|
||||
|
||||
ret = lstat(newpath, buf);
|
||||
|
||||
FREE(newpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user