| Index: third_party/re2/util/sparse_set.h
|
| diff --git a/third_party/re2/util/sparse_set.h b/third_party/re2/util/sparse_set.h
|
| index 4a324d7c7cb6710261ff584146d14ac5039bd572..9dd41eed7815d8653ae9c2c6de9b429f96009689 100644
|
| --- a/third_party/re2/util/sparse_set.h
|
| +++ b/third_party/re2/util/sparse_set.h
|
| @@ -54,17 +54,15 @@ namespace re2 {
|
| class SparseSet {
|
| public:
|
| SparseSet()
|
| - : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL),
|
| - valgrind_(RunningOnValgrindOrMemorySanitizer()) {}
|
| + : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL) {}
|
|
|
| SparseSet(int max_size) {
|
| max_size_ = max_size;
|
| sparse_to_dense_ = new int[max_size];
|
| dense_ = new int[max_size];
|
| - valgrind_ = RunningOnValgrindOrMemorySanitizer();
|
| // Don't need to zero the memory, but do so anyway
|
| // to appease Valgrind.
|
| - if (valgrind_) {
|
| + if (InitMemory()) {
|
| for (int i = 0; i < max_size; i++) {
|
| dense_[i] = 0xababababU;
|
| sparse_to_dense_[i] = 0xababababU;
|
| @@ -96,7 +94,7 @@ class SparseSet {
|
| int* a = new int[new_max_size];
|
| if (sparse_to_dense_) {
|
| memmove(a, sparse_to_dense_, max_size_*sizeof a[0]);
|
| - if (valgrind_) {
|
| + if (InitMemory()) {
|
| for (int i = max_size_; i < new_max_size; i++)
|
| a[i] = 0xababababU;
|
| }
|
| @@ -107,7 +105,7 @@ class SparseSet {
|
| a = new int[new_max_size];
|
| if (dense_) {
|
| memmove(a, dense_, size_*sizeof a[0]);
|
| - if (valgrind_) {
|
| + if (InitMemory()) {
|
| for (int i = size_; i < new_max_size; i++)
|
| a[i] = 0xababababU;
|
| }
|
| @@ -129,7 +127,7 @@ class SparseSet {
|
| bool contains(int i) const {
|
| DCHECK_GE(i, 0);
|
| DCHECK_LT(i, max_size_);
|
| - if (static_cast<uint>(i) >= max_size_) {
|
| + if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
|
| return false;
|
| }
|
| // Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
|
| @@ -146,7 +144,7 @@ class SparseSet {
|
| // Set the value at the new index i to v.
|
| // Fast but unsafe: only use if contains(i) is false.
|
| void insert_new(int i) {
|
| - if (static_cast<uint>(i) >= max_size_) {
|
| + if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
|
| // Semantically, end() would be better here, but we already know
|
| // the user did something stupid, so begin() insulates them from
|
| // dereferencing an invalid pointer.
|
| @@ -166,13 +164,20 @@ class SparseSet {
|
| static bool less(int a, int b) { return a < b; }
|
|
|
| private:
|
| + static bool InitMemory() {
|
| +#ifdef MEMORY_SANITIZER
|
| + return true;
|
| +#else
|
| + return RunningOnValgrind();
|
| +#endif
|
| + }
|
| +
|
| int size_;
|
| int max_size_;
|
| int* sparse_to_dense_;
|
| int* dense_;
|
| - bool valgrind_;
|
|
|
| - DISALLOW_EVIL_CONSTRUCTORS(SparseSet);
|
| + DISALLOW_COPY_AND_ASSIGN(SparseSet);
|
| };
|
|
|
| } // namespace re2
|
|
|