diff --git a/lib/ui/window/platform_message_response_dart.cc b/lib/ui/window/platform_message_response_dart.cc index 702abad8d72bc..aed8f256cfba0 100644 --- a/lib/ui/window/platform_message_response_dart.cc +++ b/lib/ui/window/platform_message_response_dart.cc @@ -49,9 +49,10 @@ void PlatformMessageResponseDart::Complete(std::unique_ptr data) { tonic::DartState::Scope scope(dart_state); void* mapping = data->GetMutableMapping(); + size_t data_size = data->GetSize(); Dart_Handle byte_buffer; - if (mapping) { - size_t data_size = data->GetSize(); + if (mapping && + data_size >= tonic::DartByteData::kExternalSizeThreshold) { byte_buffer = Dart_NewExternalTypedDataWithFinalizer( /*type=*/Dart_TypedData_kByteData, /*data=*/mapping, diff --git a/third_party/tonic/typed_data/dart_byte_data.cc b/third_party/tonic/typed_data/dart_byte_data.cc index cab038d14f85d..f4a557f17e946 100644 --- a/third_party/tonic/typed_data/dart_byte_data.cc +++ b/third_party/tonic/typed_data/dart_byte_data.cc @@ -11,17 +11,15 @@ namespace tonic { namespace { - -// For large objects it is more efficient to use an external typed data object -// with a buffer allocated outside the Dart heap. -const int kExternalSizeThreshold = 1000; - void FreeFinalizer(void* isolate_callback_data, void* peer) { free(peer); } - } // anonymous namespace +// For large objects it is more efficient to use an external typed data object +// with a buffer allocated outside the Dart heap. +const size_t DartByteData::kExternalSizeThreshold = 1000; + Dart_Handle DartByteData::Create(const void* data, size_t length) { if (length < kExternalSizeThreshold) { auto handle = DartByteData{data, length}.dart_handle(); diff --git a/third_party/tonic/typed_data/dart_byte_data.h b/third_party/tonic/typed_data/dart_byte_data.h index bad96446de6f8..025df77dd0869 100644 --- a/third_party/tonic/typed_data/dart_byte_data.h +++ b/third_party/tonic/typed_data/dart_byte_data.h @@ -14,6 +14,7 @@ namespace tonic { class DartByteData { public: + static const size_t kExternalSizeThreshold; static Dart_Handle Create(const void* data, size_t length); explicit DartByteData(Dart_Handle list);