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>
This commit is contained in:
parent
8ed88d8d14
commit
f490ac6712
@ -1642,8 +1642,8 @@ entity_ref ::= AMPERSAND name SEMICOLON;
|
|||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (entityHash.contains(reference)) {
|
if (const auto it = entityHash.find(reference); it != entityHash.end()) {
|
||||||
Entity &entity = entityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed) {
|
if (entity.unparsed) {
|
||||||
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
|
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
|
||||||
} else {
|
} else {
|
||||||
@ -1684,9 +1684,9 @@ pereference ::= PERCENT name SEMICOLON;
|
|||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (parameterEntityHash.contains(reference)) {
|
if (const auto it = parameterEntityHash.find(reference); it != parameterEntityHash.end()) {
|
||||||
referenceToParameterEntityDetected = true;
|
referenceToParameterEntityDetected = true;
|
||||||
Entity &entity = parameterEntityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed || entity.external) {
|
if (entity.unparsed || entity.external) {
|
||||||
referenceToUnparsedEntityDetected = true;
|
referenceToUnparsedEntityDetected = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1715,8 +1715,8 @@ entity_ref_in_attribute_value ::= AMPERSAND name SEMICOLON;
|
|||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (entityHash.contains(reference)) {
|
if (const auto it = entityHash.find(reference); it != entityHash.end()) {
|
||||||
Entity &entity = entityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed || entity.value.isNull()) {
|
if (entity.unparsed || entity.value.isNull()) {
|
||||||
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
|
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
|
||||||
break;
|
break;
|
||||||
|
@ -1814,8 +1814,8 @@ bool QXmlStreamReaderPrivate::parse()
|
|||||||
case 240: {
|
case 240: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (entityHash.contains(reference)) {
|
if (const auto it = entityHash.find(reference); it != entityHash.end()) {
|
||||||
Entity &entity = entityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed) {
|
if (entity.unparsed) {
|
||||||
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
|
raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
|
||||||
} else {
|
} else {
|
||||||
@ -1853,9 +1853,9 @@ bool QXmlStreamReaderPrivate::parse()
|
|||||||
case 241: {
|
case 241: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (parameterEntityHash.contains(reference)) {
|
if (const auto it = parameterEntityHash.find(reference); it != parameterEntityHash.end()) {
|
||||||
referenceToParameterEntityDetected = true;
|
referenceToParameterEntityDetected = true;
|
||||||
Entity &entity = parameterEntityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed || entity.external) {
|
if (entity.unparsed || entity.external) {
|
||||||
referenceToUnparsedEntityDetected = true;
|
referenceToUnparsedEntityDetected = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1876,8 +1876,8 @@ bool QXmlStreamReaderPrivate::parse()
|
|||||||
case 243: {
|
case 243: {
|
||||||
sym(1).len += sym(2).len + 1;
|
sym(1).len += sym(2).len + 1;
|
||||||
QStringView reference = symView(2);
|
QStringView reference = symView(2);
|
||||||
if (entityHash.contains(reference)) {
|
if (const auto it = entityHash.find(reference); it != entityHash.end()) {
|
||||||
Entity &entity = entityHash[reference];
|
Entity &entity = *it;
|
||||||
if (entity.unparsed || entity.value.isNull()) {
|
if (entity.unparsed || entity.value.isNull()) {
|
||||||
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
|
raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user