Skip to content

Commit 7f16177

Browse files
addaleaxRafaelGSS
authored andcommitted
src: use if constexpr where appropriate
Doesn't change much but communicates to readers that these are compile-time conditionals. PR-URL: #44291 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent b670954 commit 7f16177

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/base_object-inl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool BaseObject::has_pointer_data() const {
115115
template <typename T, bool kIsWeak>
116116
BaseObject::PointerData*
117117
BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
118-
if (kIsWeak) {
118+
if constexpr (kIsWeak) {
119119
return data_.pointer_data;
120120
}
121121
if (get_base_object() == nullptr) {
@@ -126,7 +126,7 @@ BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
126126

127127
template <typename T, bool kIsWeak>
128128
BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
129-
if (kIsWeak) {
129+
if constexpr (kIsWeak) {
130130
if (pointer_data() == nullptr) {
131131
return nullptr;
132132
}
@@ -137,7 +137,7 @@ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
137137

138138
template <typename T, bool kIsWeak>
139139
BaseObjectPtrImpl<T, kIsWeak>::~BaseObjectPtrImpl() {
140-
if (kIsWeak) {
140+
if constexpr (kIsWeak) {
141141
if (pointer_data() != nullptr &&
142142
--pointer_data()->weak_ptr_count == 0 &&
143143
pointer_data()->self == nullptr) {
@@ -157,7 +157,7 @@ template <typename T, bool kIsWeak>
157157
BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(T* target)
158158
: BaseObjectPtrImpl() {
159159
if (target == nullptr) return;
160-
if (kIsWeak) {
160+
if constexpr (kIsWeak) {
161161
data_.pointer_data = target->pointer_data();
162162
CHECK_NOT_NULL(pointer_data());
163163
pointer_data()->weak_ptr_count++;
@@ -198,7 +198,7 @@ BaseObjectPtrImpl<T, kIsWeak>& BaseObjectPtrImpl<T, kIsWeak>::operator=(
198198
template <typename T, bool kIsWeak>
199199
BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(BaseObjectPtrImpl&& other)
200200
: data_(other.data_) {
201-
if (kIsWeak)
201+
if constexpr (kIsWeak)
202202
other.data_.target = nullptr;
203203
else
204204
other.data_.pointer_data = nullptr;

src/json_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class JSONWriter {
128128
typename test_for_number = typename std::
129129
enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
130130
inline void write_value(T number) {
131-
if (std::is_same<T, bool>::value)
131+
if constexpr (std::is_same<T, bool>::value)
132132
out_ << (number ? "true" : "false");
133133
else
134134
out_ << number;

src/node_http_parser.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ class Parser : public AsyncWrap, public StreamListener {
674674
// Should always be called from the same context.
675675
CHECK_EQ(env, parser->env());
676676

677-
if (should_pause) {
677+
if constexpr (should_pause) {
678678
llhttp_pause(&parser->parser_);
679679
} else {
680680
llhttp_resume(&parser->parser_);

src/node_zlib.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
361361
ctx_.SetBuffers(in, in_len, out, out_len);
362362
ctx_.SetFlush(flush);
363363

364-
if (!async) {
364+
if constexpr (!async) {
365365
// sync version
366366
AsyncWrap::env()->PrintSyncTrace();
367367
DoThreadPoolWork();

0 commit comments

Comments
 (0)