diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-04-15 14:25:54 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-05-30 10:38:17 +0000 |
commit | dc72ff7b978a935d95bced05d8b2c8eee87d042d (patch) | |
tree | 73be47300bdadd077f00deb9e5a36df2a9654984 /src/corelib/xml/qxmlstream.cpp | |
parent | e136565505bd5f2e787dace5b6107e211d55854e (diff) |
QXmlStream: don't create QStrings just to look up entities in a hash
Move the entity's name into the Entity struct and use a QStringView
into Entity::name as the hash key, instead of a QString.
This avoids having to create a QString from QStringRefs every time an
entity is looked up.
Only costs 280B in text size on optimized GCC 6.1 Linux AMD64 builds.
Change-Id: I8dbd04c90c1ff684b794685025204abc89f68a84
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/xml/qxmlstream.cpp')
-rw-r--r-- | src/corelib/xml/qxmlstream.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index 195466e803..6dfa6744b8 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -796,11 +796,17 @@ QXmlStreamReaderPrivate::QXmlStreamReaderPrivate(QXmlStreamReader *q) reallocateStack(); entityResolver = 0; init(); - entityHash.insert(QLatin1String("lt"), Entity::createLiteral(QLatin1String("<"))); - entityHash.insert(QLatin1String("gt"), Entity::createLiteral(QLatin1String(">"))); - entityHash.insert(QLatin1String("amp"), Entity::createLiteral(QLatin1String("&"))); - entityHash.insert(QLatin1String("apos"), Entity::createLiteral(QLatin1String("'"))); - entityHash.insert(QLatin1String("quot"), Entity::createLiteral(QLatin1String("\""))); +#define ADD_PREDEFINED(n, v) \ + do { \ + Entity e = Entity::createLiteral(QLatin1String(n), QLatin1String(v)); \ + entityHash.insert(qToStringViewIgnoringNull(e.name), std::move(e)); \ + } while (false) + ADD_PREDEFINED("lt", "<"); + ADD_PREDEFINED("gt", ">"); + ADD_PREDEFINED("amp", "&"); + ADD_PREDEFINED("apos", "'"); + ADD_PREDEFINED("quot", "\""); +#undef ADD_PREDEFINED } void QXmlStreamReaderPrivate::init() |