mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-14 15:42:28 -05:00
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
This commit is contained in:
parent
c27c3f10fd
commit
5fd8dd1321
1 changed files with 23 additions and 18 deletions
|
|
@ -300,26 +300,31 @@ struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
|
||||||
#endif
|
#endif
|
||||||
snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
|
snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
|
||||||
|
|
||||||
if (!stat(path, &s))
|
|
||||||
|
if (!lstat(path, &s))
|
||||||
{
|
{
|
||||||
if (S_ISDIR(s.st_mode))
|
int err = 0;
|
||||||
ret.attribute |= ATTR_DIRECTORY;
|
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;
|
ret.size = s.st_size;
|
||||||
tm = localtime(&(s.st_mtime));
|
if ((tm = localtime(&(s.st_mtime))))
|
||||||
}
|
{
|
||||||
|
ret.wrtdate = ((tm->tm_year - 80) << 9) |
|
||||||
if (!lstat(path, &s) && S_ISLNK(s.st_mode))
|
((tm->tm_mon + 1) << 5) |
|
||||||
ret.attribute |= ATTR_LINK;
|
tm->tm_mday;
|
||||||
|
ret.wrttime = (tm->tm_hour << 11) |
|
||||||
if (tm)
|
(tm->tm_min << 5) |
|
||||||
{
|
(tm->tm_sec >> 1);
|
||||||
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;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue