summaryrefslogtreecommitdiff
path: root/fxbarcode
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-04-11 17:55:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-11 17:55:00 +0000
commit7b77dfc9aafb423e6204dd5433699cfd787147b3 (patch)
treefd8e728f993718385e1fc1d33942577bf1c4c1a2 /fxbarcode
parent63c5fa9cf2250dcd91dd88d8233c0d9d93b1d917 (diff)
downloadpdfium-7b77dfc9aafb423e6204dd5433699cfd787147b3.tar.xz
Reserve space to reduce memory operations while encoding barcode
In the test case from the bug, the majority of the time is being spent resizing Widestring internal buffers, since += is being called in a tight loop. Since the size of the input being mutated and stored is known, this CL reserves the space before hand to lower thrashing. This substantially improves runtime of this test case locally. BUG=chromium:802242 Change-Id: I5176dabc94634b4d6bc3e9425fe6469a5bf35a41 Reviewed-on: https://pdfium-review.googlesource.com/30190 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'fxbarcode')
-rw-r--r--fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index ffc057a5f6..6dd7ee5191 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -61,8 +61,9 @@ WideString CBC_PDF417HighLevelEncoder::encodeHighLevel(WideString wideMsg,
int32_t& e) {
ByteString bytes;
CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes);
- WideString msg;
int32_t len = bytes.GetLength();
+ WideString msg;
+ msg.Reserve(len);
for (int32_t i = 0; i < len; i++) {
wchar_t ch = (wchar_t)(bytes[i] & 0xff);
if (ch == '?' && bytes[i] != '?') {
@@ -72,8 +73,9 @@ WideString CBC_PDF417HighLevelEncoder::encodeHighLevel(WideString wideMsg,
msg += ch;
}
std::vector<uint8_t> byteArr(bytes.begin(), bytes.end());
- WideString sb;
len = msg.GetLength();
+ WideString sb;
+ sb.Reserve(len);
int32_t p = 0;
int32_t textSubMode = SUBMODE_ALPHA;
if (compaction == TEXT) {