Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from atom/snake-case-functions
Browse files Browse the repository at this point in the history
Convert method names to snake_case
  • Loading branch information
Nathan Sobo authored Jan 15, 2017
2 parents 88c7876 + cd04812 commit b9b7a06
Show file tree
Hide file tree
Showing 25 changed files with 966 additions and 980 deletions.
10 changes: 5 additions & 5 deletions benchmark/native/marker-index-benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
using namespace std::chrono;
using std::vector;

Range GetRandomRange() {
Range get_random_range() {
Point start(rand() % 100, rand() % 100);
Point end = start;
if (rand() % 10 < 5) {
end = end.Traverse(Point(rand() % 10, rand() % 10));
end = end.traverse(Point(rand() % 10, rand() % 10));
}
return Range{start, end};
}


TEST_CASE("MarkerIndex::Insert") {
TEST_CASE("MarkerIndex::insert") {
srand(0);
MarkerIndex marker_index;
vector<Range> ranges;
uint count = 20000;

for (uint i = 0; i < count; i++) {
ranges.push_back(GetRandomRange());
ranges.push_back(get_random_range());
}

milliseconds start = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
for (uint i = 0; i < count; i++) {
marker_index.Insert(i, ranges[i].start, ranges[i].end);
marker_index.insert(i, ranges[i].start, ranges[i].end);
}
milliseconds end = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
std::cout << "Inserting " << (end - start).count();
Expand Down
8 changes: 4 additions & 4 deletions src/bindings/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using namespace v8;

void Init(Local<Object> exports) {
PointWrapper::Init();
PatchWrapper::Init(exports);
MarkerIndexWrapper::Init(exports);
BufferOffsetIndexWrapper::Init(exports);
PointWrapper::init();
PatchWrapper::init(exports);
MarkerIndexWrapper::init(exports);
BufferOffsetIndexWrapper::init(exports);
}

NODE_MODULE(superstring, Init)
28 changes: 14 additions & 14 deletions src/bindings/buffer-offset-index-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

using namespace v8;

void BufferOffsetIndexWrapper::Init(Local<Object> exports) {
Local<FunctionTemplate> constructor_template = Nan::New<FunctionTemplate>(New);
void BufferOffsetIndexWrapper::init(Local<Object> exports) {
Local<FunctionTemplate> constructor_template = Nan::New<FunctionTemplate>(construct);
constructor_template->SetClassName(Nan::New<String>("BufferOffsetIndex").ToLocalChecked());
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
const auto &prototype_template = constructor_template->PrototypeTemplate();
prototype_template->Set(Nan::New<String>("splice").ToLocalChecked(), Nan::New<FunctionTemplate>(Splice));
prototype_template->Set(Nan::New<String>("positionForCharacterIndex").ToLocalChecked(), Nan::New<FunctionTemplate>(PositionForCharacterIndex));
prototype_template->Set(Nan::New<String>("characterIndexForPosition").ToLocalChecked(), Nan::New<FunctionTemplate>(CharacterIndexForPosition));
prototype_template->Set(Nan::New<String>("splice").ToLocalChecked(), Nan::New<FunctionTemplate>(splice));
prototype_template->Set(Nan::New<String>("position_for_character_index").ToLocalChecked(), Nan::New<FunctionTemplate>(position_for_character_index));
prototype_template->Set(Nan::New<String>("character_index_for_position").ToLocalChecked(), Nan::New<FunctionTemplate>(character_index_for_position));
exports->Set(Nan::New("BufferOffsetIndex").ToLocalChecked(), constructor_template->GetFunction());
}

void BufferOffsetIndexWrapper::New(const Nan::FunctionCallbackInfo<Value> &info) {
void BufferOffsetIndexWrapper::construct(const Nan::FunctionCallbackInfo<Value> &info) {
BufferOffsetIndexWrapper *buffer_offset_index = new BufferOffsetIndexWrapper();
buffer_offset_index->Wrap(info.This());
}

void BufferOffsetIndexWrapper::Splice(const Nan::FunctionCallbackInfo<Value> &info) {
void BufferOffsetIndexWrapper::splice(const Nan::FunctionCallbackInfo<Value> &info) {
BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap<BufferOffsetIndexWrapper>(info.This())->buffer_offset_index;

auto start_row = info[0].As<Uint32>()->Value();
Expand All @@ -29,25 +29,25 @@ void BufferOffsetIndexWrapper::Splice(const Nan::FunctionCallbackInfo<Value> &in
for (size_t i = 0; i < new_line_lengths.size(); i++) {
new_line_lengths[i] = js_new_line_lengths->Get(i).As<Uint32>()->Value();
}
buffer_offset_index.Splice(start_row, deleted_lines_count, new_line_lengths);
buffer_offset_index.splice(start_row, deleted_lines_count, new_line_lengths);
}

void BufferOffsetIndexWrapper::CharacterIndexForPosition(const Nan::FunctionCallbackInfo<Value> &info) {
void BufferOffsetIndexWrapper::character_index_for_position(const Nan::FunctionCallbackInfo<Value> &info) {
BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap<BufferOffsetIndexWrapper>(info.This())->buffer_offset_index;

auto position = PointWrapper::PointFromJS(info[0]);
auto position = PointWrapper::point_from_js(info[0]);
if (position) {
auto result = buffer_offset_index.CharacterIndexForPosition(*position);
auto result = buffer_offset_index.character_index_for_position(*position);
info.GetReturnValue().Set(Nan::New(result));
}
}

void BufferOffsetIndexWrapper::PositionForCharacterIndex(const Nan::FunctionCallbackInfo<Value> &info) {
void BufferOffsetIndexWrapper::position_for_character_index(const Nan::FunctionCallbackInfo<Value> &info) {
BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap<BufferOffsetIndexWrapper>(info.This())->buffer_offset_index;

auto character_index = Nan::To<unsigned>(info[0]);
if (character_index.IsJust()) {
auto result = buffer_offset_index.PositionForCharacterIndex(character_index.FromJust());
info.GetReturnValue().Set(PointWrapper::FromPoint(result));
auto result = buffer_offset_index.position_for_character_index(character_index.FromJust());
info.GetReturnValue().Set(PointWrapper::from_point(result));
}
}
10 changes: 5 additions & 5 deletions src/bindings/buffer-offset-index-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class BufferOffsetIndexWrapper : public Nan::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
static void init(v8::Local<v8::Object> exports);

private:
static void New(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void Splice(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void CharacterIndexForPosition(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void PositionForCharacterIndex(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void construct(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void splice(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void character_index_for_position(const Nan::FunctionCallbackInfo<v8::Value> &info);
static void position_for_character_index(const Nan::FunctionCallbackInfo<v8::Value> &info);

BufferOffsetIndex buffer_offset_index;
};
Loading

0 comments on commit b9b7a06

Please sign in to comment.