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

Commit

Permalink
dispose of unused slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Apr 8, 2016
1 parent 160e0b2 commit ab2d68d
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Iterator::Iterator (

v8::Local<v8::Object> obj = Nan::New<v8::Object>();
if (!startHandle.IsEmpty())
obj->Set(Nan::New("start").ToLocalChecked(), startHandle);
obj->Set(Nan::New("obj").ToLocalChecked(), startHandle);
persistentHandle.Reset(obj);

options = new leveldb::ReadOptions();
Expand All @@ -70,10 +70,12 @@ Iterator::Iterator (

Iterator::~Iterator () {
delete options;
if (start != NULL) {
DisposeStringOrBufferFromSlice(persistentHandle, *start);
delete start;
}
if (!persistentHandle.IsEmpty())
persistentHandle.Reset();
if (start != NULL)
delete start;
if (end != NULL)
delete end;
if (lt != NULL)
Expand Down Expand Up @@ -394,6 +396,7 @@ NAN_METHOD(Iterator::New) {
if (StringOrBufferLength(endBuffer) > 0) {
LD_STRING_OR_BUFFER_TO_SLICE(_end, endBuffer, end)
end = new std::string(_end.data(), _end.size());
DisposeStringOrBufferFromSlice(endBuffer, _end);
}
}

Expand All @@ -417,8 +420,14 @@ NAN_METHOD(Iterator::New) {
if (StringOrBufferLength(ltBuffer) > 0) {
LD_STRING_OR_BUFFER_TO_SLICE(_lt, ltBuffer, lt)
lt = new std::string(_lt.data(), _lt.size());
if (reverse)
if (reverse) {
if (start != NULL)
DisposeStringOrBufferFromSlice(startHandle, *start);
start = new leveldb::Slice(_lt.data(), _lt.size());
startHandle = optionsObj->Get(Nan::New("lt").ToLocalChecked()).As<v8::Object>();
} else {
DisposeStringOrBufferFromSlice(ltBuffer, _lt);
}
}
}

Expand All @@ -432,8 +441,14 @@ NAN_METHOD(Iterator::New) {
if (StringOrBufferLength(lteBuffer) > 0) {
LD_STRING_OR_BUFFER_TO_SLICE(_lte, lteBuffer, lte)
lte = new std::string(_lte.data(), _lte.size());
if (reverse)
if (reverse) {
if (start != NULL)
DisposeStringOrBufferFromSlice(startHandle, *start);
start = new leveldb::Slice(_lte.data(), _lte.size());
startHandle = optionsObj->Get(Nan::New("lte").ToLocalChecked()).As<v8::Object>();
} else {
DisposeStringOrBufferFromSlice(lteBuffer, _lte);
}
}
}

Expand All @@ -447,8 +462,14 @@ NAN_METHOD(Iterator::New) {
if (StringOrBufferLength(gtBuffer) > 0) {
LD_STRING_OR_BUFFER_TO_SLICE(_gt, gtBuffer, gt)
gt = new std::string(_gt.data(), _gt.size());
if (!reverse)
if (!reverse) {
if (start != NULL)
DisposeStringOrBufferFromSlice(startHandle, *start);
start = new leveldb::Slice(_gt.data(), _gt.size());
startHandle = optionsObj->Get(Nan::New("gt").ToLocalChecked()).As<v8::Object>();
} else {
DisposeStringOrBufferFromSlice(gtBuffer, _gt);
}
}
}

Expand All @@ -462,8 +483,14 @@ NAN_METHOD(Iterator::New) {
if (StringOrBufferLength(gteBuffer) > 0) {
LD_STRING_OR_BUFFER_TO_SLICE(_gte, gteBuffer, gte)
gte = new std::string(_gte.data(), _gte.size());
if (!reverse)
if (!reverse) {
if (start != NULL)
DisposeStringOrBufferFromSlice(startHandle, *start);
start = new leveldb::Slice(_gte.data(), _gte.size());
startHandle = optionsObj->Get(Nan::New("gte").ToLocalChecked()).As<v8::Object>();
} else {
DisposeStringOrBufferFromSlice(gteBuffer, _gte);
}
}
}

Expand Down

0 comments on commit ab2d68d

Please sign in to comment.