Skip to content

Commit

Permalink
Optimize: NativePath remembers the current work path
Browse files Browse the repository at this point in the history
Rather than always querying the path with QDir::currentPath() (which
looks somewhat inefficient in the profiler), remember which path
has been set as the current path.
  • Loading branch information
skyjake committed Mar 29, 2013
1 parent b181bf4 commit 3d3563c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doomsday/libdeng2/include/de/filesys/nativepath.h
Expand Up @@ -147,6 +147,15 @@ class DENG2_PUBLIC NativePath : public Path
* Returns the current native working path.
*/
static NativePath workPath();

/**
* Sets the current native working path.
*
* @param cwd Working path.
*
* @return @c true iff successfully changed the current working path.
*/
static bool setWorkPath(NativePath const &cwd);
};

} // namespace de
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -287,7 +287,7 @@ NativePath App::currentWorkPath()

bool App::setCurrentWorkPath(NativePath const &cwd)
{
return QDir::setCurrent(cwd);
return NativePath::setWorkPath(cwd);
}

NativePath App::nativeBasePath()
Expand Down
18 changes: 17 additions & 1 deletion doomsday/libdeng2/src/filesys/nativepath.cpp
Expand Up @@ -218,9 +218,25 @@ bool NativePath::exists() const
return QFile::exists(toString());
}

static NativePath currentNativeWorkPath;

NativePath NativePath::workPath()
{
return QDir::currentPath();
if(currentNativeWorkPath.isEmpty())
{
currentNativeWorkPath = QDir::currentPath();
}
return currentNativeWorkPath;
}

bool NativePath::setWorkPath(const NativePath &cwd)
{
if(QDir::setCurrent(cwd))
{
currentNativeWorkPath = cwd;
return true;
}
return false;
}

} // namespace de

0 comments on commit 3d3563c

Please sign in to comment.