diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-04-30 18:35:03 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-30 18:35:03 +0000 |
commit | 94161d59fd3c815e404fb3f027becf056516a5da (patch) | |
tree | 2adedc73bd5c562cb49e216f3b7345ab587b7e0b | |
parent | da8063f087c379bfd286624338d31a112cae5ba4 (diff) | |
download | pdfium-94161d59fd3c815e404fb3f027becf056516a5da.tar.xz |
Optimize yet another piece of barcode code
Rolling two iterations over the input into one, and reserving the
maximum possibly output size to avoid memory thrash when
appending. Under Valgrind this reduces the instruction count by ~200x
BUG=chromium:837610
Change-Id: If12a3b98048b41906a4401d4dcc9470b513e28d2
Reviewed-on: https://pdfium-review.googlesource.com/31731
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r-- | fxbarcode/oned/BC_OnedCode128Writer.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp index 50d3fb65a6..034ffc3557 100644 --- a/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp @@ -95,22 +95,20 @@ bool CBC_OnedCode128Writer::CheckContentValidity( WideString CBC_OnedCode128Writer::FilterContents( const WideStringView& contents) { - WideString filterChineseChar; + const wchar_t limit = m_codeFormat == BC_CODE128_B ? 126 : 106; + + WideString filtered; + filtered.Reserve(contents.GetLength()); for (size_t i = 0; i < contents.GetLength(); i++) { wchar_t ch = contents[i]; if (ch > 175) { i++; continue; } - filterChineseChar += ch; - } - const wchar_t limit = m_codeFormat == BC_CODE128_B ? 126 : 106; - WideString filtercontents; - for (const auto& ch : filterChineseChar) { if (ch >= 32 && ch <= limit) - filtercontents += ch; + filtered += ch; } - return filtercontents; + return filtered; } bool CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) { |