Skip to content

use constexpr instead of static const #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bindings/patch-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static Nan::Persistent<v8::Function> change_wrapper_constructor;
static Nan::Persistent<v8::FunctionTemplate> patch_wrapper_constructor_template;
static Nan::Persistent<v8::Function> patch_wrapper_constructor;

static const char *InvalidSpliceMessage = "Patch does not apply";
constexpr char *InvalidSpliceMessage = "Patch does not apply";

class ChangeWrapper : public Nan::ObjectWrap {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/text-buffer-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ void TextBufferWrapper::is_modified(const Nan::FunctionCallbackInfo<Value> &info
info.GetReturnValue().Set(Nan::New<Boolean>(text_buffer.is_modified()));
}

static const int INVALID_ENCODING = -1;
constexpr int INVALID_ENCODING = -1;

struct Error {
int number;
Expand Down
8 changes: 4 additions & 4 deletions src/core/encoding-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-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<size_t>(-1);
constexpr float buffer_growth_factor = 2;

enum Mode {
GENERAL,
Expand Down
2 changes: 1 addition & 1 deletion src/core/patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/core/text-buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubsequenceMatch> matches;

Expand Down