 Chromium Code Reviews
 Chromium Code Reviews Issue 149723005:
  Patch re2 to support MSan.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 149723005:
  Patch re2 to support MSan.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright 2006 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2006 The RE2 Authors. All Rights Reserved. | 
| 2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style | 
| 3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 // DESCRIPTION | 5 // DESCRIPTION | 
| 6 // | 6 // | 
| 7 // SparseArray<T>(m) is a map from integers in [0, m) to T values. | 7 // SparseArray<T>(m) is a map from integers in [0, m) to T values. | 
| 8 // It requires (sizeof(T)+sizeof(int))*m memory, but it provides | 8 // It requires (sizeof(T)+sizeof(int))*m memory, but it provides | 
| 9 // fast iteration through the elements in the array and fast clearing | 9 // fast iteration through the elements in the array and fast clearing | 
| 10 // of the array. The array has a concept of certain elements being | 10 // of the array. The array has a concept of certain elements being | 
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 int max_size_; | 224 int max_size_; | 
| 225 int* sparse_to_dense_; | 225 int* sparse_to_dense_; | 
| 226 vector<IndexValue> dense_; | 226 vector<IndexValue> dense_; | 
| 227 bool valgrind_; | 227 bool valgrind_; | 
| 228 | 228 | 
| 229 DISALLOW_EVIL_CONSTRUCTORS(SparseArray); | 229 DISALLOW_EVIL_CONSTRUCTORS(SparseArray); | 
| 230 }; | 230 }; | 
| 231 | 231 | 
| 232 template<typename Value> | 232 template<typename Value> | 
| 233 SparseArray<Value>::SparseArray() | 233 SparseArray<Value>::SparseArray() | 
| 234 : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(), valgrind_(Runnin gOnValgrind()) {} | 234 : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(), | 
| 235 #if defined(MEMORY_SANITIZER) | |
| 
eugenis
2014/01/30 09:02:55
I think it would be cleaner to implement RunningOn
 | |
| 236 valgrind_(true) | |
| 237 #else | |
| 238 valgrind_(RunningOnValgrind()) | |
| 239 #endif | |
| 240 { | |
| 241 } | |
| 235 | 242 | 
| 236 // IndexValue pairs: exposed in SparseArray::iterator. | 243 // IndexValue pairs: exposed in SparseArray::iterator. | 
| 237 template<typename Value> | 244 template<typename Value> | 
| 238 class SparseArray<Value>::IndexValue { | 245 class SparseArray<Value>::IndexValue { | 
| 239 friend class SparseArray; | 246 friend class SparseArray; | 
| 240 public: | 247 public: | 
| 241 typedef int first_type; | 248 typedef int first_type; | 
| 242 typedef Value second_type; | 249 typedef Value second_type; | 
| 243 | 250 | 
| 244 IndexValue() {} | 251 IndexValue() {} | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 DCHECK(!has_index(i)); | 418 DCHECK(!has_index(i)); | 
| 412 DCHECK_LT(size_, max_size_); | 419 DCHECK_LT(size_, max_size_); | 
| 413 sparse_to_dense_[i] = size_; | 420 sparse_to_dense_[i] = size_; | 
| 414 dense_[size_].index_ = i; | 421 dense_[size_].index_ = i; | 
| 415 size_++; | 422 size_++; | 
| 416 } | 423 } | 
| 417 | 424 | 
| 418 template<typename Value> SparseArray<Value>::SparseArray(int max_size) { | 425 template<typename Value> SparseArray<Value>::SparseArray(int max_size) { | 
| 419 max_size_ = max_size; | 426 max_size_ = max_size; | 
| 420 sparse_to_dense_ = new int[max_size]; | 427 sparse_to_dense_ = new int[max_size]; | 
| 428 #if defined(MEMORY_SANITIZER) | |
| 429 valgrind_ = true; | |
| 430 #else | |
| 421 valgrind_ = RunningOnValgrind(); | 431 valgrind_ = RunningOnValgrind(); | 
| 432 #endif | |
| 422 dense_.resize(max_size); | 433 dense_.resize(max_size); | 
| 423 // Don't need to zero the new memory, but appease Valgrind. | 434 // Don't need to zero the new memory, but appease Valgrind. | 
| 424 if (valgrind_) { | 435 if (valgrind_) { | 
| 425 for (int i = 0; i < max_size; i++) { | 436 for (int i = 0; i < max_size; i++) { | 
| 426 sparse_to_dense_[i] = 0xababababU; | 437 sparse_to_dense_[i] = 0xababababU; | 
| 427 dense_[i].index_ = 0xababababU; | 438 dense_[i].index_ = 0xababababU; | 
| 428 } | 439 } | 
| 429 } | 440 } | 
| 430 size_ = 0; | 441 size_ = 0; | 
| 431 DebugCheckInvariants(); | 442 DebugCheckInvariants(); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 444 | 455 | 
| 445 // Comparison function for sorting. | 456 // Comparison function for sorting. | 
| 446 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a, | 457 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a, | 
| 447 const IndexValue& b) { | 458 const IndexValue& b) { | 
| 448 return a.index_ < b.index_; | 459 return a.index_ < b.index_; | 
| 449 } | 460 } | 
| 450 | 461 | 
| 451 } // namespace re2 | 462 } // namespace re2 | 
| 452 | 463 | 
| 453 #endif // RE2_UTIL_SPARSE_ARRAY_H__ | 464 #endif // RE2_UTIL_SPARSE_ARRAY_H__ | 
| OLD | NEW |