Small optimizations for CBC_HighLevelEncoder::lookAheadTest
Currently ClusterFuzz is timing out when running cases that cause a
large number of calls to this method. Looking at the cases, I believe
these to be valid calls, so this CL attempts to lower the cost of
making each individual call.
Adds in pre-allocation of a vector that has a fixed size and uses a
const-ref for passing in |msg| to avoid copying.
BUG=chromium:881678
Change-Id: I61ec4dc96e79c84def5b10102cc58a96773ce07f
Reviewed-on: https://pdfium-review.googlesource.com/42230
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index 56a8847..f143ac2 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -127,27 +127,17 @@
}
return codewords;
}
-int32_t CBC_HighLevelEncoder::lookAheadTest(WideString msg,
+int32_t CBC_HighLevelEncoder::lookAheadTest(const WideString& msg,
int32_t startpos,
int32_t currentMode) {
if (startpos >= pdfium::base::checked_cast<int32_t>(msg.GetLength())) {
return currentMode;
}
- std::vector<float> charCounts;
+ std::vector<float> charCounts(6);
if (currentMode == ASCII_ENCODATION) {
- charCounts.push_back(0);
- charCounts.push_back(1);
- charCounts.push_back(1);
- charCounts.push_back(1);
- charCounts.push_back(1);
- charCounts.push_back(1.25f);
+ charCounts = {0, 1, 1, 1, 1, 1.25f};
} else {
- charCounts.push_back(1);
- charCounts.push_back(2);
- charCounts.push_back(2);
- charCounts.push_back(2);
- charCounts.push_back(2);
- charCounts.push_back(2.25f);
+ charCounts = {1, 2, 2, 2, 2, 2.25f};
charCounts[currentMode] = 0;
}
int32_t charsProcessed = 0;
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
index 50cfc8c..9ad0d70 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.h
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
@@ -29,7 +29,7 @@
WideString ecLevel,
bool allowRectangular,
int32_t& e);
- static int32_t lookAheadTest(WideString msg,
+ static int32_t lookAheadTest(const WideString& msg,
int32_t startpos,
int32_t currentMode);
static bool isDigit(wchar_t ch);