summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2010-01-26 16:26:50 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-01-26 16:26:50 (GMT)
commit3c8ac0ee7f09bbef4dc56a05de538df1aa16a596 (patch)
tree4a2ee8e89172a1e627816ad8143ac0bbc9fe01f1 /src/corelib/io
parentfbd0b8c0f6dce834b241f6beb755d2c2cb013305 (diff)
downloadQt-3c8ac0ee7f09bbef4dc56a05de538df1aa16a596.zip
Qt-3c8ac0ee7f09bbef4dc56a05de538df1aa16a596.tar.gz
Qt-3c8ac0ee7f09bbef4dc56a05de538df1aa16a596.tar.bz2
QFileInfo: Implement additional caching of FileOwner strings
Reduce overhead of the uid/gid to user/group name conversion by caching results from QAbstractFileEngine::owner(). Merge-request: 446 Reviewed-by: João Abecasis <joao@trolltech.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfileinfo.cpp16
-rw-r--r--src/corelib/io/qfileinfo_p.h4
2 files changed, 18 insertions, 2 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index f4e92a5..d827f57 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -137,6 +137,18 @@ QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const
return ret;
}
+QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const
+{
+ if (data->cache_enabled && !data->fileOwners[(int)own].isNull())
+ return data->fileOwners[(int)own];
+ QString ret = data->fileEngine->owner(own);
+ if (ret.isNull())
+ ret = QLatin1String("");
+ if (data->cache_enabled)
+ data->fileOwners[(int)own] = ret;
+ return ret;
+}
+
uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const
{
// We split the testing into tests for for LinkType, BundleType, PermsMask
@@ -1089,7 +1101,7 @@ QString QFileInfo::owner() const
Q_D(const QFileInfo);
if(!d->data->fileEngine)
return QLatin1String("");
- return d->data->fileEngine->owner(QAbstractFileEngine::OwnerUser);
+ return d->getFileOwner(QAbstractFileEngine::OwnerUser);
}
/*!
@@ -1125,7 +1137,7 @@ QString QFileInfo::group() const
Q_D(const QFileInfo);
if(!d->data->fileEngine)
return QLatin1String("");
- return d->data->fileEngine->owner(QAbstractFileEngine::OwnerGroup);
+ return d->getFileOwner(QAbstractFileEngine::OwnerGroup);
}
/*!
diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h
index bf02aaa..d97a0cf 100644
--- a/src/corelib/io/qfileinfo_p.h
+++ b/src/corelib/io/qfileinfo_p.h
@@ -78,6 +78,7 @@ public:
uint getFileFlags(QAbstractFileEngine::FileFlags) const;
QDateTime &getFileTime(QAbstractFileEngine::FileTime) const;
QString getFileName(QAbstractFileEngine::FileName) const;
+ QString getFileOwner(QAbstractFileEngine::FileOwner own) const;
enum { CachedFileFlags=0x01, CachedLinkTypeFlag=0x02, CachedBundleTypeFlag=0x04,
CachedMTime=0x10, CachedCTime=0x20, CachedATime=0x40,
@@ -103,12 +104,15 @@ public:
clearFlags();
for (int i = QAbstractFileEngine::NFileNames - 1 ; i >= 0 ; --i)
fileNames[i].clear();
+ fileOwners[1].clear();
+ fileOwners[0].clear();
}
mutable QAtomicInt ref;
QAbstractFileEngine *fileEngine;
mutable QString fileName;
mutable QString fileNames[QAbstractFileEngine::NFileNames];
+ mutable QString fileOwners[2];
mutable uint cachedFlags : 31;
mutable uint cache_enabled : 1;