diff options
author | Thomas Martitz <kugel@rockbox.org> | 2014-02-24 23:13:00 +0100 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2014-02-24 23:13:00 +0100 |
commit | 5fd8dd1321bd3513e0b03ef9474d88b2a8161c16 (patch) | |
tree | cff1d8f613110bcc1b008f44ea6a76833c724bdc | |
parent | c27c3f10fd8c32e837c1f11176dc7223542bda6d (diff) | |
download | rockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.tar.gz rockbox-5fd8dd1321bd3513e0b03ef9474d88b2a8161c16.zip |
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.c | 41 |
1 files changed, 23 insertions, 18 deletions
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) | |||
300 | #endif | 300 | #endif |
301 | snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name); | 301 | snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name); |
302 | 302 | ||
303 | if (!stat(path, &s)) | ||
304 | { | ||
305 | if (S_ISDIR(s.st_mode)) | ||
306 | ret.attribute |= ATTR_DIRECTORY; | ||
307 | |||
308 | ret.size = s.st_size; | ||
309 | tm = localtime(&(s.st_mtime)); | ||
310 | } | ||
311 | |||
312 | if (!lstat(path, &s) && S_ISLNK(s.st_mode)) | ||
313 | ret.attribute |= ATTR_LINK; | ||
314 | 303 | ||
315 | if (tm) | 304 | if (!lstat(path, &s)) |
316 | { | 305 | { |
317 | ret.wrtdate = ((tm->tm_year - 80) << 9) | | 306 | int err = 0; |
318 | ((tm->tm_mon + 1) << 5) | | 307 | if (S_ISLNK(s.st_mode)) |
319 | tm->tm_mday; | 308 | { |
320 | ret.wrttime = (tm->tm_hour << 11) | | 309 | ret.attribute |= ATTR_LINK; |
321 | (tm->tm_min << 5) | | 310 | err = stat(path, &s); |
322 | (tm->tm_sec >> 1); | 311 | } |
312 | if (!err) | ||
313 | { | ||
314 | if (S_ISDIR(s.st_mode)) | ||
315 | ret.attribute |= ATTR_DIRECTORY; | ||
316 | |||
317 | ret.size = s.st_size; | ||
318 | if ((tm = localtime(&(s.st_mtime)))) | ||
319 | { | ||
320 | ret.wrtdate = ((tm->tm_year - 80) << 9) | | ||
321 | ((tm->tm_mon + 1) << 5) | | ||
322 | tm->tm_mday; | ||
323 | ret.wrttime = (tm->tm_hour << 11) | | ||
324 | (tm->tm_min << 5) | | ||
325 | (tm->tm_sec >> 1); | ||
326 | } | ||
327 | } | ||
323 | } | 328 | } |
324 | 329 | ||
325 | return ret; | 330 | return ret; |