summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-09 16:36:08 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-05-10 12:48:23 +0200
commitf490ac671267438d8a539f4639c9e987861924cf (patch)
treed4d108eaf6f614d701b589519e69faab20fa21ed /src/corelib/serialization
parent8ed88d8d14ae9aed41029afe8bf4a6c42678c6b5 (diff)
QXmlStreamReader: avoid double QHash lookups
Replace if (hash.contains(x)) { // lookup #1 ~~~ hash[x]; // lookup #2 with if (auto it = hash.find(x); it != hash.end()) { // lookup ~~~ *it; // no lookup halving the number of QHash lookups. The container is not shared, so there's no danger of a detach when going directly to the non-const function. Change-Id: Ifae409f98e0be972b31a24326ad548723831fda8 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qxmlstream.g12
-rw-r--r--src/corelib/serialization/qxmlstream_p.h12
2 files changed, 12 insertions, 12 deletions
diff --git a/src/corelib/serialization/qxmlstream.g b/src/corelib/serialization/qxmlstream.g
index b623de9505..e630366822 100644
--- a/src/corelib/serialization/qxmlstream.g
+++ b/src/corelib/serialization/qxmlstream.g
@@ -1642,8 +1642,8 @@ entity_ref ::= AMPERSAND name SEMICOLON;
case $rule_number: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (entityHash.contains(reference)) {
- Entity &entity = entityHash[reference];
+ if (const auto it = entityHash.find(reference); it != entityHash.end()) {
+ Entity &entity = *it;
if (entity.unparsed) {
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
} else {
@@ -1684,9 +1684,9 @@ pereference ::= PERCENT name SEMICOLON;
case $rule_number: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (parameterEntityHash.contains(reference)) {
+ if (const auto it = parameterEntityHash.find(reference); it != parameterEntityHash.end()) {
referenceToParameterEntityDetected = true;
- Entity &entity = parameterEntityHash[reference];
+ Entity &entity = *it;
if (entity.unparsed || entity.external) {
referenceToUnparsedEntityDetected = true;
} else {
@@ -1715,8 +1715,8 @@ entity_ref_in_attribute_value ::= AMPERSAND name SEMICOLON;
case $rule_number: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (entityHash.contains(reference)) {
- Entity &entity = entityHash[reference];
+ if (const auto it = entityHash.find(reference); it != entityHash.end()) {
+ Entity &entity = *it;
if (entity.unparsed || entity.value.isNull()) {
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
break;
diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h
index 103b123b10..0ffe57e403 100644
--- a/src/corelib/serialization/qxmlstream_p.h
+++ b/src/corelib/serialization/qxmlstream_p.h
@@ -1814,8 +1814,8 @@ bool QXmlStreamReaderPrivate::parse()
case 240: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (entityHash.contains(reference)) {
- Entity &entity = entityHash[reference];
+ if (const auto it = entityHash.find(reference); it != entityHash.end()) {
+ Entity &entity = *it;
if (entity.unparsed) {
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
} else {
@@ -1853,9 +1853,9 @@ bool QXmlStreamReaderPrivate::parse()
case 241: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (parameterEntityHash.contains(reference)) {
+ if (const auto it = parameterEntityHash.find(reference); it != parameterEntityHash.end()) {
referenceToParameterEntityDetected = true;
- Entity &entity = parameterEntityHash[reference];
+ Entity &entity = *it;
if (entity.unparsed || entity.external) {
referenceToUnparsedEntityDetected = true;
} else {
@@ -1876,8 +1876,8 @@ bool QXmlStreamReaderPrivate::parse()
case 243: {
sym(1).len += sym(2).len + 1;
QStringView reference = symView(2);
- if (entityHash.contains(reference)) {
- Entity &entity = entityHash[reference];
+ if (const auto it = entityHash.find(reference); it != entityHash.end()) {
+ Entity &entity = *it;
if (entity.unparsed || entity.value.isNull()) {
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
break;