QXmlStream: optimize PrivateTagStack::addToStringStorage()

De-duplicate the QString/Ref code paths by using QStringView instead.
Keep the old overloads so we can centrally apply the qToStringView-
IgnoringNull() optimization.

Replace insert(p, ..) where p = size() with append(..). The code
ensures in the lines before that the insertion position is the end of
the string.

Port the few QLatin1String arguments to addToStringStorage() to
QStringViewLiteral. I also considered adding a QLatin1String()
overload, but the test size increased, so the function wasn't pulling
its own weight.

This version saves 360B in text size on optimized GCC 6.1 Linux AMD64
builds.

Change-Id: I4b759fddc38b1f97a7218954e756cc19400922e9
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Marc Mutz 2017-04-13 14:59:57 +02:00
parent e9fd074cec
commit 58d2927861
3 changed files with 14 additions and 18 deletions

View File

@ -775,8 +775,8 @@ QXmlStreamPrivateTagStack::QXmlStreamPrivateTagStack()
tagStackStringStorage.reserve(32);
tagStackStringStorageSize = 0;
NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
namespaceDeclaration.prefix = addToStringStorage(QLatin1String("xml"));
namespaceDeclaration.namespaceUri = addToStringStorage(QLatin1String("http://www.w3.org/XML/1998/namespace"));
namespaceDeclaration.prefix = addToStringStorage(QStringViewLiteral("xml"));
namespaceDeclaration.namespaceUri = addToStringStorage(QStringViewLiteral("http://www.w3.org/XML/1998/namespace"));
initialTagStackStringStorageSize = tagStackStringStorageSize;
}

View File

@ -205,20 +205,18 @@ public:
bool tagsDone;
inline QStringRef addToStringStorage(const QStringRef &s) {
int pos = tagStackStringStorageSize;
int sz = s.size();
if (pos != tagStackStringStorage.size())
tagStackStringStorage.resize(pos);
tagStackStringStorage.insert(pos, s.unicode(), sz);
tagStackStringStorageSize += sz;
return QStringRef(&tagStackStringStorage, pos, sz);
return addToStringStorage(qToStringViewIgnoringNull(s));
}
inline QStringRef addToStringStorage(const QString &s) {
return addToStringStorage(qToStringViewIgnoringNull(s));
}
QStringRef addToStringStorage(QStringView s)
{
int pos = tagStackStringStorageSize;
int sz = s.size();
if (pos != tagStackStringStorage.size())
tagStackStringStorage.resize(pos);
tagStackStringStorage.insert(pos, s.unicode(), sz);
tagStackStringStorage.append(s.data(), sz);
tagStackStringStorageSize += sz;
return QStringRef(&tagStackStringStorage, pos, sz);
}

View File

@ -701,20 +701,18 @@ public:
bool tagsDone;
inline QStringRef addToStringStorage(const QStringRef &s) {
int pos = tagStackStringStorageSize;
int sz = s.size();
if (pos != tagStackStringStorage.size())
tagStackStringStorage.resize(pos);
tagStackStringStorage.insert(pos, s.unicode(), sz);
tagStackStringStorageSize += sz;
return QStringRef(&tagStackStringStorage, pos, sz);
return addToStringStorage(qToStringViewIgnoringNull(s));
}
inline QStringRef addToStringStorage(const QString &s) {
return addToStringStorage(qToStringViewIgnoringNull(s));
}
QStringRef addToStringStorage(QStringView s)
{
int pos = tagStackStringStorageSize;
int sz = s.size();
if (pos != tagStackStringStorage.size())
tagStackStringStorage.resize(pos);
tagStackStringStorage.insert(pos, s.unicode(), sz);
tagStackStringStorage.append(s.data(), sz);
tagStackStringStorageSize += sz;
return QStringRef(&tagStackStringStorage, pos, sz);
}