QXmlStreamReader: use qOffsetStringArray for storing token types

Change-Id: I9e58c17d97c44e1b13899d30396f65b452d8600f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Sona Kurazyan 2022-09-02 16:52:04 +02:00
parent d6fae59faa
commit d674f3f545
1 changed files with 16 additions and 51 deletions

View File

@ -15,6 +15,8 @@
#include <qscopeguard.h>
#include <qcoreapplication.h>
#include <private/qoffsetstringarray_p.h>
#include <iterator>
#include "qxmlstream_p.h"
#include "qxmlstreamparser_p.h"
@ -668,55 +670,19 @@ void QXmlStreamReader::skipCurrentElement()
}
}
/*
* Use the following Perl script to generate the error string index list:
===== PERL SCRIPT ====
print "static const char QXmlStreamReader_tokenTypeString_string[] =\n";
$counter = 0;
$i = 0;
while (<STDIN>) {
chomp;
print " \"$_\\0\"\n";
$sizes[$i++] = $counter;
$counter += length 1 + $_;
}
print " \"\\0\";\n\nstatic const short QXmlStreamReader_tokenTypeString_indices[] = {\n ";
for ($j = 0; $j < $i; ++$j) {
printf "$sizes[$j], ";
}
print "0\n};\n";
===== PERL SCRIPT ====
* The input data is as follows (copied from qxmlstream.h):
NoToken
Invalid
StartDocument
EndDocument
StartElement
EndElement
Characters
Comment
DTD
EntityReference
ProcessingInstruction
*/
static const char QXmlStreamReader_tokenTypeString_string[] =
"NoToken\0"
"Invalid\0"
"StartDocument\0"
"EndDocument\0"
"StartElement\0"
"EndElement\0"
"Characters\0"
"Comment\0"
"DTD\0"
"EntityReference\0"
"ProcessingInstruction\0";
static const short QXmlStreamReader_tokenTypeString_indices[] = {
0, 8, 16, 30, 42, 55, 66, 77, 85, 89, 105, 0
};
static constexpr auto QXmlStreamReader_tokenTypeString = qOffsetStringArray(
"NoToken",
"Invalid",
"StartDocument",
"EndDocument",
"StartElement",
"EndElement",
"Characters",
"Comment",
"DTD",
"EntityReference",
"ProcessingInstruction"
);
/*!
\property QXmlStreamReader::namespaceProcessing
@ -749,8 +715,7 @@ bool QXmlStreamReader::namespaceProcessing() const
QString QXmlStreamReader::tokenString() const
{
Q_D(const QXmlStreamReader);
return QLatin1StringView(QXmlStreamReader_tokenTypeString_string +
QXmlStreamReader_tokenTypeString_indices[d->type]);
return QLatin1StringView(QXmlStreamReader_tokenTypeString.at(d->type));
}
#endif // QT_NO_XMLSTREAMREADER