Skip to content

Commit 8565e29

Browse files
committed
fix: Only lookup once
1 parent 0098776 commit 8565e29

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cpp/base/WKTJsiHostObject.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ void JsiHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
4949
jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
5050
const jsi::PropNameID &name) {
5151
auto nameStr = name.utf8(runtime);
52+
auto& cache = _hostFunctionCache.get(runtime);
5253

5354
// Check function cache
54-
auto cachedFunc = _hostFunctionCache.get(runtime).find(nameStr);
55-
if (cachedFunc != _hostFunctionCache.get(runtime).end()) {
55+
auto cachedFunc = cache.find(nameStr);
56+
if (cachedFunc != cache.end()) {
5657
return cachedFunc->second.asFunction(runtime);
5758
}
5859

@@ -75,7 +76,7 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
7576

7677
// Add to cache - it is important to cache the results from the
7778
// createFromHostFunction function which takes some time.
78-
return _hostFunctionCache.get(runtime)
79+
return cache
7980
.emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name,
8081
0, dispatcher))
8182
.first->second.asFunction(runtime);

cpp/base/WKTRuntimeAwareCache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class RuntimeAwareCache : public BaseRuntimeAwareCache,
8080
// we only add listener when the secondary runtime is used, this assumes
8181
// that the secondary runtime is terminated first. This lets us avoid
8282
// additional complexity for the majority of cases when objects are not
83-
// shared between runtimes. Otherwise we'd have to register all objecrts
83+
// shared between runtimes. Otherwise we'd have to register all objects
8484
// with the RuntimeMonitor as opposed to only registering ones that are
8585
// used in secondary runtime. Note that we can't register listener here
8686
// with the primary runtime as it may run on a separate thread.

0 commit comments

Comments
 (0)