From c787367758dd1b11c2db2d8e341bdbe8c722db5e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Dec 2020 05:25:43 -0600 Subject: [PATCH] use constexpr instead of static const constexpr variable is guaranteed to have a value available at compile time. whereas static const members or const variable could either mean a compile time value or a runtime value. --- src/bindings/patch-wrapper.cc | 2 +- src/bindings/text-buffer-wrapper.cc | 2 +- src/core/encoding-conversion.cc | 8 ++++---- src/core/patch.cc | 2 +- src/core/text-buffer.cc | 10 +++++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bindings/patch-wrapper.cc b/src/bindings/patch-wrapper.cc index fc610aaf..1cbf7fe2 100644 --- a/src/bindings/patch-wrapper.cc +++ b/src/bindings/patch-wrapper.cc @@ -17,7 +17,7 @@ static Nan::Persistent change_wrapper_constructor; static Nan::Persistent patch_wrapper_constructor_template; static Nan::Persistent patch_wrapper_constructor; -static const char *InvalidSpliceMessage = "Patch does not apply"; +constexpr char *InvalidSpliceMessage = "Patch does not apply"; class ChangeWrapper : public Nan::ObjectWrap { public: diff --git a/src/bindings/text-buffer-wrapper.cc b/src/bindings/text-buffer-wrapper.cc index 52e7bded..f84cf879 100644 --- a/src/bindings/text-buffer-wrapper.cc +++ b/src/bindings/text-buffer-wrapper.cc @@ -665,7 +665,7 @@ void TextBufferWrapper::is_modified(const Nan::FunctionCallbackInfo &info info.GetReturnValue().Set(Nan::New(text_buffer.is_modified())); } -static const int INVALID_ENCODING = -1; +constexpr int INVALID_ENCODING = -1; struct Error { int number; diff --git a/src/core/encoding-conversion.cc b/src/core/encoding-conversion.cc index 7259d40d..c1e64062 100644 --- a/src/core/encoding-conversion.cc +++ b/src/core/encoding-conversion.cc @@ -7,10 +7,10 @@ using std::function; using std::u16string; using std::vector; -static const uint32_t bytes_per_character = (sizeof(uint16_t) / sizeof(char)); -static const uint16_t replacement_character = 0xFFFD; -static const size_t conversion_failure = static_cast(-1); -static const float buffer_growth_factor = 2; +constexpr uint32_t bytes_per_character = (sizeof(uint16_t) / sizeof(char)); +constexpr uint16_t replacement_character = 0xFFFD; +constexpr size_t conversion_failure = static_cast(-1); +constexpr float buffer_growth_factor = 2; enum Mode { GENERAL, diff --git a/src/core/patch.cc b/src/core/patch.cc index 8702f9b3..ace85400 100644 --- a/src/core/patch.cc +++ b/src/core/patch.cc @@ -17,7 +17,7 @@ using std::ostream; using std::endl; using Change = Patch::Change; -static const uint32_t SERIALIZATION_VERSION = 1; +constexpr uint32_t SERIALIZATION_VERSION = 1; struct Patch::Node { Node *left; diff --git a/src/core/text-buffer.cc b/src/core/text-buffer.cc index c4dd3e8c..c36d4f1f 100644 --- a/src/core/text-buffer.cc +++ b/src/core/text-buffer.cc @@ -523,11 +523,11 @@ struct TextBuffer::Layer { // Next, calculate a score for each word indicating the quality of the // match against the query. - static const unsigned consecutive_bonus = 5; - static const unsigned subword_start_with_case_match_bonus = 10; - static const unsigned subword_start_with_case_mismatch_bonus = 9; - static const unsigned mismatch_penalty = 1; - static const unsigned leading_mismatch_penalty = 3; + constexpr unsigned consecutive_bonus = 5; + constexpr unsigned subword_start_with_case_match_bonus = 10; + constexpr unsigned subword_start_with_case_mismatch_bonus = 9; + constexpr unsigned mismatch_penalty = 1; + constexpr unsigned leading_mismatch_penalty = 3; vector matches;