summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-02-24 23:13:00 +0100
committerThomas Martitz <kugel@rockbox.org>2014-02-24 23:13:00 +0100
commit5fd8dd1321bd3513e0b03ef9474d88b2a8161c16 (patch)
treecff1d8f613110bcc1b008f44ea6a76833c724bdc
parentc27c3f10fd8c32e837c1f11176dc7223542bda6d (diff)
downloadrockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.zip
rockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.tar.gz
rockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.tar.bz2
rockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.tar.xz
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
-rw-r--r--firmware/common/rbpaths.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index c59ef7c..7632b70 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;