[Development] Is Qt allowed caching the home dir path?

Jiergir Ogoerg f35f22fan at gmail.com
Sun Oct 27 03:53:41 CET 2013


It looks like only the home and temp dir paths are worth caching, their
window$ implementation is ~ 30-40 lines of code
if counting QDir's subcalls to QFileSystemEngine.

For these two QDir functions to stay one liners and lock-less (while thread
safe), I'm caching the paths in QDirPrivate
(QTSRC/qtbase/src/corelib/io/qdir_p.h and
QTSRC/qtbase/src/corelib/io/qdir.cpp),

FILE qdir_p.h:

//==> QDirPrivate
static void initPaths();

static QString homePath;
static QString tempPath;

FILE qdir.cpp:

QString QDirPrivate::homePath;
QString QDirPrivate::tempPath;

void QDirPrivate::initPaths()
{
    homePath = QFileSystemEngine::homePath();
    tempPath = QFileSystemEngine::tempPath();
}
//<== QDirPrivate

//==> QDir
QString QDir::homePath()
{
    return QDirPrivate::homePath;
    //return QFileSystemEngine::homePath();
}

QString QDir::tempPath()
{
    return QDirPrivate::tempPath;
    //return QFileSystemEngine::tempPath();
}
//<== public

and initiating the variables once when the program starts when it's still
in single thread mode in QCoreApplication::init()
(QTSRC/qtbase/src/corelib/kernel/qcoreapplication.cpp)

QCoreApplication::init() {
...
QCoreApplication::self = this; // after this line
QDirPrivate::initPaths();
}

Does it sound plausible?



On Sat, Oct 26, 2013 at 10:14 PM, Thiago Macieira <thiago.macieira at intel.com
> wrote:

> On sábado, 26 de outubro de 2013 21:58:10, Jiergir Ogoerg wrote:
> > That is, it calls other (sub)functions to perform search, copy and
> cleaning
> > up the string which makes me
> > wonder if it's OK for Qt caching the home dir path as long as the Qt
> > library runs?
>
> Yes, caching is fine, since the user shouldn't really be doing
> setenv(HOME).
> It's very unlikely.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131027/6b1147f9/attachment.html>


More information about the Development mailing list