perf: avoid duplicate calculations in gin_helper::Dictionary getters (#43073)

* perf: cache the dictionary handle

* refactor: prefer result.IsJust() over !result.IsNothing()

for consistency

* refactor: prefer maybe.FromMaybe() over maybe.IsJust() && maybe.FromJust()

the inlined code is simpler

* refactor: simplify Get() impl

* refactor: add private helper Dictionary::MakeKey()

refactor: add private helper Dictionary::MakeHiddenKey()
This commit is contained in:
Charles Kerr 2024-07-29 12:43:28 -05:00 committed by GitHub
parent e70ce89235
commit 7e9eb9e3f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 41 deletions

View file

@ -32,14 +32,13 @@ class PersistentDictionary {
template <typename K, typename V>
bool Get(const K& key, V* out) const {
const auto handle = GetHandle();
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::Value> v8_key = gin::ConvertToV8(isolate_, key);
v8::Local<v8::Value> value;
v8::Maybe<bool> result = GetHandle()->Has(context, v8_key);
if (result.IsJust() && result.FromJust() &&
GetHandle()->Get(context, v8_key).ToLocal(&value))
return gin::ConvertFromV8(isolate_, value, out);
return false;
return handle->Has(context, v8_key).FromMaybe(false) &&
handle->Get(context, v8_key).ToLocal(&value) &&
gin::ConvertFromV8(isolate_, value, out);
}
private: