Refactor QXmlStreamStringRef
Use a QStringPrivate inside the implementation. This saves two pointers, and actually makes this a safe replacement for QStringRef inside the implementation of QXmlStreamReader. Unexport the class as all members are inline, and move it into the QtPrivate namespace as class QXmlString. Change-Id: I43fa4684f569514c8c621838dcc346657ac1a915 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>bb10
parent
551eef1aa6
commit
3398eeadf6
|
|
@ -75,6 +75,8 @@ private:
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace QtPrivate;
|
||||
|
||||
enum { StreamEOF = ~0U };
|
||||
|
||||
namespace {
|
||||
|
|
@ -1608,13 +1610,13 @@ void QXmlStreamReaderPrivate::resolveTag()
|
|||
QStringRef qualifiedName(symName(attrib.key));
|
||||
QStringRef value(symString(attrib.value));
|
||||
|
||||
attribute.m_name = QXmlStreamStringRef(name);
|
||||
attribute.m_qualifiedName = QXmlStreamStringRef(qualifiedName);
|
||||
attribute.m_value = QXmlStreamStringRef(value);
|
||||
attribute.m_name = name;
|
||||
attribute.m_qualifiedName = qualifiedName;
|
||||
attribute.m_value = value;
|
||||
|
||||
if (!prefix.isEmpty()) {
|
||||
QStringRef attributeNamespaceUri = namespaceForPrefix(prefix);
|
||||
attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
|
||||
attribute.m_namespaceUri = attributeNamespaceUri;
|
||||
}
|
||||
|
||||
for (qsizetype j = 0; j < i; ++j) {
|
||||
|
|
@ -1643,13 +1645,13 @@ void QXmlStreamReaderPrivate::resolveTag()
|
|||
|
||||
|
||||
QXmlStreamAttribute attribute;
|
||||
attribute.m_name = QXmlStreamStringRef(dtdAttribute.attributeName);
|
||||
attribute.m_qualifiedName = QXmlStreamStringRef(dtdAttribute.attributeQualifiedName);
|
||||
attribute.m_value = QXmlStreamStringRef(dtdAttribute.defaultValue);
|
||||
attribute.m_name = dtdAttribute.attributeName;
|
||||
attribute.m_qualifiedName = dtdAttribute.attributeQualifiedName;
|
||||
attribute.m_value = dtdAttribute.defaultValue;
|
||||
|
||||
if (!dtdAttribute.attributePrefix.isEmpty()) {
|
||||
QStringRef attributeNamespaceUri = namespaceForPrefix(dtdAttribute.attributePrefix);
|
||||
attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
|
||||
attribute.m_namespaceUri = attributeNamespaceUri;
|
||||
}
|
||||
attribute.m_isDefault = true;
|
||||
attributes.append(std::move(attribute));
|
||||
|
|
@ -1664,8 +1666,8 @@ void QXmlStreamReaderPrivate::resolvePublicNamespaces()
|
|||
for (qsizetype i = 0; i < n; ++i) {
|
||||
const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(tag.namespaceDeclarationsSize + i);
|
||||
QXmlStreamNamespaceDeclaration &publicNamespaceDeclaration = publicNamespaceDeclarations[i];
|
||||
publicNamespaceDeclaration.m_prefix = QXmlStreamStringRef(namespaceDeclaration.prefix);
|
||||
publicNamespaceDeclaration.m_namespaceUri = QXmlStreamStringRef(namespaceDeclaration.namespaceUri);
|
||||
publicNamespaceDeclaration.m_prefix = namespaceDeclaration.prefix;
|
||||
publicNamespaceDeclaration.m_namespaceUri = namespaceDeclaration.namespaceUri;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1675,9 +1677,9 @@ void QXmlStreamReaderPrivate::resolveDtd()
|
|||
for (qsizetype i = 0; i < notationDeclarations.size(); ++i) {
|
||||
const QXmlStreamReaderPrivate::NotationDeclaration ¬ationDeclaration = notationDeclarations.at(i);
|
||||
QXmlStreamNotationDeclaration &publicNotationDeclaration = publicNotationDeclarations[i];
|
||||
publicNotationDeclaration.m_name = QXmlStreamStringRef(notationDeclaration.name);
|
||||
publicNotationDeclaration.m_systemId = QXmlStreamStringRef(notationDeclaration.systemId);
|
||||
publicNotationDeclaration.m_publicId = QXmlStreamStringRef(notationDeclaration.publicId);
|
||||
publicNotationDeclaration.m_name = notationDeclaration.name;
|
||||
publicNotationDeclaration.m_systemId = notationDeclaration.systemId;
|
||||
publicNotationDeclaration.m_publicId = notationDeclaration.publicId;
|
||||
|
||||
}
|
||||
notationDeclarations.clear();
|
||||
|
|
@ -1685,11 +1687,11 @@ void QXmlStreamReaderPrivate::resolveDtd()
|
|||
for (qsizetype i = 0; i < entityDeclarations.size(); ++i) {
|
||||
const QXmlStreamReaderPrivate::EntityDeclaration &entityDeclaration = entityDeclarations.at(i);
|
||||
QXmlStreamEntityDeclaration &publicEntityDeclaration = publicEntityDeclarations[i];
|
||||
publicEntityDeclaration.m_name = QXmlStreamStringRef(entityDeclaration.name);
|
||||
publicEntityDeclaration.m_notationName = QXmlStreamStringRef(entityDeclaration.notationName);
|
||||
publicEntityDeclaration.m_systemId = QXmlStreamStringRef(entityDeclaration.systemId);
|
||||
publicEntityDeclaration.m_publicId = QXmlStreamStringRef(entityDeclaration.publicId);
|
||||
publicEntityDeclaration.m_value = QXmlStreamStringRef(entityDeclaration.value);
|
||||
publicEntityDeclaration.m_name = entityDeclaration.name;
|
||||
publicEntityDeclaration.m_notationName = entityDeclaration.notationName;
|
||||
publicEntityDeclaration.m_systemId = entityDeclaration.systemId;
|
||||
publicEntityDeclaration.m_publicId = entityDeclaration.publicId;
|
||||
publicEntityDeclaration.m_value = entityDeclaration.value;
|
||||
}
|
||||
entityDeclarations.clear();
|
||||
parameterEntityHash.clear();
|
||||
|
|
@ -2294,10 +2296,10 @@ QXmlStreamAttribute::QXmlStreamAttribute()
|
|||
*/
|
||||
QXmlStreamAttribute::QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value)
|
||||
{
|
||||
m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri));
|
||||
m_name = m_qualifiedName = QXmlStreamStringRef(QStringRef(&name));
|
||||
m_value = QXmlStreamStringRef(QStringRef(&value));
|
||||
m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri));
|
||||
m_namespaceUri = QStringRef(&namespaceUri);
|
||||
m_name = m_qualifiedName = QStringRef(&name);
|
||||
m_value = QStringRef(&value);
|
||||
m_namespaceUri = QStringRef(&namespaceUri);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -2306,11 +2308,9 @@ QXmlStreamAttribute::QXmlStreamAttribute(const QString &namespaceUri, const QStr
|
|||
QXmlStreamAttribute::QXmlStreamAttribute(const QString &qualifiedName, const QString &value)
|
||||
{
|
||||
int colon = qualifiedName.indexOf(QLatin1Char(':'));
|
||||
m_name = QXmlStreamStringRef(QStringRef(&qualifiedName,
|
||||
colon + 1,
|
||||
qualifiedName.size() - (colon + 1)));
|
||||
m_qualifiedName = QXmlStreamStringRef(QStringRef(&qualifiedName));
|
||||
m_value = QXmlStreamStringRef(QStringRef(&value));
|
||||
m_name = QStringRef(&qualifiedName, colon + 1, qualifiedName.size() - (colon + 1));
|
||||
m_qualifiedName = QStringRef(&qualifiedName);
|
||||
m_value = QStringRef(&value);
|
||||
}
|
||||
|
||||
/*! \fn QStringView QXmlStreamAttribute::namespaceUri() const
|
||||
|
|
@ -2508,9 +2508,9 @@ Returns the namespaceUri.
|
|||
*/
|
||||
|
||||
/*!
|
||||
\class QXmlStreamStringRef
|
||||
\class QXmlString
|
||||
\inmodule QtCore
|
||||
\since 4.3
|
||||
\since 6.0
|
||||
\internal
|
||||
*/
|
||||
|
||||
|
|
@ -2534,8 +2534,8 @@ QXmlStreamEntityDeclaration::QXmlStreamEntityDeclaration()
|
|||
{
|
||||
}
|
||||
|
||||
/*! \fn QXmlStreamStringRef::swap(QXmlStreamStringRef &other)
|
||||
\since 5.6
|
||||
/*! \fn QXmlString::swap(QXmlString &other)
|
||||
\since 6.0
|
||||
|
||||
Swaps this string reference's contents with \a other.
|
||||
This function is very fast and never fails.
|
||||
|
|
|
|||
|
|
@ -50,34 +50,43 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QtPrivate {
|
||||
class QXmlString {
|
||||
QStringPrivate m_string;
|
||||
public:
|
||||
inline constexpr QXmlString() {}
|
||||
inline QXmlString(const QStringRef &aString)
|
||||
{
|
||||
if (!aString.string())
|
||||
return;
|
||||
m_string = aString.string()->data_ptr();
|
||||
m_string = { m_string.d_ptr(), m_string.data() + aString.position(), size_t(aString.size()) };
|
||||
// need to manually call ref(), as the constructor above does not do it
|
||||
m_string.ref();
|
||||
}
|
||||
QXmlString(const QString &aString) : m_string(aString.data_ptr()) {}
|
||||
QXmlString(QString &&aString) noexcept
|
||||
{ qSwap(m_string, aString.data_ptr()); }
|
||||
|
||||
class Q_CORE_EXPORT QXmlStreamStringRef {
|
||||
QString m_string;
|
||||
int m_position, m_size;
|
||||
public:
|
||||
inline QXmlStreamStringRef():m_position(0), m_size(0){}
|
||||
inline QXmlStreamStringRef(const QStringRef &aString)
|
||||
:m_string(aString.string()?*aString.string():QString()), m_position(aString.position()), m_size(aString.size()){}
|
||||
QXmlStreamStringRef(const QString &aString) : m_string(aString), m_position(0), m_size(m_string.size()) {}
|
||||
QXmlStreamStringRef(QString &&aString) noexcept : m_string(std::move(aString)), m_position(0), m_size(m_string.size()) {}
|
||||
QXmlString &operator=(const QStringRef &s)
|
||||
{ *this = QXmlString(s); return *this; }
|
||||
|
||||
void swap(QXmlStreamStringRef &other) noexcept
|
||||
{
|
||||
qSwap(m_string, other.m_string);
|
||||
qSwap(m_position, other.m_position);
|
||||
qSwap(m_size, other.m_size);
|
||||
}
|
||||
void swap(QXmlString &other) noexcept
|
||||
{
|
||||
qSwap(m_string, other.m_string);
|
||||
}
|
||||
|
||||
inline operator QStringView() const { return QStringView(m_string.constData() + m_position, m_size); }
|
||||
inline int size() const { return m_size; }
|
||||
};
|
||||
Q_DECLARE_SHARED(QXmlStreamStringRef)
|
||||
inline operator QStringView() const { return QStringView(m_string.data(), m_string.size); }
|
||||
inline int size() const { return m_string.size; }
|
||||
};
|
||||
}
|
||||
Q_DECLARE_SHARED(QtPrivate::QXmlString)
|
||||
|
||||
|
||||
class QXmlStreamReaderPrivate;
|
||||
class QXmlStreamAttributes;
|
||||
class Q_CORE_EXPORT QXmlStreamAttribute {
|
||||
QXmlStreamStringRef m_name, m_namespaceUri, m_qualifiedName, m_value;
|
||||
QtPrivate::QXmlString m_name, m_namespaceUri, m_qualifiedName, m_value;
|
||||
uint m_isDefault : 1;
|
||||
friend class QXmlStreamReaderPrivate;
|
||||
friend class QXmlStreamAttributes;
|
||||
|
|
@ -138,7 +147,7 @@ public:
|
|||
};
|
||||
|
||||
class Q_CORE_EXPORT QXmlStreamNamespaceDeclaration {
|
||||
QXmlStreamStringRef m_prefix, m_namespaceUri;
|
||||
QtPrivate::QXmlString m_prefix, m_namespaceUri;
|
||||
|
||||
friend class QXmlStreamReaderPrivate;
|
||||
public:
|
||||
|
|
@ -158,7 +167,7 @@ Q_DECLARE_TYPEINFO(QXmlStreamNamespaceDeclaration, Q_MOVABLE_TYPE);
|
|||
typedef QList<QXmlStreamNamespaceDeclaration> QXmlStreamNamespaceDeclarations;
|
||||
|
||||
class Q_CORE_EXPORT QXmlStreamNotationDeclaration {
|
||||
QXmlStreamStringRef m_name, m_systemId, m_publicId;
|
||||
QtPrivate::QXmlString m_name, m_systemId, m_publicId;
|
||||
|
||||
friend class QXmlStreamReaderPrivate;
|
||||
public:
|
||||
|
|
@ -179,7 +188,7 @@ Q_DECLARE_TYPEINFO(QXmlStreamNotationDeclaration, Q_MOVABLE_TYPE);
|
|||
typedef QList<QXmlStreamNotationDeclaration> QXmlStreamNotationDeclarations;
|
||||
|
||||
class Q_CORE_EXPORT QXmlStreamEntityDeclaration {
|
||||
QXmlStreamStringRef m_name, m_notationName, m_systemId, m_publicId, m_value;
|
||||
QtPrivate::QXmlString m_name, m_notationName, m_systemId, m_publicId, m_value;
|
||||
|
||||
friend class QXmlStreamReaderPrivate;
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -974,6 +974,7 @@ private:
|
|||
|
||||
public:
|
||||
inline DataPointer &data_ptr() { return d; }
|
||||
inline const DataPointer &data_ptr() const { return d; }
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -267,7 +267,6 @@ QT_CLASS_LIB(QVectorIterator, QtCore, qvector.h)
|
|||
QT_CLASS_LIB(QMutableVectorIterator, QtCore, qvector.h)
|
||||
QT_CLASS_LIB(QVectorIterator, QtCore, qvector.h)
|
||||
QT_CLASS_LIB(QMutableVectorIterator, QtCore, qvector.h)
|
||||
QT_CLASS_LIB(QXmlStreamStringRef, QtCore, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamAttribute, QtCore, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamAttributes, QtCore, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamNamespaceDeclaration, QtCore, qxmlstream.h)
|
||||
|
|
@ -348,7 +347,6 @@ QT_CLASS_LIB(QXmlStreamNamespaceDeclarations, QtXml, qxmlstream.h)
|
|||
QT_CLASS_LIB(QXmlStreamNotationDeclaration, QtXml, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamNotationDeclarations, QtXml, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamReader, QtXml, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamStringRef, QtXml, qxmlstream.h)
|
||||
QT_CLASS_LIB(QXmlStreamWriter, QtXml, qxmlstream.h)
|
||||
QT_CLASS_LIB(QNetworkCacheMetaData, QtNetwork, qabstractnetworkcache.h)
|
||||
QT_CLASS_LIB(QAbstractNetworkCache, QtNetwork, qabstractnetworkcache.h)
|
||||
|
|
|
|||
Loading…
Reference in New Issue