Skip to content

Commit

Permalink
Optimize|libdeng2: App remembers the native base path once determined
Browse files Browse the repository at this point in the history
App::nativeBasePath() may be called very often, so there is no point
in determining the base path location again and again.
  • Loading branch information
skyjake committed Dec 4, 2012
1 parent 1160f0c commit d68f45e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -102,7 +102,10 @@ class DENG2_PUBLIC App : public QApplication
static NativePath executablePath();

/**
* Returns the native path of the data base directory.
* Returns the native path of the data base folder.
*
* In libdeng2, the base folder is the location where all the common
* data files are located, e.g., /usr/share/doomsday on Linux.
*/
NativePath nativeBasePath();

Expand Down
9 changes: 7 additions & 2 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -47,6 +47,9 @@ struct App::Instance
/// Path of the application executable.
NativePath appPath;

/// Path of the FS1 main data folder (the "base dir") in the native file system.
NativePath cachedBasePath;

/// The file system.
FS fs;

Expand Down Expand Up @@ -228,11 +231,13 @@ bool App::setCurrentWorkPath(NativePath const &cwd)

NativePath App::nativeBasePath()
{
if(!d->cachedBasePath.isEmpty()) return d->cachedBasePath;

int i;
if((i = d->cmdLine.check("-basedir", 1)))
{
d->cmdLine.makeAbsolutePath(i + 1);
return d->cmdLine.at(i + 1);
return (d->cachedBasePath = d->cmdLine.at(i + 1));
}

NativePath path;
Expand All @@ -247,7 +252,7 @@ NativePath App::nativeBasePath()
// Also check the system config files.
d->unixInfo.path("basedir", path);
#endif
return path;
return (d->cachedBasePath = path);
}

void App::initSubsystems(SubsystemInitFlags flags)
Expand Down

0 comments on commit d68f45e

Please sign in to comment.