diff --git a/engine/src/flutter/lib/ui/dart_ui.cc b/engine/src/flutter/lib/ui/dart_ui.cc index 818e99a6187..0cf6cf509ac 100644 --- a/engine/src/flutter/lib/ui/dart_ui.cc +++ b/engine/src/flutter/lib/ui/dart_ui.cc @@ -4,6 +4,8 @@ #include "flutter/lib/ui/dart_ui.h" +#include + #include "flutter/common/settings.h" #include "flutter/fml/build_config.h" #include "flutter/lib/ui/compositing/scene.h" @@ -279,26 +281,41 @@ typedef CanvasPath Path; V(SemanticsUpdateBuilder, updateNode, 36) \ V(SemanticsUpdate, dispose, 1) -#define FFI_FUNCTION_MATCH(FUNCTION, ARGS) \ - if (strcmp(name, #FUNCTION) == 0 && args == ARGS) { \ - return reinterpret_cast( \ - tonic::FfiDispatcher::Call); \ - } +#define FFI_FUNCTION_INSERT(FUNCTION, ARGS) \ + function_dispatchers.insert(std::make_pair( \ + std::string_view(#FUNCTION), \ + reinterpret_cast( \ + tonic::FfiDispatcher::Call))); -#define FFI_METHOD_MATCH(CLASS, METHOD, ARGS) \ - if (strcmp(name, #CLASS "::" #METHOD) == 0 && args == ARGS) { \ - return reinterpret_cast( \ - tonic::FfiDispatcher::Call); \ - } +#define FFI_METHOD_INSERT(CLASS, METHOD, ARGS) \ + function_dispatchers.insert( \ + std::make_pair(std::string_view(#CLASS "::" #METHOD), \ + reinterpret_cast( \ + tonic::FfiDispatcher::Call))); + +namespace { + +std::unordered_map function_dispatchers; void* ResolveFfiNativeFunction(const char* name, uintptr_t args) { - FFI_FUNCTION_LIST(FFI_FUNCTION_MATCH) - FFI_METHOD_LIST(FFI_METHOD_MATCH) - return nullptr; + auto it = function_dispatchers.find(name); + return (it != function_dispatchers.end()) ? it->second : nullptr; } +void InitDispatcherMap() { + if (!function_dispatchers.empty()) { + return; + } + FFI_FUNCTION_LIST(FFI_FUNCTION_INSERT) + FFI_METHOD_LIST(FFI_METHOD_INSERT) +} + +} // anonymous namespace + void DartUI::InitForIsolate(const Settings& settings) { + InitDispatcherMap(); + auto dart_ui = Dart_LookupLibrary(ToDart("dart:ui")); if (Dart_IsError(dart_ui)) { Dart_PropagateError(dart_ui);