Skip to content

Commit

Permalink
Cache path hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Mormert committed Sep 23, 2023
1 parent b399878 commit 77f7477
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion engine/jlePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

jlePath::jlePath(const std::string &path, bool virtualPath)
{

std::string processedPath = path;
fixSlashes(processedPath);

Expand All @@ -18,6 +17,8 @@ jlePath::jlePath(const std::string &path, bool virtualPath)
_realPath = processedPath;
_virtualPath = findVirtualPathFromRealPath(processedPath);
}

_hash = std::hash<std::string>()(_virtualPath);
}

jlePath::jlePath(const char *virtualPath) : jlePath(std::string{virtualPath}, true) {}
Expand Down Expand Up @@ -163,6 +164,7 @@ jlePath::getVirtualPath()
{
if (_virtualPath.empty()) {
_virtualPath = findVirtualPathFromRealPath(_realPath);
_hash = std::hash<std::string>()(_virtualPath);
}
return _virtualPath;
}
Expand Down
5 changes: 4 additions & 1 deletion engine/jlePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class jlePath
fixSlashes(_virtualPath);
_realPath = findRealPathFromVirtualPath(_virtualPath);
_virtualPath = value;
_hash = std::hash<std::string>()(_virtualPath);
}

jlePath(const char* virtualPath);
Expand Down Expand Up @@ -74,6 +75,8 @@ class jlePath
static std::string findRealPathFromVirtualPath(const std::string &virtualPath);

static void fixSlashes(std::string &str);

size_t _hash;
};

namespace std
Expand All @@ -83,7 +86,7 @@ struct hash<jlePath> {
std::size_t
operator()(const jlePath &path) const
{
return hash<std::string>()(path._virtualPath);
return path._hash;
}
};
} // namespace std

0 comments on commit 77f7477

Please sign in to comment.