Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: components/packed_ct_ev_whitelist/bit_stream_reader.cc

Issue 1070903003: Optimize BitStreamReader, speed up EV Whitelist loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary &0xff - forgot uint8_t is exactly 1 byte not at least 1 byte Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/packed_ct_ev_whitelist/bit_stream_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/packed_ct_ev_whitelist/bit_stream_reader.cc
diff --git a/components/packed_ct_ev_whitelist/bit_stream_reader.cc b/components/packed_ct_ev_whitelist/bit_stream_reader.cc
index e4f6cc7b64a8896055bc56dd85f272d891b7f745..94ef00904bbd9ae79758a6f24552022be90184bb 100644
--- a/components/packed_ct_ev_whitelist/bit_stream_reader.cc
+++ b/components/packed_ct_ev_whitelist/bit_stream_reader.cc
@@ -34,8 +34,13 @@ bool BitStreamReader::ReadBits(uint8_t num_bits, uint64_t* out) {
return false;
*out = 0;
- for (uint8_t i = 0; i < num_bits; ++i)
- (*out) |= (static_cast<uint64_t>(ReadBit()) << (num_bits - (i + 1)));
+
+ for (; num_bits && (current_bit_ != 7); --num_bits)
+ (*out) |= (static_cast<uint64_t>(ReadBit()) << (num_bits - 1));
+ for (; num_bits / 8; num_bits -= 8)
+ (*out) |= (static_cast<uint64_t>(ReadByte()) << (num_bits - 8));
+ for (; num_bits; --num_bits)
+ (*out) |= (static_cast<uint64_t>(ReadBit()) << (num_bits - 1));
return true;
}
@@ -61,5 +66,13 @@ uint8_t BitStreamReader::ReadBit() {
return res;
}
+uint8_t BitStreamReader::ReadByte() {
+ DCHECK_GT(BitsLeft(), 7u);
+ DCHECK_EQ(current_bit_, 7);
+
+ return source_.data()[current_byte_++];
+
+}
+
} // namespace internal
} // namespace packed_ct_ev_whitelist
« no previous file with comments | « components/packed_ct_ev_whitelist/bit_stream_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698