diff options
Diffstat (limited to 'src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h')
-rw-r--r-- | src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h index 0248330304f..4aee1416818 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h @@ -8,8 +8,10 @@ #ifndef KSYNTAXHIGHLIGHTING_STATE_P_H #define KSYNTAXHIGHLIGHTING_STATE_P_H +#include <vector> + #include <QSharedData> -#include <QVector> +#include <QStringList> #include "definitionref_p.h" @@ -21,15 +23,25 @@ class StateData : public QSharedData { friend class State; friend class AbstractHighlighter; + friend std::size_t qHash(const StateData &, std::size_t); public: StateData() = default; - static StateData *get(State &state); - bool isEmpty() const; - void clear(); - int size() const; - void push(Context *context, const QStringList &captures); + static StateData *reset(State &state); + static StateData *detach(State &state); + + static StateData *get(const State &state) + { + return state.d.data(); + } + + int size() const + { + return m_contextStack.size(); + } + + void push(Context *context, QStringList &&captures); /** * Pop the number of elements given from the top of the current stack. @@ -39,8 +51,25 @@ public: */ bool pop(int popCount); - Context *topContext() const; - const QStringList &topCaptures() const; + Context *topContext() const + { + return m_contextStack.back().context; + } + + const QStringList &topCaptures() const + { + return m_contextStack.back().captures; + } + + struct StackValue { + Context *context; + QStringList captures; + + bool operator==(const StackValue &other) const + { + return context == other.context && captures == other.captures; + } + }; private: /** @@ -51,9 +80,18 @@ private: /** * the context stack combines the active context + valid captures */ - QVector<QPair<Context *, QStringList>> m_contextStack; + std::vector<StackValue> m_contextStack; }; +inline std::size_t qHash(const StateData::StackValue &stackValue, std::size_t seed = 0) +{ + return qHashMulti(seed, stackValue.context, stackValue.captures); +} + +inline std::size_t qHash(const StateData &k, std::size_t seed = 0) +{ + return qHashMulti(seed, k.m_defId, qHashRange(k.m_contextStack.begin(), k.m_contextStack.end(), seed)); +} } #endif |