summaryrefslogtreecommitdiffstats
path: root/src/xml/dom
diff options
context:
space:
mode:
authorIsak Fyksen <isak.fyksen@qt.io>2023-11-10 16:46:33 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-03-20 14:21:00 +0000
commitb1e8287b8db5463f9a933302a27671b2b0ca1fa5 (patch)
tree2f56a2a8ee2a9b00bf2dcc336e5a40371851bdb8 /src/xml/dom
parente5ebb9022ab9e00ab01d0bce527755da77083217 (diff)
Extract method `bool QDomNodeListPrivate::maybeCreateList()`
Extract duplicated logic to own method, and call where previously used. Also, make `QDomNodeListPrivate::[list|timestamp]` mutable, to allow `maybeCreateList()` and `createList()` to be `const` methods, and avoid `const_cast` in `QDomNodeListPrivate::length()`. Task-number: QTBUG-115076 Change-Id: I4f3a27315da28082a12cc4f5653567039b4cb376 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/xml/dom')
-rw-r--r--src/xml/dom/qdom.cpp21
-rw-r--r--src/xml/dom/qdom_p.h7
2 files changed, 14 insertions, 14 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index 2ac044004e..b25cdf487f 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -649,7 +649,7 @@ bool QDomNodeListPrivate::operator!=(const QDomNodeListPrivate &other) const
return !operator==(other);
}
-void QDomNodeListPrivate::createList()
+void QDomNodeListPrivate::createList() const
{
if (!node_impl)
return;
@@ -703,16 +703,21 @@ void QDomNodeListPrivate::createList()
}
}
-QDomNodePrivate* QDomNodeListPrivate::item(int index)
+bool QDomNodeListPrivate::maybeCreateList() const
{
if (!node_impl)
- return nullptr;
+ return false;
const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
if (!doc || timestamp != doc->nodeListTime)
createList();
- if (index >= list.size())
+ return true;
+}
+
+QDomNodePrivate *QDomNodeListPrivate::item(int index)
+{
+ if (!maybeCreateList() || index >= list.size() || index < 0)
return nullptr;
return list.at(index);
@@ -720,15 +725,9 @@ QDomNodePrivate* QDomNodeListPrivate::item(int index)
int QDomNodeListPrivate::length() const
{
- if (!node_impl)
+ if (!maybeCreateList())
return 0;
- const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
- if (!doc || timestamp != doc->nodeListTime) {
- QDomNodeListPrivate *that = const_cast<QDomNodeListPrivate *>(this);
- that->createList();
- }
-
return list.size();
}
diff --git a/src/xml/dom/qdom_p.h b/src/xml/dom/qdom_p.h
index fb71f8ce23..b2ecd534c8 100644
--- a/src/xml/dom/qdom_p.h
+++ b/src/xml/dom/qdom_p.h
@@ -142,7 +142,8 @@ public:
bool operator==(const QDomNodeListPrivate &) const;
bool operator!=(const QDomNodeListPrivate &) const;
- void createList();
+ void createList() const;
+ bool maybeCreateList() const;
QDomNodePrivate *item(int index);
int length() const;
@@ -153,8 +154,8 @@ public:
QDomNodePrivate *node_impl;
QString tagname;
QString nsURI;
- QList<QDomNodePrivate *> list;
- long timestamp;
+ mutable QList<QDomNodePrivate *> list;
+ mutable long timestamp;
};
class QDomNamedNodeMapPrivate