QXmlStream: use even more ranged for loops
Write a small range adapter that maps begin() to rbegin() and end() to rend() of the underlying range, use it to replace indexed reverse loops with ranged for ones. Change-Id: I5498a23106b0432ce885e72e5e3912910f50b5c1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
2e298c5f82
commit
0c17dca4f0
@ -71,12 +71,31 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
#include <private/qmemory_p.h>
|
#include <private/qmemory_p.h>
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#include "qxmlstream_p.h"
|
#include "qxmlstream_p.h"
|
||||||
|
|
||||||
enum { StreamEOF = ~0U };
|
enum { StreamEOF = ~0U };
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <typename Range>
|
||||||
|
auto reversed(Range &r)
|
||||||
|
{
|
||||||
|
struct R {
|
||||||
|
Range *r;
|
||||||
|
auto begin() { return std::make_reverse_iterator(std::end(*r)); }
|
||||||
|
auto end() { return std::make_reverse_iterator(std::begin(*r)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
return R{&r};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Range>
|
||||||
|
void reversed(const Range &&) = delete;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\enum QXmlStreamReader::TokenType
|
\enum QXmlStreamReader::TokenType
|
||||||
|
|
||||||
@ -1562,8 +1581,7 @@ uint QXmlStreamReaderPrivate::getChar_helper()
|
|||||||
|
|
||||||
QStringRef QXmlStreamReaderPrivate::namespaceForPrefix(const QStringRef &prefix)
|
QStringRef QXmlStreamReaderPrivate::namespaceForPrefix(const QStringRef &prefix)
|
||||||
{
|
{
|
||||||
for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
|
for (const NamespaceDeclaration &namespaceDeclaration : reversed(namespaceDeclarations)) {
|
||||||
const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(j);
|
|
||||||
if (namespaceDeclaration.prefix == prefix) {
|
if (namespaceDeclaration.prefix == prefix) {
|
||||||
return namespaceDeclaration.namespaceUri;
|
return namespaceDeclaration.namespaceUri;
|
||||||
}
|
}
|
||||||
@ -3240,8 +3258,7 @@ bool QXmlStreamWriterPrivate::finishStartElement(bool contents)
|
|||||||
|
|
||||||
QXmlStreamPrivateTagStack::NamespaceDeclaration &QXmlStreamWriterPrivate::findNamespace(const QString &namespaceUri, bool writeDeclaration, bool noDefault)
|
QXmlStreamPrivateTagStack::NamespaceDeclaration &QXmlStreamWriterPrivate::findNamespace(const QString &namespaceUri, bool writeDeclaration, bool noDefault)
|
||||||
{
|
{
|
||||||
for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
|
for (NamespaceDeclaration &namespaceDeclaration : reversed(namespaceDeclarations)) {
|
||||||
NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations[j];
|
|
||||||
if (namespaceDeclaration.namespaceUri == namespaceUri) {
|
if (namespaceDeclaration.namespaceUri == namespaceUri) {
|
||||||
if (!noDefault || !namespaceDeclaration.prefix.isEmpty())
|
if (!noDefault || !namespaceDeclaration.prefix.isEmpty())
|
||||||
return namespaceDeclaration;
|
return namespaceDeclaration;
|
||||||
|
Loading…
Reference in New Issue
Block a user