Skip to content

Commit e2a01ca

Browse files
cjihrigtargos
authored andcommitted
src: use DCHECK_* macros where possible
PR-URL: #25207 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 39b3fd1 commit e2a01ca

5 files changed

+10
-22
lines changed

src/aliased_buffer.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,15 @@ class AliasedBuffer {
198198
* Set position index to given value.
199199
*/
200200
inline void SetValue(const size_t index, NativeT value) {
201-
#if defined(DEBUG) && DEBUG
202-
CHECK_LT(index, count_);
203-
#endif
201+
DCHECK_LT(index, count_);
204202
buffer_[index] = value;
205203
}
206204

207205
/**
208206
* Get value at position index
209207
*/
210208
inline const NativeT GetValue(const size_t index) const {
211-
#if defined(DEBUG) && DEBUG
212-
CHECK_LT(index, count_);
213-
#endif
209+
DCHECK_LT(index, count_);
214210
return buffer_[index];
215211
}
216212

@@ -233,9 +229,9 @@ class AliasedBuffer {
233229
// Should only be used on an owning array, not one created as a sub array of
234230
// an owning `AliasedBuffer`.
235231
void reserve(size_t new_capacity) {
232+
DCHECK_GE(new_capacity, count_);
233+
DCHECK_EQ(byte_offset_, 0);
236234
#if defined(DEBUG) && DEBUG
237-
CHECK_GE(new_capacity, count_);
238-
CHECK_EQ(byte_offset_, 0);
239235
CHECK(free_buffer_);
240236
#endif
241237
const v8::HandleScope handle_scope(isolate_);

src/base_object-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
115115
auto constructor = [](const v8::FunctionCallbackInfo<v8::Value>& args) {
116116
#ifdef DEBUG
117117
CHECK(args.IsConstructCall());
118-
CHECK_GT(args.This()->InternalFieldCount(), 0);
119118
#endif
119+
DCHECK_GT(args.This()->InternalFieldCount(), 0);
120120
args.This()->SetAlignedPointerInInternalField(0, nullptr);
121121
};
122122

src/debug_utils.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ template <typename... Args>
6868
inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
6969
const char* format,
7070
Args&&... args) {
71-
#ifdef DEBUG
72-
CHECK_NOT_NULL(async_wrap);
73-
#endif
71+
DCHECK_NOT_NULL(async_wrap);
7472
DebugCategory cat =
7573
static_cast<DebugCategory>(async_wrap->provider_type());
7674
if (!UNLIKELY(async_wrap->env()->debug_enabled(cat)))

src/string_decoder.cc

+3-7
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ MaybeLocal<String> StringDecoder::DecodeData(Isolate* isolate,
123123
body = !prepend.IsEmpty() ? prepend : String::Empty(isolate);
124124
prepend = Local<String>();
125125
} else {
126-
#ifdef DEBUG
127126
// If not, that means is no character left to finish at this point.
128-
CHECK_EQ(MissingBytes(), 0);
129-
CHECK_EQ(BufferedBytes(), 0);
130-
#endif
127+
DCHECK_EQ(MissingBytes(), 0);
128+
DCHECK_EQ(BufferedBytes(), 0);
131129

132130
// See whether there is a character that we may have to cut off and
133131
// finish when receiving the next chunk.
@@ -136,9 +134,7 @@ MaybeLocal<String> StringDecoder::DecodeData(Isolate* isolate,
136134
// This means we'll need to figure out where the character to which
137135
// the byte belongs begins.
138136
for (size_t i = nread - 1; ; --i) {
139-
#ifdef DEBUG
140-
CHECK_LT(i, nread);
141-
#endif
137+
DCHECK_LT(i, nread);
142138
state_[kBufferedBytes]++;
143139
if ((data[i] & 0xC0) == 0x80) {
144140
// This byte does not start a character (a "trailing" byte).

src/string_search.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class Vector {
3737

3838
// Access individual vector elements - checks bounds in debug mode.
3939
T& operator[](size_t index) const {
40-
#ifdef DEBUG
41-
CHECK(index < length_);
42-
#endif
40+
DCHECK_LT(index, length_);
4341
return start_[is_forward_ ? index : (length_ - index - 1)];
4442
}
4543

0 commit comments

Comments
 (0)