Append in-place in ExportEncodeAttribute()
Avoid copying from a text buf to a widestring, then from that widestring
onto the end of another widestring. Unfortunately requires wide literals
since wide strings don't have an AppendASCII() method (yet).
Change-Id: I57c613942baa9b7f9ac81d40b191351265d06ea1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/88090
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 2f199cf..b69e9a4 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -31,31 +31,28 @@
const char kFormNS[] = "http://www.xfa.org/schema/xfa-form/";
-WideString ExportEncodeAttribute(const WideString& str) {
- CFX_WideTextBuf textBuf;
- int32_t iLen = str.GetLength();
- for (int32_t i = 0; i < iLen; i++) {
+void ExportEncodeAttribute(const WideString& str, WideString& textBuf) {
+ for (size_t i = 0; i < str.GetLength(); i++) {
switch (str[i]) {
case '&':
- textBuf << "&";
+ textBuf += L"&";
break;
case '<':
- textBuf << "<";
+ textBuf += L"<";
break;
case '>':
- textBuf << ">";
+ textBuf += L">";
break;
case '\'':
- textBuf << "'";
+ textBuf += L"'";
break;
case '\"':
- textBuf << """;
+ textBuf += L""";
break;
default:
- textBuf.AppendChar(str[i]);
+ textBuf += str[i];
}
}
- return textBuf.MakeString();
}
bool IsXMLValidChar(wchar_t ch) {
@@ -148,7 +145,7 @@
wsOutput += L" ";
wsOutput += wsName;
wsOutput += L"=\"";
- wsOutput += ExportEncodeAttribute(value.value());
+ ExportEncodeAttribute(value.value(), wsOutput);
wsOutput += L"\"";
}