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

Side by Side Diff: third_party/WebKit/Source/platform/wtf/TerminatedArrayBuilder.h

Issue 2833123002: Replace ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/wtf (Closed)
Patch Set: wtf Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #ifndef TerminatedArrayBuilder_h 4 #ifndef TerminatedArrayBuilder_h
5 #define TerminatedArrayBuilder_h 5 #define TerminatedArrayBuilder_h
6 6
7 #include "platform/wtf/Allocator.h" 7 #include "platform/wtf/Allocator.h"
8 8
9 namespace WTF { 9 namespace WTF {
10 10
(...skipping 23 matching lines...) Expand all
34 DCHECK(array_->at(count_ - 1).IsLastInArray()); 34 DCHECK(array_->at(count_ - 1).IsLastInArray());
35 capacity_ += count; 35 capacity_ += count;
36 array_ = ArrayType<T>::Allocator::Resize( 36 array_ = ArrayType<T>::Allocator::Resize(
37 ArrayType<T>::Allocator::Release(array_), capacity_); 37 ArrayType<T>::Allocator::Release(array_), capacity_);
38 array_->at(count_ - 1).SetLastInArray(false); 38 array_->at(count_ - 1).SetLastInArray(false);
39 } 39 }
40 array_->at(capacity_ - 1).SetLastInArray(true); 40 array_->at(capacity_ - 1).SetLastInArray(true);
41 } 41 }
42 42
43 void Append(const T& item) { 43 void Append(const T& item) {
44 RELEASE_ASSERT(count_ < capacity_); 44 CHECK_LT(count_, capacity_);
45 DCHECK(!item.IsLastInArray()); 45 DCHECK(!item.IsLastInArray());
46 array_->at(count_++) = item; 46 array_->at(count_++) = item;
47 if (count_ == capacity_) 47 if (count_ == capacity_)
48 array_->at(capacity_ - 1).SetLastInArray(true); 48 array_->at(capacity_ - 1).SetLastInArray(true);
49 } 49 }
50 50
51 typename ArrayType<T>::Allocator::PassPtr Release() { 51 typename ArrayType<T>::Allocator::PassPtr Release() {
52 RELEASE_ASSERT(count_ == capacity_); 52 CHECK_EQ(count_, capacity_);
53 AssertValid(); 53 AssertValid();
54 return ArrayType<T>::Allocator::Release(array_); 54 return ArrayType<T>::Allocator::Release(array_);
55 } 55 }
56 56
57 private: 57 private:
58 #if DCHECK_IS_ON() 58 #if DCHECK_IS_ON()
59 void AssertValid() { 59 void AssertValid() {
60 for (size_t i = 0; i < count_; ++i) { 60 for (size_t i = 0; i < count_; ++i) {
61 bool is_last_in_array = (i + 1 == count_); 61 bool is_last_in_array = (i + 1 == count_);
62 DCHECK_EQ(array_->at(i).IsLastInArray(), is_last_in_array); 62 DCHECK_EQ(array_->at(i).IsLastInArray(), is_last_in_array);
63 } 63 }
64 } 64 }
65 #else 65 #else
66 void AssertValid() {} 66 void AssertValid() {}
67 #endif 67 #endif
68 68
69 typename ArrayType<T>::Allocator::Ptr array_; 69 typename ArrayType<T>::Allocator::Ptr array_;
70 size_t count_; 70 size_t count_;
71 size_t capacity_; 71 size_t capacity_;
72 }; 72 };
73 73
74 } // namespace WTF 74 } // namespace WTF
75 75
76 using WTF::TerminatedArrayBuilder; 76 using WTF::TerminatedArrayBuilder;
77 77
78 #endif // TerminatedArrayBuilder_h 78 #endif // TerminatedArrayBuilder_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/wtf/StackUtil.cpp ('k') | third_party/WebKit/Source/platform/wtf/Vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698