FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-09-2011, 07:13 PM
Dan McGee
 
Default _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>
---
lib/libalpm/util.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 9a8f06d..357ce50 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -636,17 +636,18 @@ const char *_alpm_filecache_setup(pmhandle_t *handle)
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] = '';
+ if(len != 0 && path[len - 1] == '/') {
+ char *newpath = strdup(path);
+ newpath[len - 1] = '';
+ ret = lstat(newpath, buf);
+ free(newpath);
+ } else {
+ ret = lstat(path, buf);
}

- ret = lstat(newpath, buf);
-
- FREE(newpath);
return ret;
}

--
1.7.5.2
 

Thread Tools




All times are GMT. The time now is 06:14 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org