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

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

Issue 1509953005: re2: Initialize sparse_to_dense_ on initial allocation under Valgrind. (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 unified diff | Download patch
« no previous file with comments | « third_party/re2/patches/sparse-array-valgrind.patch ('k') | no next file » | 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 // Change the maximum size of the array. 267 // Change the maximum size of the array.
268 // Invalidates all iterators. 268 // Invalidates all iterators.
269 template<typename Value> 269 template<typename Value>
270 void SparseArray<Value>::resize(int new_max_size) { 270 void SparseArray<Value>::resize(int new_max_size) {
271 DebugCheckInvariants(); 271 DebugCheckInvariants();
272 if (new_max_size > max_size_) { 272 if (new_max_size > max_size_) {
273 int* a = new int[new_max_size]; 273 int* a = new int[new_max_size];
274 if (sparse_to_dense_) { 274 if (sparse_to_dense_) {
275 memmove(a, sparse_to_dense_, max_size_*sizeof a[0]); 275 memmove(a, sparse_to_dense_, max_size_*sizeof a[0]);
276 // Don't need to zero the memory but appease Valgrind.
277 if (valgrind_) {
278 for (int i = max_size_; i < new_max_size; i++)
279 a[i] = 0xababababU;
280 }
281 delete[] sparse_to_dense_; 276 delete[] sparse_to_dense_;
282 } 277 }
278 // Don't need to zero the memory but appease Valgrind.
279 if (valgrind_) {
280 for (int i = max_size_; i < new_max_size; i++)
281 a[i] = 0xababababU;
282 }
283 sparse_to_dense_ = a; 283 sparse_to_dense_ = a;
284 284
285 dense_.resize(new_max_size); 285 dense_.resize(new_max_size);
286 } 286 }
287 max_size_ = new_max_size; 287 max_size_ = new_max_size;
288 if (size_ > max_size_) 288 if (size_ > max_size_)
289 size_ = max_size_; 289 size_ = max_size_;
290 DebugCheckInvariants(); 290 DebugCheckInvariants();
291 } 291 }
292 292
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 // Comparison function for sorting. 446 // Comparison function for sorting.
447 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a, 447 template<typename Value> bool SparseArray<Value>::less(const IndexValue& a,
448 const IndexValue& b) { 448 const IndexValue& b) {
449 return a.index_ < b.index_; 449 return a.index_ < b.index_;
450 } 450 }
451 451
452 } // namespace re2 452 } // namespace re2
453 453
454 #endif // RE2_UTIL_SPARSE_ARRAY_H__ 454 #endif // RE2_UTIL_SPARSE_ARRAY_H__
OLDNEW
« no previous file with comments | « third_party/re2/patches/sparse-array-valgrind.patch ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698