summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-16 18:41:42 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-16 18:41:42 +0000
commit33515fbec463e3038b3d54fb74fe4b51af1791c6 (patch)
treec812c4f37a52ad78d03b9bfe293aeec98233f35c
parentdebd2d23306313712a60a7c380ece864f7a3a9ab (diff)
downloadpdfium-33515fbec463e3038b3d54fb74fe4b51af1791c6.tar.xz
Do more optimizations to make FindBit() faster.chromium/3433
Change-Id: Ibbc020393e38405f9d1cb0d483ef875777d4e721 Reviewed-on: https://pdfium-review.googlesource.com/32650 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fxcodec/codec/fx_codec_fax.cpp42
1 files changed, 12 insertions, 30 deletions
diff --git a/core/fxcodec/codec/fx_codec_fax.cpp b/core/fxcodec/codec/fx_codec_fax.cpp
index 09d0ebc157..4a70b5302e 100644
--- a/core/fxcodec/codec/fx_codec_fax.cpp
+++ b/core/fxcodec/codec/fx_codec_fax.cpp
@@ -31,19 +31,6 @@ const uint8_t OneLeadPos[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-const uint8_t ZeroLeadPos[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8,
-};
// Limit of image dimension. Use the same limit as the JBIG2 codecs.
const int kMaxImageDimension = 65535;
@@ -53,20 +40,17 @@ int FindBit(const uint8_t* data_buf, int max_pos, int start_pos, bool bit) {
if (start_pos >= max_pos)
return max_pos;
- const uint8_t* leading_pos = bit ? OneLeadPos : ZeroLeadPos;
- if (start_pos % 8) {
- uint8_t data = data_buf[start_pos / 8];
- if (bit)
- data &= 0xff >> (start_pos % 8);
- else
- data |= 0xff << (8 - start_pos % 8);
-
- if (leading_pos[data] < 8)
- return start_pos / 8 * 8 + leading_pos[data];
+ const uint8_t bit_xor = bit ? 0x00 : 0xff;
+ int bit_offset = start_pos % 8;
+ if (bit_offset) {
+ const int byte_pos = start_pos / 8;
+ uint8_t data = (data_buf[byte_pos] ^ bit_xor) & (0xff >> bit_offset);
+ if (data)
+ return byte_pos * 8 + OneLeadPos[data];
start_pos += 7;
}
- const uint8_t skip = bit ? 0x00 : 0xff;
+
const int max_byte = (max_pos + 7) / 8;
int byte_pos = start_pos / 8;
@@ -85,15 +69,13 @@ int FindBit(const uint8_t* data_buf, int max_pos, int start_pos, bool bit) {
}
while (byte_pos < max_byte) {
- if (data_buf[byte_pos] != skip)
- break;
+ uint8_t data = data_buf[byte_pos] ^ bit_xor;
+ if (data)
+ return std::min(byte_pos * 8 + OneLeadPos[data], max_pos);
++byte_pos;
}
- if (byte_pos == max_byte)
- return max_pos;
-
- return std::min(leading_pos[data_buf[byte_pos]] + byte_pos * 8, max_pos);
+ return max_pos;
}
void FaxG4FindB1B2(const std::vector<uint8_t>& ref_buf,