diff options
author | Bastien Bouclet | 2019-10-31 21:35:41 +0100 |
---|---|---|
committer | Bastien Bouclet | 2019-10-31 21:35:41 +0100 |
commit | 8fb57967d75b5ef9911fbbbf15eb25b43458c997 (patch) | |
tree | 8ca7d224f3d346ef66469c8a98f957055ff1cfc2 /backends/fs | |
parent | 17173f6dacd7591b237b6f03b9d5c8f21d3d6335 (diff) | |
download | scummvm-rg350-8fb57967d75b5ef9911fbbbf15eb25b43458c997.tar.gz scummvm-rg350-8fb57967d75b5ef9911fbbbf15eb25b43458c997.tar.bz2 scummvm-rg350-8fb57967d75b5ef9911fbbbf15eb25b43458c997.zip |
3DS: Avoid stat calls in DrivePOSIXFilesystemNode
Diffstat (limited to 'backends/fs')
-rw-r--r-- | backends/fs/posix-drives/posix-drives-fs.cpp | 33 | ||||
-rw-r--r-- | backends/fs/posix-drives/posix-drives-fs.h | 1 | ||||
-rw-r--r-- | backends/fs/posix/posix-fs.h | 2 |
3 files changed, 29 insertions, 7 deletions
diff --git a/backends/fs/posix-drives/posix-drives-fs.cpp b/backends/fs/posix-drives/posix-drives-fs.cpp index 683ab190ae..d48792e2ff 100644 --- a/backends/fs/posix-drives/posix-drives-fs.cpp +++ b/backends/fs/posix-drives/posix-drives-fs.cpp @@ -53,10 +53,8 @@ DrivePOSIXFilesystemNode::DrivePOSIXFilesystemNode(const DrivesArray &drives) : _isValid = false; } -AbstractFSNode *DrivePOSIXFilesystemNode::getChild(const Common::String &n) const { - if (!_isPseudoRoot) { - return POSIXFilesystemNode::getChild(n); - } +DrivePOSIXFilesystemNode *DrivePOSIXFilesystemNode::getChildWithKnownType(const Common::String &n, bool isDirectory) const { + assert(_isDirectory); // Make sure the string contains no slashes assert(!n.contains('/')); @@ -66,7 +64,21 @@ AbstractFSNode *DrivePOSIXFilesystemNode::getChild(const Common::String &n) cons newPath += '/'; newPath += n; - return makeNode(newPath); + DrivePOSIXFilesystemNode *child = new DrivePOSIXFilesystemNode(_drives); + child->_path = newPath; + child->_isValid = true; + child->_isPseudoRoot = false; + child->_isDirectory = isDirectory; + child->_displayName = n; + + return child; +} + +AbstractFSNode *DrivePOSIXFilesystemNode::getChild(const Common::String &n) const { + DrivePOSIXFilesystemNode *child = getChildWithKnownType(n, false); + child->setFlags(); + + return child; } bool DrivePOSIXFilesystemNode::getChildren(AbstractFSList &list, AbstractFSNode::ListMode mode, bool hidden) const { @@ -96,7 +108,16 @@ bool DrivePOSIXFilesystemNode::getChildren(AbstractFSList &list, AbstractFSNode: continue; } - AbstractFSNode *child = getChild(dp->d_name); + AbstractFSNode *child = nullptr; + +#if !defined(SYSTEM_NOT_SUPPORTING_D_TYPE) + if (dp->d_type == DT_DIR || dp->d_type == DT_REG) { + child = getChildWithKnownType(dp->d_name, dp->d_type == DT_DIR); + } else +#endif + { + child = getChild(dp->d_name); + } // Honor the chosen mode if ((mode == Common::FSNode::kListFilesOnly && child->isDirectory()) || diff --git a/backends/fs/posix-drives/posix-drives-fs.h b/backends/fs/posix-drives/posix-drives-fs.h index 43c89423fa..04d21b42b1 100644 --- a/backends/fs/posix-drives/posix-drives-fs.h +++ b/backends/fs/posix-drives/posix-drives-fs.h @@ -50,6 +50,7 @@ private: bool _isPseudoRoot; const DrivesArray &_drives; + DrivePOSIXFilesystemNode *getChildWithKnownType(const Common::String &n, bool isDirectory) const; bool isDrive(const Common::String &path) const; }; diff --git a/backends/fs/posix/posix-fs.h b/backends/fs/posix/posix-fs.h index 9751ab74f6..6a67a616a3 100644 --- a/backends/fs/posix/posix-fs.h +++ b/backends/fs/posix/posix-fs.h @@ -70,7 +70,7 @@ public: virtual Common::WriteStream *createWriteStream(); virtual bool createDirectory(); -private: +protected: /** * Tests and sets the _isValid and _isDirectory flags, using the stat() function. */ |