summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-15 01:36:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-15 01:36:51 +0000
commit12401f7d2dab48cc01387c58636c2e93db9c738d (patch)
tree4ab0dc643504b844e4a51cbe30267433ab768273
parentce03169f65a105f0abfbf737d162a3418ab5f637 (diff)
downloadpdfium-12401f7d2dab48cc01387c58636c2e93db9c738d.tar.xz
Read data in bigger chunks in fax codec code.
In case there are long runs of data to be skipped, FindBit() runs much faster reading and comparing 8 bytes at a time. BUG=chromium:834633 Change-Id: Ifc7b348d123c5a72cf09fbf53d764075f8abfba0 Reviewed-on: https://pdfium-review.googlesource.com/32513 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--core/fxcodec/codec/fx_codec_fax.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/fxcodec/codec/fx_codec_fax.cpp b/core/fxcodec/codec/fx_codec_fax.cpp
index 20280a3760..9739101fec 100644
--- a/core/fxcodec/codec/fx_codec_fax.cpp
+++ b/core/fxcodec/codec/fx_codec_fax.cpp
@@ -66,9 +66,21 @@ int FindBit(const uint8_t* data_buf, int max_pos, int start_pos, bool bit) {
start_pos += 7;
}
- uint8_t skip = bit ? 0x00 : 0xff;
+ const uint8_t skip = bit ? 0x00 : 0xff;
+ const int max_byte = (max_pos + 7) / 8;
int byte_pos = start_pos / 8;
- int max_byte = (max_pos + 7) / 8;
+
+ // Try reading in bigger chunks in case there are long runs to be skipped.
+ static constexpr int kBulkReadSize = 8;
+ if (max_byte >= kBulkReadSize && byte_pos < max_byte - kBulkReadSize) {
+ uint8_t skip_block[kBulkReadSize];
+ memset(skip_block, skip, kBulkReadSize);
+ while (byte_pos < max_byte - kBulkReadSize &&
+ memcmp(data_buf + byte_pos, skip_block, kBulkReadSize) == 0) {
+ byte_pos += kBulkReadSize;
+ }
+ }
+
while (byte_pos < max_byte) {
if (data_buf[byte_pos] != skip)
break;