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

Unified Diff: chrome/browser/safe_browsing/prefix_set.cc

Issue 6711021: Safe-browsing PrefixSet cleanups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: log when size is broken Created 9 years, 9 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 | « chrome/browser/safe_browsing/prefix_set.h ('k') | chrome/browser/safe_browsing/prefix_set_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/prefix_set.cc
diff --git a/chrome/browser/safe_browsing/prefix_set.cc b/chrome/browser/safe_browsing/prefix_set.cc
index 72ceb6f3d472b101e29bc0e6499200f4e2c72ab3..e72eb57b21b61868a3640d5d1b8fc14e8154cc54 100644
--- a/chrome/browser/safe_browsing/prefix_set.cc
+++ b/chrome/browser/safe_browsing/prefix_set.cc
@@ -54,17 +54,18 @@ PrefixSet::PrefixSet(const std::vector<SBPrefix>& sorted_prefixes) {
// Calculate the delta. |unsigned| is mandatory, because the
// sorted_prefixes could be more than INT_MAX apart.
DCHECK_GT(sorted_prefixes[i], prev_prefix);
- unsigned delta = sorted_prefixes[i] - prev_prefix;
+ const unsigned delta = sorted_prefixes[i] - prev_prefix;
+ const uint16 delta16 = static_cast<uint16>(delta);
- // New index ref if the delta is too wide, or if too many
- // consecutive deltas have been encoded. Note that
- // |kMaxDelta| cannot itself be encoded.
- if (delta >= kMaxDelta || run_length >= kMaxRun) {
+ // New index ref if the delta doesn't fit, or if too many
+ // consecutive deltas have been encoded.
+ if (delta != static_cast<unsigned>(delta16) || run_length >= kMaxRun) {
index_.push_back(std::make_pair(sorted_prefixes[i], deltas_.size()));
run_length = 0;
} else {
// Continue the run of deltas.
- deltas_.push_back(static_cast<uint16>(delta));
+ deltas_.push_back(delta16);
+ DCHECK_EQ(static_cast<unsigned>(deltas_.back()), delta);
++run_length;
}
@@ -125,7 +126,7 @@ bool PrefixSet::Exists(SBPrefix prefix) const {
return current == prefix;
}
-void PrefixSet::GetPrefixes(std::vector<SBPrefix>* prefixes) {
+void PrefixSet::GetPrefixes(std::vector<SBPrefix>* prefixes) const {
for (size_t ii = 0; ii < index_.size(); ++ii) {
// The deltas for this |index_| entry run to the next index entry,
// or the end of the deltas.
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.h ('k') | chrome/browser/safe_browsing/prefix_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698