Less string copies of text in XML parsing.
Change-Id: I5bf80de3da7ae4bd91dd7675a9af16d377c014aa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/366409
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/xml/SkXMLParser.cpp b/src/xml/SkXMLParser.cpp
index fb31e06..7432ae8 100644
--- a/src/xml/SkXMLParser.cpp
+++ b/src/xml/SkXMLParser.cpp
@@ -5,15 +5,16 @@
* found in the LICENSE file.
*/
-#include "src/xml/SkXMLParser.h"
-
-#include "expat.h"
-
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/SkTemplates.h"
#include "include/private/SkTo.h"
+#include "src/xml/SkXMLParser.h"
+
+#include <expat.h>
+
+#include <vector>
static char const* const gErrorStrings[] = {
"empty or missing file ",
@@ -70,21 +71,21 @@
, fXMLParser(XML_ParserCreate_MM(nullptr, &sk_XML_alloc, nullptr)) { }
void flushText() {
- if (!fBufferedText.isEmpty()) {
- fParser->text(fBufferedText.c_str(), SkTo<int>(fBufferedText.size()));
- fBufferedText.reset();
+ if (!fBufferedText.empty()) {
+ fParser->text(fBufferedText.data(), SkTo<int>(fBufferedText.size()));
+ fBufferedText.clear();
}
}
void appendText(const char* txt, size_t len) {
- fBufferedText.append(txt, len);
+ fBufferedText.insert(fBufferedText.end(), txt, &txt[len]);
}
SkXMLParser* fParser;
SkAutoTCallVProc<std::remove_pointer_t<XML_Parser>, XML_ParserFree> fXMLParser;
private:
- SkString fBufferedText;
+ std::vector<char> fBufferedText;
};
#define HANDLER_CONTEXT(arg, name) ParsingContext* name = static_cast<ParsingContext*>(arg)