Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions NativeScript/ffi/jni/jsi/conversion/ArgConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,11 @@ int64_t ArgConverter::ConvertToJavaLong(JsRuntime &rt, const JsValue &value) {
}

ArgConverter::TypeLongOperationsCache *ArgConverter::GetTypeLongCache(JsRuntime &rt) {
TypeLongOperationsCache *cache;
auto itFound = s_type_long_operations_cache.find(rt.identity());
if (itFound == s_type_long_operations_cache.end()) {
cache = new TypeLongOperationsCache;
s_type_long_operations_cache.emplace(rt.identity(), cache);
} else {
cache = itFound->second;
}

const void *key = rt.identity();
auto cache = s_type_long_operations_cache.Get(key);
if (cache) return cache;
cache = new TypeLongOperationsCache;
s_type_long_operations_cache.Insert(key, cache);
return cache;
}

Expand Down Expand Up @@ -299,11 +295,10 @@ u16string ArgConverter::ConvertToUtf16String(JsRuntime &rt, const JsValue &s) {
}

void ArgConverter::onDisposeRuntime(JsRuntime &rt) {
auto itFound = s_type_long_operations_cache.find(rt.identity());
if (itFound != s_type_long_operations_cache.end()) {
delete itFound->second;
s_type_long_operations_cache.erase(itFound);
}
const void *key = rt.identity();
auto cache = s_type_long_operations_cache.Get(key);
s_type_long_operations_cache.Remove(key);
delete cache;
}

robin_hood::unordered_map<const void *, ArgConverter::TypeLongOperationsCache *> ArgConverter::s_type_long_operations_cache;
tns::ConcurrentMap<const void *, ArgConverter::TypeLongOperationsCache *> ArgConverter::s_type_long_operations_cache;
2 changes: 1 addition & 1 deletion NativeScript/ffi/jni/jsi/conversion/ArgConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace tns {
* dealing with operations concerning java long -> javascript number.
*/
// Keyed by JsRuntime::identity(); &rt is not stable across callbacks.
static robin_hood::unordered_map<const void *, TypeLongOperationsCache *> s_type_long_operations_cache;
static tns::ConcurrentMap<const void *, TypeLongOperationsCache *> s_type_long_operations_cache;
};
}

Expand Down
31 changes: 13 additions & 18 deletions NativeScript/ffi/jni/napi/conversion/ArgConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,10 @@ int64_t ArgConverter::ConvertToJavaLong(napi_env env, napi_value value) {
}

ArgConverter::TypeLongOperationsCache *ArgConverter::GetTypeLongCache(napi_env env) {
TypeLongOperationsCache *cache;
auto itFound = s_type_long_operations_cache.find(env);
if (itFound == s_type_long_operations_cache.end()) {
cache = new TypeLongOperationsCache;
s_type_long_operations_cache.emplace(env, cache);
} else {
cache = itFound->second;
}

auto cache = s_type_long_operations_cache.Get(env);
if (cache) return cache;
cache = new TypeLongOperationsCache;
s_type_long_operations_cache.Insert(env, cache);
return cache;
}

Expand All @@ -331,17 +326,17 @@ u16string ArgConverter::ConvertToUtf16String(napi_env env, napi_value s) {

void ArgConverter::onDisposeEnv(napi_env env) {
napi_status status;
auto itFound = s_type_long_operations_cache.find(env);
if (itFound != s_type_long_operations_cache.end()) {
if (itFound->second->LongNumberCtorFunc) {
NAPI_GUARD(napi_delete_reference(env, itFound->second->LongNumberCtorFunc)) {}
auto cache = s_type_long_operations_cache.Get(env);
if (cache) {
if (cache->LongNumberCtorFunc) {
NAPI_GUARD(napi_delete_reference(env, cache->LongNumberCtorFunc)) {}
}
if (itFound->second->NanNumberObject) {
NAPI_GUARD(napi_delete_reference(env, itFound->second->NanNumberObject)) {}
if (cache->NanNumberObject) {
NAPI_GUARD(napi_delete_reference(env, cache->NanNumberObject)) {}
}
delete itFound->second;
s_type_long_operations_cache.erase(itFound);
s_type_long_operations_cache.Remove(env);
delete cache;
}
}

robin_hood::unordered_map<napi_env, ArgConverter::TypeLongOperationsCache *> ArgConverter::s_type_long_operations_cache;
tns::ConcurrentMap<napi_env, ArgConverter::TypeLongOperationsCache *> ArgConverter::s_type_long_operations_cache;
2 changes: 1 addition & 1 deletion NativeScript/ffi/jni/napi/conversion/ArgConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace tns {
* "s_type_long_operations_cache" used to keep function
* dealing with operations concerning java long -> javascript number.
*/
static robin_hood::unordered_map<napi_env, TypeLongOperationsCache *> s_type_long_operations_cache;
static tns::ConcurrentMap<napi_env, TypeLongOperationsCache *> s_type_long_operations_cache;
};
}

Expand Down
Loading