Skip to content

Commit

Permalink
Use try_reserve() instead of reserve()
Browse files Browse the repository at this point in the history
  • Loading branch information
abetomo committed Oct 10, 2024
1 parent a572eaa commit 18939c7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions javascript/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void CompiledIndex::Load(Napi::CallbackInfo const& ctx) {
auto result = native_->load(path.c_str());
if (!result)
Napi::TypeError::New(ctx.Env(), result.error.release()).ThrowAsJavaScriptException();
native_->reserve(ceil2(native_->size()));
if (!native_->try_reserve(ceil2(native_->size())))
Napi::Error::New(ctx.Env(), "Failed to reserve memory").ThrowAsJavaScriptException();

} catch (...) {
Napi::TypeError::New(ctx.Env(), "Loading failed").ThrowAsJavaScriptException();
Expand All @@ -143,7 +144,8 @@ void CompiledIndex::View(Napi::CallbackInfo const& ctx) {
auto result = native_->view(path.c_str());
if (!result)
Napi::TypeError::New(ctx.Env(), result.error.release()).ThrowAsJavaScriptException();
native_->reserve(ceil2(native_->size()));
if (!native_->try_reserve(ceil2(native_->size())))
Napi::Error::New(ctx.Env(), "Failed to reserve memory").ThrowAsJavaScriptException();

} catch (...) {
Napi::TypeError::New(ctx.Env(), "Memory-mapping failed").ThrowAsJavaScriptException();
Expand Down

0 comments on commit 18939c7

Please sign in to comment.