Issue 19484 - Fix it so that DirEntry on POSIX only calls lstat once
Summary: Fix it so that DirEntry on POSIX only calls lstat once
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-13 23:37 UTC by Jonathan M Davis
Modified: 2024-12-01 16:34 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2018-12-13 23:37:32 UTC
On POSIX, DirEntry's constructor calls exists to verify that the file exists and then throws if it doesn't - which makes perfect sense until you look at what exists does. exists calls lstat, which is fine in and of itself, but calling exists means that that information is thrown away, whereas DirEntry then later calls lstat again when certain functions are called. It has the _didLStat member to keep track of whether it's called lstat yet, so it avoids calling it multiple times when the properties on it are used which require it, but it would be more efficient to just call lstat directly in the constructor and always save the result. If lstat fails, the exception can be thrown like it is now, but by checking the result of lstat directly rather than using exists, we remove the need for _didLStat, and we make it so that lstat is always called exactly once instead of being called once if the information from lstat isn't needed later or twice if it is.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:34:40 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9768

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB