diff --git a/NativeScript/ffi/jni/jsi/conversion/ArgConverter.cpp b/NativeScript/ffi/jni/jsi/conversion/ArgConverter.cpp index 13cc59a18..9f1d895a2 100644 --- a/NativeScript/ffi/jni/jsi/conversion/ArgConverter.cpp +++ b/NativeScript/ffi/jni/jsi/conversion/ArgConverter.cpp @@ -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; } @@ -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 ArgConverter::s_type_long_operations_cache; +tns::ConcurrentMap ArgConverter::s_type_long_operations_cache; diff --git a/NativeScript/ffi/jni/jsi/conversion/ArgConverter.h b/NativeScript/ffi/jni/jsi/conversion/ArgConverter.h index 957e04eb3..2c1ddb390 100644 --- a/NativeScript/ffi/jni/jsi/conversion/ArgConverter.h +++ b/NativeScript/ffi/jni/jsi/conversion/ArgConverter.h @@ -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 s_type_long_operations_cache; + static tns::ConcurrentMap s_type_long_operations_cache; }; } diff --git a/NativeScript/ffi/jni/napi/conversion/ArgConverter.cpp b/NativeScript/ffi/jni/napi/conversion/ArgConverter.cpp index 176b7b910..7f3cccf6e 100644 --- a/NativeScript/ffi/jni/napi/conversion/ArgConverter.cpp +++ b/NativeScript/ffi/jni/napi/conversion/ArgConverter.cpp @@ -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; } @@ -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 ArgConverter::s_type_long_operations_cache; +tns::ConcurrentMap ArgConverter::s_type_long_operations_cache; diff --git a/NativeScript/ffi/jni/napi/conversion/ArgConverter.h b/NativeScript/ffi/jni/napi/conversion/ArgConverter.h index a42a14cf2..ea6eb9e81 100644 --- a/NativeScript/ffi/jni/napi/conversion/ArgConverter.h +++ b/NativeScript/ffi/jni/napi/conversion/ArgConverter.h @@ -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 s_type_long_operations_cache; + static tns::ConcurrentMap s_type_long_operations_cache; }; }