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

Side by Side Diff: third_party/re2/util/sparse_array.h

Issue 149723005: Patch re2 to support MSan. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address eugenis's suggestions Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/re2/patches/re2-msan.patch ('k') | third_party/re2/util/sparse_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 valgrind_(RunningOnValgrindOrMemorySanitizer()) {}
235 236
236 // IndexValue pairs: exposed in SparseArray::iterator. 237 // IndexValue pairs: exposed in SparseArray::iterator.
237 template<typename Value> 238 template<typename Value>
238 class SparseArray<Value>::IndexValue { 239 class SparseArray<Value>::IndexValue {
239 friend class SparseArray; 240 friend class SparseArray;
240 public: 241 public:
241 typedef int first_type; 242 typedef int first_type;
242 typedef Value second_type; 243 typedef Value second_type;
243 244
244 IndexValue() {} 245 IndexValue() {}
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 DCHECK(!has_index(i)); 412 DCHECK(!has_index(i));
412 DCHECK_LT(size_, max_size_); 413 DCHECK_LT(size_, max_size_);
413 sparse_to_dense_[i] = size_; 414 sparse_to_dense_[i] = size_;
414 dense_[size_].index_ = i; 415 dense_[size_].index_ = i;
415 size_++; 416 size_++;
416 } 417 }
417 418
418 template<typename Value> SparseArray<Value>::SparseArray(int max_size) { 419 template<typename Value> SparseArray<Value>::SparseArray(int max_size) {
419 max_size_ = max_size; 420 max_size_ = max_size;
420 sparse_to_dense_ = new int[max_size]; 421 sparse_to_dense_ = new int[max_size];
421 valgrind_ = RunningOnValgrind(); 422 valgrind_ = RunningOnValgrindOrMemorySanitizer();
422 dense_.resize(max_size); 423 dense_.resize(max_size);
423 // Don't need to zero the new memory, but appease Valgrind. 424 // Don't need to zero the new memory, but appease Valgrind.
424 if (valgrind_) { 425 if (valgrind_) {
425 for (int i = 0; i < max_size; i++) { 426 for (int i = 0; i < max_size; i++) {
426 sparse_to_dense_[i] = 0xababababU; 427 sparse_to_dense_[i] = 0xababababU;
427 dense_[i].index_ = 0xababababU; 428 dense_[i].index_ = 0xababababU;
428 } 429 }
429 } 430 }
430 size_ = 0; 431 size_ = 0;
431 DebugCheckInvariants(); 432 DebugCheckInvariants();
(...skipping 12 matching lines...) Expand all
444 445
445 // Comparison function for sorting. 446 // Comparison function for sorting.
446 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a, 447 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a,
447 const IndexValue& b) { 448 const IndexValue& b) {
448 return a.index_ < b.index_; 449 return a.index_ < b.index_;
449 } 450 }
450 451
451 } // namespace re2 452 } // namespace re2
452 453
453 #endif // RE2_UTIL_SPARSE_ARRAY_H__ 454 #endif // RE2_UTIL_SPARSE_ARRAY_H__
OLDNEW
« no previous file with comments | « third_party/re2/patches/re2-msan.patch ('k') | third_party/re2/util/sparse_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698