From 5fd8dd1321bd3513e0b03ef9474d88b2a8161c16 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Mon, 24 Feb 2014 23:13:00 +0100 Subject: application: Speed up dir_get_info() further. It's quite rare that it is called for a symlink to a directory. But it only needs a second syscall to stat() if that happened. Therefore speed up the common case by avoiding an unecessary second syscall. Change-Id: I911105f76631ebccc7696a1540e9cf069a706000 --- firmware/common/rbpaths.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'firmware/common') diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c index c59ef7cf65..7632b70306 100644 --- a/firmware/common/rbpaths.c +++ b/firmware/common/rbpaths.c @@ -300,26 +300,31 @@ struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir) #endif snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name); - if (!stat(path, &s)) - { - if (S_ISDIR(s.st_mode)) - ret.attribute |= ATTR_DIRECTORY; - - ret.size = s.st_size; - tm = localtime(&(s.st_mtime)); - } - - if (!lstat(path, &s) && S_ISLNK(s.st_mode)) - ret.attribute |= ATTR_LINK; - if (tm) + if (!lstat(path, &s)) { - ret.wrtdate = ((tm->tm_year - 80) << 9) | - ((tm->tm_mon + 1) << 5) | - tm->tm_mday; - ret.wrttime = (tm->tm_hour << 11) | - (tm->tm_min << 5) | - (tm->tm_sec >> 1); + int err = 0; + if (S_ISLNK(s.st_mode)) + { + ret.attribute |= ATTR_LINK; + err = stat(path, &s); + } + if (!err) + { + if (S_ISDIR(s.st_mode)) + ret.attribute |= ATTR_DIRECTORY; + + ret.size = s.st_size; + if ((tm = localtime(&(s.st_mtime)))) + { + ret.wrtdate = ((tm->tm_year - 80) << 9) | + ((tm->tm_mon + 1) << 5) | + tm->tm_mday; + ret.wrttime = (tm->tm_hour << 11) | + (tm->tm_min << 5) | + (tm->tm_sec >> 1); + } + } } return ret; -- cgit v1.2.3