diff options
Diffstat (limited to 'qmake/library/proitems.cpp')
-rw-r--r-- | qmake/library/proitems.cpp | 162 |
1 files changed, 52 insertions, 110 deletions
diff --git a/qmake/library/proitems.cpp b/qmake/library/proitems.cpp index db19794bec..2edd40a35c 100644 --- a/qmake/library/proitems.cpp +++ b/qmake/library/proitems.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the qmake application of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "proitems.h" @@ -32,13 +7,14 @@ #include <qset.h> #include <qstringlist.h> #include <qtextstream.h> +#include <private/qduplicatetracker_p.h> QT_BEGIN_NAMESPACE // from qhash.cpp -uint ProString::hash(const QChar *p, int n) +size_t ProString::hash(const QChar *p, int n) { - uint h = 0; + size_t h = 0; while (n--) { h = (h << 4) + (*p++).unicode(); @@ -64,13 +40,13 @@ ProString::ProString(const ProString &other, OmitPreHashing) : } ProString::ProString(const QString &str, DoPreHashing) : - m_string(str), m_offset(0), m_length(str.length()), m_file(0) + m_string(str), m_offset(0), m_length(str.size()), m_file(0) { updatedHash(); } ProString::ProString(const QString &str) : - m_string(str), m_offset(0), m_length(str.length()), m_file(0), m_hash(0x80000000) + m_string(str), m_offset(0), m_length(str.size()), m_file(0), m_hash(0x80000000) { } @@ -80,13 +56,13 @@ ProString::ProString(QStringView str) : } ProString::ProString(const char *str, DoPreHashing) : - m_string(QString::fromLatin1(str)), m_offset(0), m_length(qstrlen(str)), m_file(0) + m_string(QString::fromLatin1(str)), m_offset(0), m_length(int(qstrlen(str))), m_file(0) { updatedHash(); } ProString::ProString(const char *str) : - m_string(QString::fromLatin1(str)), m_offset(0), m_length(qstrlen(str)), m_file(0), m_hash(0x80000000) + m_string(QString::fromLatin1(str)), m_offset(0), m_length(int(qstrlen(str))), m_file(0), m_hash(0x80000000) { } @@ -108,10 +84,10 @@ ProString::ProString(const QString &str, int offset, int length) : void ProString::setValue(const QString &str) { - m_string = str, m_offset = 0, m_length = str.length(), m_hash = 0x80000000; + m_string = str, m_offset = 0, m_length = str.size(), m_hash = 0x80000000; } -uint ProString::updatedHash() const +size_t ProString::updatedHash() const { return (m_hash = hash(m_string.constData() + m_offset, m_length)); } @@ -145,7 +121,7 @@ ProKey::ProKey(const QString &str, int off, int len, uint hash) : void ProKey::setValue(const QString &str) { - m_string = str, m_offset = 0, m_length = str.length(); + m_string = str, m_offset = 0, m_length = str.size(); updatedHash(); } @@ -160,51 +136,18 @@ QString &ProString::toQString(QString &tmp) const return tmp; } -/* - * \brief ProString::prepareExtend - * \param extraLen number of new characters to be added - * \param thisTarget offset to which current contents should be moved - * \param extraTarget offset at which new characters will be added - * \return pointer to storage location for new characters - * - * Prepares the string for adding new characters. - * If the string is detached and has enough space, it will be changed in place. - * Otherwise, it will be replaced with a new string object, thus detaching. - * In either case, the hash will be reset. - */ -QChar *ProString::prepareExtend(int extraLen, int thisTarget, int extraTarget) -{ - if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) { - m_string.reserve(0); // Prevent the resize() below from reallocating - QChar *ptr = (QChar *)m_string.constData(); - if (m_offset != thisTarget) - memmove(ptr + thisTarget, ptr + m_offset, m_length * 2); - ptr += extraTarget; - m_offset = 0; - m_length += extraLen; - m_string.resize(m_length); - m_hash = 0x80000000; - return ptr; - } else { - QString neu(m_length + extraLen, Qt::Uninitialized); - QChar *ptr = (QChar *)neu.constData(); - memcpy(ptr + thisTarget, m_string.constData() + m_offset, m_length * 2); - ptr += extraTarget; - *this = ProString(neu); - return ptr; - } -} - ProString &ProString::prepend(const ProString &other) { if (other.m_length) { if (!m_length) { *this = other; } else { - QChar *ptr = prepareExtend(other.m_length, other.m_length, 0); - memcpy(ptr, other.constData(), other.m_length * 2); + m_string = other.toQStringView() + toQStringView(); + m_offset = 0; + m_length = m_string.size(); if (!m_file) m_file = other.m_file; + m_hash = 0x80000000; } } return *this; @@ -212,20 +155,33 @@ ProString &ProString::prepend(const ProString &other) ProString &ProString::append(const QLatin1String other) { - const char *latin1 = other.latin1(); - int size = other.size(); - if (size) { - QChar *ptr = prepareExtend(size, 0, m_length); - for (int i = 0; i < size; i++) - *ptr++ = QLatin1Char(latin1[i]); + if (other.size()) { + if (m_length != m_string.size()) { + m_string = toQStringView() + other; + m_offset = 0; + m_length = m_string.size(); + } else { + Q_ASSERT(m_offset == 0); + m_string.append(other); + m_length += other.size(); + } + m_hash = 0x80000000; } return *this; } ProString &ProString::append(QChar other) { - QChar *ptr = prepareExtend(1, 0, m_length); - *ptr = other; + if (m_length != m_string.size()) { + m_string = toQStringView() + other; + m_offset = 0; + m_length = m_string.size(); + } else { + Q_ASSERT(m_offset == 0); + m_string.append(other); + ++m_length; + } + m_hash = 0x80000000; return *this; } @@ -236,16 +192,18 @@ ProString &ProString::append(const ProString &other, bool *pending) if (!m_length) { *this = other; } else { - QChar *ptr; + if (m_length != m_string.size()) + m_string = toQString(); if (pending && !*pending) { - ptr = prepareExtend(1 + other.m_length, 0, m_length); - *ptr++ = QLatin1Char(' '); + m_string += QLatin1Char(' ') + other.toQStringView(); } else { - ptr = prepareExtend(other.m_length, 0, m_length); + m_string += other.toQStringView(); } - memcpy(ptr, other.m_string.constData() + other.m_offset, other.m_length * 2); + m_length = m_string.size(); + m_offset = 0; if (other.m_file) m_file = other.m_file; + m_hash = 0x80000000; } if (pending) *pending = true; @@ -265,27 +223,24 @@ ProString &ProString::append(const ProStringList &other, bool *pending, bool ski if (!m_length && sz == startIdx + 1) { *this = other.at(startIdx); } else { - int totalLength = sz - startIdx; - for (int i = startIdx; i < sz; ++i) - totalLength += other.at(i).size(); bool putSpace = false; if (pending && !*pending && m_length) putSpace = true; - else - totalLength--; - QChar *ptr = prepareExtend(totalLength, 0, m_length); + m_string = toQString(); + m_offset = 0; for (int i = startIdx; i < sz; ++i) { if (putSpace) - *ptr++ = QLatin1Char(' '); + m_string += QLatin1Char(' '); else putSpace = true; const ProString &str = other.at(i); - memcpy(ptr, str.m_string.constData() + str.m_offset, str.m_length * 2); - ptr += str.m_length; + m_string += str.toQStringView(); } + m_length = m_string.size(); if (other.last().m_file) m_file = other.last().m_file; + m_hash = 0x80000000; } if (pending) *pending = true; @@ -419,21 +374,8 @@ void ProStringList::removeEmpty() void ProStringList::removeDuplicates() { - int n = size(); - int j = 0; - QSet<ProString> seen; - seen.reserve(n); - for (int i = 0; i < n; ++i) { - const ProString &s = at(i); - if (seen.contains(s)) - continue; - seen.insert(s); - if (j != i) - (*this)[j] = s; - ++j; - } - if (n != j) - erase(begin() + j, end()); + QDuplicateTracker<ProString> seen(size()); + removeIf([&](const ProString &s) { return seen.hasSeen(s); }); } void ProStringList::insertUnique(const ProStringList &value) |