diff options
Diffstat (limited to 'src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp')
-rw-r--r-- | src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp | 103 |
1 files changed, 32 insertions, 71 deletions
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp index f970e13f8b..dca58b35b7 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp @@ -1,25 +1,8 @@ -/* - Copyright (C) 2016 Volker Krause <vkrause@kde.org> - Copyright (C) 2018 Christoph Cullmann <cullmann@kde.org> - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/* + SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> + SPDX-FileCopyrightText: 2018 Christoph Cullmann <cullmann@kde.org> + + SPDX-License-Identifier: MIT */ #include "state.h" @@ -31,31 +14,23 @@ using namespace KSyntaxHighlighting; -StateData* StateData::get(State &state) -{ - state.d.detach(); - return state.d.data(); -} - -bool StateData::isEmpty() const -{ - return m_contextStack.isEmpty(); -} - -void StateData::clear() +StateData *StateData::reset(State &state) { - m_contextStack.clear(); + auto *p = new StateData(); + state.d.reset(p); + return p; } -int StateData::size() const +StateData *StateData::detach(State &state) { - return m_contextStack.size(); + state.d.detach(); + return state.d.data(); } -void StateData::push(Context *context, const QStringList &captures) +void StateData::push(Context *context, QStringList &&captures) { Q_ASSERT(context); - m_contextStack.push_back(qMakePair(context, captures)); + m_contextStack.push_back(StackValue{context, std::move(captures)}); } bool StateData::pop(int popCount) @@ -66,48 +41,28 @@ bool StateData::pop(int popCount) } // keep the initial context alive in any case - Q_ASSERT(!isEmpty()); - const bool initialContextSurvived = m_contextStack.size() > popCount; - m_contextStack.resize(std::max(1, m_contextStack.size() - popCount)); + Q_ASSERT(!m_contextStack.empty()); + const bool initialContextSurvived = int(m_contextStack.size()) > popCount; + m_contextStack.resize(std::max(1, int(m_contextStack.size()) - popCount)); return initialContextSurvived; } -Context* StateData::topContext() const -{ - Q_ASSERT(!isEmpty()); - return m_contextStack.last().first; -} +State::State() = default; -const QStringList &StateData::topCaptures() const -{ - Q_ASSERT(!isEmpty()); - return m_contextStack.last().second; -} +State::State(State &&other) noexcept = default; -State::State() : - d(new StateData) -{ -} +State::State(const State &other) noexcept = default; -State::State(const State &other) : - d(other.d) -{ -} +State::~State() = default; -State::~State() -{ -} +State &State::operator=(State &&other) noexcept = default; -State& State::operator=(const State &other) -{ - d = other.d; - return *this; -} +State &State::operator=(const State &other) noexcept = default; bool State::operator==(const State &other) const { // use pointer equal as shortcut for shared states - return (d == other.d) || (d->m_contextStack == other.d->m_contextStack && d->m_defRef == other.d->m_defRef); + return (d == other.d) || (d && other.d && d->m_contextStack == other.d->m_contextStack && d->m_defId == other.d->m_defId); } bool State::operator!=(const State &other) const @@ -117,7 +72,13 @@ bool State::operator!=(const State &other) const bool State::indentationBasedFoldingEnabled() const { - if (d->m_contextStack.isEmpty()) + if (!d || d->m_contextStack.empty()) { return false; - return d->m_contextStack.last().first->indentationBasedFoldingEnabled(); + } + return d->m_contextStack.back().context->indentationBasedFoldingEnabled(); +} + +std::size_t KSyntaxHighlighting::qHash(const State &state, std::size_t seed) +{ + return state.d ? qHashMulti(seed, *state.d) : 0; } |