summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdir.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2010-08-25 13:38:32 +0200
committerJoão Abecasis <joao.abecasis@nokia.com>2010-09-07 14:17:00 +0200
commiteddb2264a5f12ea0e6a593ca411fb6be4b8f926d (patch)
treec1b861f711876700588fe6b6d7b689469b9c0b70 /src/corelib/io/qdir.h
parentf3c3b63764f50151f373ff280bd4b77093b371db (diff)
Removed QDirPrivate layer of indirection
Merged QDirPrivate with QDirPrivate::Data, as QDirPrivate served no purpose by itself, only adding an additional layer of indirection to the potentially shared private data, and an unnecessary allocation. Now, QDir holds a QSharedDataPointer to its private data. Private data will be shared among copied instances with COW semantics. Still, this sharing is very limited as plenty of regular use cases will cause the shared data to detach, such as refreshing the file lists. As the use QSharedDataPointer breaks usage of the Q_DECLARE_PRIVATE macro, we manually define the d_func'tions. Non-const d_func detaches on shared data. A detach function was added to the public interface to support this. (On a side note, QFileInfo already exposes a similar detach function). As much as possible, detach is handled implicitly inside the Q_D macro, through the d_func() non-const overload. On the other hand, implicit creation of file engines through detach was made explicit with a call to a new initFileEngine function. Reviewed-by: Thomas Zander
Diffstat (limited to 'src/corelib/io/qdir.h')
-rw-r--r--src/corelib/io/qdir.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h
index 28da271818..abfe3873c4 100644
--- a/src/corelib/io/qdir.h
+++ b/src/corelib/io/qdir.h
@@ -45,7 +45,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qstringlist.h>
-#include <QtCore/qscopedpointer.h>
+#include <QtCore/qshareddata.h>
QT_BEGIN_HEADER
@@ -58,9 +58,19 @@ class QDirPrivate;
class Q_CORE_EXPORT QDir
{
protected:
- QScopedPointer<QDirPrivate> d_ptr;
+ QSharedDataPointer<QDirPrivate> d_ptr;
private:
- Q_DECLARE_PRIVATE(QDir)
+ inline QDirPrivate* d_func()
+ {
+ detach();
+ return const_cast<QDirPrivate *>(d_ptr.constData());
+ }
+
+ inline const QDirPrivate* d_func() const
+ {
+ return d_ptr.constData();
+ }
+
public:
enum Filter { Dirs = 0x001,
Files = 0x002,
@@ -130,6 +140,8 @@ public:
QDir &operator=(const QDir &);
QDir &operator=(const QString &path);
+ void detach();
+
void setPath(const QString &path);
QString path() const;
QString absolutePath() const;