From 7f16177f9631c428057fc5e2c9306608a08d8db7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 27 Aug 2022 11:51:35 +0200 Subject: [PATCH] src: use `if constexpr` where appropriate Doesn't change much but communicates to readers that these are compile-time conditionals. PR-URL: https://github.com/nodejs/node/pull/44291 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Feng Yu Reviewed-By: Rich Trott --- src/base_object-inl.h | 10 +++++----- src/json_utils.h | 2 +- src/node_http_parser.cc | 2 +- src/node_zlib.cc | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index ff618f08b5d394..a246c2502b48e1 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -115,7 +115,7 @@ bool BaseObject::has_pointer_data() const { template BaseObject::PointerData* BaseObjectPtrImpl::pointer_data() const { - if (kIsWeak) { + if constexpr (kIsWeak) { return data_.pointer_data; } if (get_base_object() == nullptr) { @@ -126,7 +126,7 @@ BaseObjectPtrImpl::pointer_data() const { template BaseObject* BaseObjectPtrImpl::get_base_object() const { - if (kIsWeak) { + if constexpr (kIsWeak) { if (pointer_data() == nullptr) { return nullptr; } @@ -137,7 +137,7 @@ BaseObject* BaseObjectPtrImpl::get_base_object() const { template BaseObjectPtrImpl::~BaseObjectPtrImpl() { - if (kIsWeak) { + if constexpr (kIsWeak) { if (pointer_data() != nullptr && --pointer_data()->weak_ptr_count == 0 && pointer_data()->self == nullptr) { @@ -157,7 +157,7 @@ template BaseObjectPtrImpl::BaseObjectPtrImpl(T* target) : BaseObjectPtrImpl() { if (target == nullptr) return; - if (kIsWeak) { + if constexpr (kIsWeak) { data_.pointer_data = target->pointer_data(); CHECK_NOT_NULL(pointer_data()); pointer_data()->weak_ptr_count++; @@ -198,7 +198,7 @@ BaseObjectPtrImpl& BaseObjectPtrImpl::operator=( template BaseObjectPtrImpl::BaseObjectPtrImpl(BaseObjectPtrImpl&& other) : data_(other.data_) { - if (kIsWeak) + if constexpr (kIsWeak) other.data_.target = nullptr; else other.data_.pointer_data = nullptr; diff --git a/src/json_utils.h b/src/json_utils.h index 3ece077a91705d..06033aa0a9b16d 100644 --- a/src/json_utils.h +++ b/src/json_utils.h @@ -128,7 +128,7 @@ class JSONWriter { typename test_for_number = typename std:: enable_if::is_specialized, bool>::type> inline void write_value(T number) { - if (std::is_same::value) + if constexpr (std::is_same::value) out_ << (number ? "true" : "false"); else out_ << number; diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 914d0294214853..6dbc8b806dc40f 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -674,7 +674,7 @@ class Parser : public AsyncWrap, public StreamListener { // Should always be called from the same context. CHECK_EQ(env, parser->env()); - if (should_pause) { + if constexpr (should_pause) { llhttp_pause(&parser->parser_); } else { llhttp_resume(&parser->parser_); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index c217861e82ae1d..367979f01203a2 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -361,7 +361,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { ctx_.SetBuffers(in, in_len, out, out_len); ctx_.SetFlush(flush); - if (!async) { + if constexpr (!async) { // sync version AsyncWrap::env()->PrintSyncTrace(); DoThreadPoolWork();