Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2022-08-27 12:51:35 +0300
committerGitHub <noreply@github.com>2022-08-27 12:51:35 +0300
commitee75ad7a38ae6980881e704172539470cefb916b (patch)
treef399cf5f8f05004c59da1b10526b86f896daedbc /src
parent14000517b49371cfd3bc012898d730179e6c6d97 (diff)
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 <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>
Diffstat (limited to 'src')
-rw-r--r--src/base_object-inl.h10
-rw-r--r--src/json_utils.h2
-rw-r--r--src/node_http_parser.cc2
-rw-r--r--src/node_zlib.cc2
4 files changed, 8 insertions, 8 deletions
diff --git a/src/base_object-inl.h b/src/base_object-inl.h
index ff618f08b5d..a246c2502b4 100644
--- a/src/base_object-inl.h
+++ b/src/base_object-inl.h
@@ -115,7 +115,7 @@ bool BaseObject::has_pointer_data() const {
template <typename T, bool kIsWeak>
BaseObject::PointerData*
BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
- if (kIsWeak) {
+ if constexpr (kIsWeak) {
return data_.pointer_data;
}
if (get_base_object() == nullptr) {
@@ -126,7 +126,7 @@ BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
template <typename T, bool kIsWeak>
BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
- if (kIsWeak) {
+ if constexpr (kIsWeak) {
if (pointer_data() == nullptr) {
return nullptr;
}
@@ -137,7 +137,7 @@ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
template <typename T, bool kIsWeak>
BaseObjectPtrImpl<T, kIsWeak>::~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 <typename T, bool kIsWeak>
BaseObjectPtrImpl<T, kIsWeak>::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<T, kIsWeak>& BaseObjectPtrImpl<T, kIsWeak>::operator=(
template <typename T, bool kIsWeak>
BaseObjectPtrImpl<T, kIsWeak>::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 3ece077a917..06033aa0a9b 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<std::numeric_limits<T>::is_specialized, bool>::type>
inline void write_value(T number) {
- if (std::is_same<T, bool>::value)
+ if constexpr (std::is_same<T, bool>::value)
out_ << (number ? "true" : "false");
else
out_ << number;
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index 914d0294214..6dbc8b806dc 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 c217861e82a..367979f0120 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();