Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4compilationunitmapper.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <private/qv4compileddata_p.h>
7
8#include <QtCore/qdatetime.h>
9#include <QtCore/qmutex.h>
10#include <QtCore/qhash.h>
11
13
14using namespace QV4;
15
17{
18public:
19 StaticUnitCache() : m_lock(&s_mutex) {}
20
22 {
23 const auto it = s_staticUnits.constFind(file);
24 return it == s_staticUnits.constEnd() ? CompilationUnitMapper() : *it;
25 }
26
27 void set(const QString &file, const CompilationUnitMapper &staticUnit) {
28 s_staticUnits.insert(file, staticUnit);
29 }
30
31 void remove(const QString &file)
32 {
33 s_staticUnits.remove(file);
34 }
35
36private:
37 QMutexLocker<QMutex> m_lock;
38
39 static QMutex s_mutex;
40
41 // We can copy the mappers around because they're all static.
42 // We never unmap the files.
43 static QHash<QString, CompilationUnitMapper> s_staticUnits;
44};
45
46QHash<QString, CompilationUnitMapper> StaticUnitCache::s_staticUnits;
47QMutex StaticUnitCache::s_mutex;
48
50 const QString &cacheFilePath, const QDateTime &sourceTimeStamp, QString *errorString)
51{
53
54 CompilationUnitMapper mapper = cache.get(cacheFilePath);
55 if (mapper.dataPtr) {
56 auto *unit = reinterpret_cast<CompiledData::Unit *>(mapper.dataPtr);
57 if (unit->verifyHeader(sourceTimeStamp, errorString)) {
58 *this = mapper;
59 return unit;
60 }
61
62 return nullptr;
63 }
64
65 CompiledData::Unit *data = open(cacheFilePath, sourceTimeStamp, errorString);
66 if (data && (data->flags & CompiledData::Unit::StaticData)) {
67 cache.set(cacheFilePath, *this);
68 return data;
69 } else {
70 close();
71 return nullptr;
72 }
73}
74
76{
78 cache.remove(cacheFilePath);
79}
80
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore
Definition qmutex.h:281
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static void invalidate(const QString &cacheFilePath)
CompiledData::Unit * get(const QString &cacheFilePath, const QDateTime &sourceTimeStamp, QString *errorString)
CompilationUnitMapper get(const QString &file)
void set(const QString &file, const CompilationUnitMapper &staticUnit)
void remove(const QString &file)
QCache< int, Employee > cache
[0]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QFile file
[0]
QDataWidgetMapper * mapper
[0]