diff --git a/toolbox/fs_spec.cpp b/toolbox/fs_spec.cpp index 7a8020e..1e0ae16 100644 --- a/toolbox/fs_spec.cpp +++ b/toolbox/fs_spec.cpp @@ -5,6 +5,8 @@ namespace OS { + const int RootPathID = 2; + std::deque FSSpecManager::_pathQueue; void FSSpecManager::Init() @@ -49,7 +51,9 @@ namespace OS { Init(); - int i = 1; + // this only works well for a small number of directories, + // which should be the common case. + int i = RootPathID; for (const auto &e : _pathQueue) { if (e.hash == hash && e.path == path) return i; @@ -82,7 +86,7 @@ namespace OS { Init(); - int i = 1; + int i = RootPathID; for (const auto &e : _pathQueue) { if (e.hash == hash && e.path == path) return i; @@ -102,10 +106,11 @@ namespace OS { Init(); - if (id < 1) return NullString; - if (id > _pathQueue.size()) return NullString; + id -= RootPathID; + if (id < 0) return NullString; + if (id >= _pathQueue.size()) return NullString; - return _pathQueue[id - 1].path; + return _pathQueue[id].path; } std::string FSSpecManager::ExpandPath(const std::string &path, int32_t id)