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

Unified Diff: third_party/re2/util/sparse_set.h

Issue 1530113002: Revert of Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « third_party/re2/util/sparse_array_test.cc ('k') | third_party/re2/util/stringpiece.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9dd41eed7815d8653ae9c2c6de9b429f96009689..4a324d7c7cb6710261ff584146d14ac5039bd572 100644
--- a/third_party/re2/util/sparse_set.h
+++ b/third_party/re2/util/sparse_set.h
@@ -54,15 +54,17 @@
class SparseSet {
public:
SparseSet()
- : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL) {}
+ : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL),
+ valgrind_(RunningOnValgrindOrMemorySanitizer()) {}
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 (InitMemory()) {
+ if (valgrind_) {
for (int i = 0; i < max_size; i++) {
dense_[i] = 0xababababU;
sparse_to_dense_[i] = 0xababababU;
@@ -94,7 +96,7 @@
int* a = new int[new_max_size];
if (sparse_to_dense_) {
memmove(a, sparse_to_dense_, max_size_*sizeof a[0]);
- if (InitMemory()) {
+ if (valgrind_) {
for (int i = max_size_; i < new_max_size; i++)
a[i] = 0xababababU;
}
@@ -105,7 +107,7 @@
a = new int[new_max_size];
if (dense_) {
memmove(a, dense_, size_*sizeof a[0]);
- if (InitMemory()) {
+ if (valgrind_) {
for (int i = size_; i < new_max_size; i++)
a[i] = 0xababababU;
}
@@ -127,7 +129,7 @@
bool contains(int i) const {
DCHECK_GE(i, 0);
DCHECK_LT(i, max_size_);
- if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
+ if (static_cast<uint>(i) >= max_size_) {
return false;
}
// Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
@@ -144,7 +146,7 @@
// 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) >= static_cast<uint>(max_size_)) {
+ if (static_cast<uint>(i) >= 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.
@@ -164,20 +166,13 @@
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_COPY_AND_ASSIGN(SparseSet);
+ DISALLOW_EVIL_CONSTRUCTORS(SparseSet);
};
} // namespace re2
« no previous file with comments | « third_party/re2/util/sparse_array_test.cc ('k') | third_party/re2/util/stringpiece.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698