| 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 | #ifndef QV4IDENTIFIERTABLE_H |
| 4 | #define QV4IDENTIFIERTABLE_H |
| 5 | |
| 6 | // |
| 7 | // W A R N I N G |
| 8 | // ------------- |
| 9 | // |
| 10 | // This file is not part of the Qt API. It exists purely as an |
| 11 | // implementation detail. This header file may change from version to |
| 12 | // version without notice, or even be removed. |
| 13 | // |
| 14 | // We mean it. |
| 15 | // |
| 16 | |
| 17 | #include "qv4identifierhash_p.h" |
| 18 | #include "qv4string_p.h" |
| 19 | #include "qv4engine_p.h" |
| 20 | #include <qset.h> |
| 21 | #include <limits.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | namespace QV4 { |
| 26 | |
| 27 | struct Q_QML_EXPORT IdentifierTable |
| 28 | { |
| 29 | ExecutionEngine *engine; |
| 30 | |
| 31 | uint alloc; |
| 32 | uint size; |
| 33 | int numBits; |
| 34 | Heap::StringOrSymbol **entriesByHash; |
| 35 | Heap::StringOrSymbol **entriesById; |
| 36 | |
| 37 | QSet<IdentifierHashData *> idHashes; |
| 38 | |
| 39 | void addEntry(Heap::StringOrSymbol *str); |
| 40 | |
| 41 | public: |
| 42 | |
| 43 | IdentifierTable(ExecutionEngine *engine, int numBits = 8); |
| 44 | ~IdentifierTable(); |
| 45 | |
| 46 | Heap::String *insertString(const QString &s); |
| 47 | Heap::Symbol *insertSymbol(const QString &s); |
| 48 | |
| 49 | PropertyKey asPropertyKey(const Heap::String *str) { |
| 50 | if (str->identifier.isValid()) |
| 51 | return str->identifier; |
| 52 | return asPropertyKeyImpl(str); |
| 53 | } |
| 54 | PropertyKey asPropertyKey(const QV4::String *str) { |
| 55 | return asPropertyKey(str: str->d()); |
| 56 | } |
| 57 | |
| 58 | enum KeyConversionBehavior { Default, ForceConversionToId }; |
| 59 | PropertyKey asPropertyKey(const QString &s, KeyConversionBehavior conversionBehavior = Default); |
| 60 | |
| 61 | PropertyKey asPropertyKeyImpl(const Heap::String *str); |
| 62 | |
| 63 | Heap::StringOrSymbol *resolveId(PropertyKey i) const; |
| 64 | Heap::String *stringForId(PropertyKey i) const; |
| 65 | Heap::Symbol *symbolForId(PropertyKey i) const; |
| 66 | |
| 67 | void markObjects(MarkStack *markStack); |
| 68 | void sweep(); |
| 69 | |
| 70 | void addIdentifierHash(IdentifierHashData *h) { |
| 71 | idHashes.insert(value: h); |
| 72 | } |
| 73 | void removeIdentifierHash(IdentifierHashData *h) { |
| 74 | idHashes.remove(value: h); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | Heap::String *resolveStringEntry(const QString &s, uint hash, uint subtype); |
| 79 | }; |
| 80 | |
| 81 | } |
| 82 | |
| 83 | QT_END_NAMESPACE |
| 84 | |
| 85 | #endif |
| 86 |
