From 94161d59fd3c815e404fb3f027becf056516a5da Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Mon, 30 Apr 2018 18:35:03 +0000 Subject: 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 Commit-Queue: Ryan Harrison --- fxbarcode/oned/BC_OnedCode128Writer.cpp | 14 ++++++-------- 1 file 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) { -- cgit v1.2.3