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

Unified Diff: chrome/browser/sync/util/enum_set.h

Issue 8895008: [Sync] Relax EnumSet semantics for some functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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/sync/engine/nigori_util.cc ('k') | chrome/browser/sync/util/enum_set_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/enum_set.h
diff --git a/chrome/browser/sync/util/enum_set.h b/chrome/browser/sync/util/enum_set.h
index d12712267f22d9298e04a4820b8022a6a93025a4..51d3afec2ec7e32d4ad4861f176da6753c89c62f 100644
--- a/chrome/browser/sync/util/enum_set.h
+++ b/chrome/browser/sync/util/enum_set.h
@@ -65,8 +65,16 @@ class EnumSet {
// Process(it.Get());
// }
//
- // There are no guarantees as to what will happen if you modify an
- // EnumSet while traversing it with an iterator.
+ // The iterator must not be outlived by the set. In particular, the
+ // following is an error:
+ //
+ // EnumSet<...> SomeFn() { ... }
+ //
+ // /* ERROR */
+ // for (EnumSet<...>::Iterator it = SomeFun().First(); ...
+ //
+ // Also, there are no guarantees as to what will happen if you
+ // modify an EnumSet while traversing it with an iterator.
class Iterator {
public:
// A default-constructed iterator can't do anything except check
@@ -148,7 +156,7 @@ class EnumSet {
// self-mutating versions of Union, Intersection, and Difference
// (defined below).
- // Adds the given value to our set.
+ // Adds the given value (which must be in range) to our set.
void Put(E value) {
enums_.set(ToIndex(value));
}
@@ -165,9 +173,11 @@ class EnumSet {
enums_ &= other.enums_;
}
- // Removes the given value from our set.
+ // If the given value is in range, removes it from our set.
void Remove(E value) {
- enums_.reset(ToIndex(value));
+ if (InRange(value)) {
+ enums_.reset(ToIndex(value));
+ }
}
// Removes all values in the given set from our set.
@@ -180,9 +190,10 @@ class EnumSet {
enums_.reset();
}
- // Returns true iff the given value is a member of our set.
+ // Returns true iff the given value is in range and a member of our
+ // set.
bool Has(E value) const {
- return enums_.test(ToIndex(value));
+ return InRange(value) && enums_.test(ToIndex(value));
}
// Returns true iff the given set is a subset of our set.
@@ -221,6 +232,10 @@ class EnumSet {
explicit EnumSet(EnumBitSet enums) : enums_(enums) {}
+ static bool InRange(E value) {
+ return (value >= MinEnumValue) && (value <= MaxEnumValue);
+ }
+
// Converts a value to/from an index into |enums_|.
static size_t ToIndex(E value) {
« no previous file with comments | « chrome/browser/sync/engine/nigori_util.cc ('k') | chrome/browser/sync/util/enum_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698