Avoid copy between CFX_WideTextBuf and WideString in CFX_UTF8Decoder.
I suspect CFX_UTF8Decoder initially used WideTextBuf because it
grew exponentially, but widestrings only used to grow at a
constant increment. Buf we changed that a while ago (and strings
now grow at 1.5x vs. WideTextBufs 1.25x).
Change-Id: If56ba6ae1f7eb31d78732282e6ff910d6045fd48
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/87733
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/cfx_utf8decoder.cpp b/core/fxcrt/cfx_utf8decoder.cpp
index 68ea30a..df29f44 100644
--- a/core/fxcrt/cfx_utf8decoder.cpp
+++ b/core/fxcrt/cfx_utf8decoder.cpp
@@ -6,18 +6,24 @@
#include "core/fxcrt/cfx_utf8decoder.h"
+#include <utility>
+
CFX_UTF8Decoder::CFX_UTF8Decoder() = default;
CFX_UTF8Decoder::~CFX_UTF8Decoder() = default;
+WideString CFX_UTF8Decoder::TakeResult() {
+ return std::move(m_Buffer);
+}
+
void CFX_UTF8Decoder::AppendCodePoint(uint32_t ch) {
- m_Buffer.AppendChar(static_cast<wchar_t>(ch));
+ m_Buffer += static_cast<wchar_t>(ch);
}
void CFX_UTF8Decoder::Input(uint8_t byte) {
if (byte < 0x80) {
m_PendingBytes = 0;
- m_Buffer.AppendChar(byte);
+ AppendCodePoint(byte);
} else if (byte < 0xc0) {
if (m_PendingBytes == 0) {
return;
diff --git a/core/fxcrt/cfx_utf8decoder.h b/core/fxcrt/cfx_utf8decoder.h
index af14a04..9e662ea 100644
--- a/core/fxcrt/cfx_utf8decoder.h
+++ b/core/fxcrt/cfx_utf8decoder.h
@@ -7,7 +7,7 @@
#ifndef CORE_FXCRT_CFX_UTF8DECODER_H_
#define CORE_FXCRT_CFX_UTF8DECODER_H_
-#include "core/fxcrt/cfx_widetextbuf.h"
+#include "core/fxcrt/widestring.h"
class CFX_UTF8Decoder {
public:
@@ -15,14 +15,14 @@
~CFX_UTF8Decoder();
void Input(uint8_t byte);
- WideStringView GetResult() const { return m_Buffer.AsStringView(); }
+ WideString TakeResult();
private:
void AppendCodePoint(uint32_t ch);
int m_PendingBytes = 0;
uint32_t m_PendingChar = 0;
- CFX_WideTextBuf m_Buffer;
+ WideString m_Buffer;
};
#endif // CORE_FXCRT_CFX_UTF8DECODER_H_
diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp
index 46961d4..96675d9 100644
--- a/core/fxcrt/fx_string.cpp
+++ b/core/fxcrt/fx_string.cpp
@@ -28,7 +28,7 @@
for (size_t i = 0; i < bsStr.GetLength(); i++)
decoder.Input(bsStr[i]);
- return WideString(decoder.GetResult());
+ return decoder.TakeResult();
}
namespace {