Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 343c07b

Browse files
committed
jonahs feedback - faster smaller messages
1 parent f466af4 commit 343c07b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/ui/window/platform_message_response_dart.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
4949
tonic::DartState::Scope scope(dart_state);
5050

5151
void* mapping = data->GetMutableMapping();
52+
size_t data_size = data->GetSize();
5253
Dart_Handle byte_buffer;
53-
if (mapping) {
54-
size_t data_size = data->GetSize();
54+
if (mapping &&
55+
data_size >= tonic::DartByteData::kExternalSizeThreshold) {
5556
byte_buffer = Dart_NewExternalTypedDataWithFinalizer(
5657
/*type=*/Dart_TypedData_kByteData,
5758
/*data=*/mapping,

third_party/tonic/typed_data/dart_byte_data.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
namespace tonic {
1212

1313
namespace {
14-
15-
// For large objects it is more efficient to use an external typed data object
16-
// with a buffer allocated outside the Dart heap.
17-
const int kExternalSizeThreshold = 1000;
18-
1914
void FreeFinalizer(void* isolate_callback_data, void* peer) {
2015
free(peer);
2116
}
22-
2317
} // anonymous namespace
2418

19+
// For large objects it is more efficient to use an external typed data object
20+
// with a buffer allocated outside the Dart heap.
21+
const size_t DartByteData::kExternalSizeThreshold = 1000;
22+
2523
Dart_Handle DartByteData::Create(const void* data, size_t length) {
2624
if (length < kExternalSizeThreshold) {
2725
auto handle = DartByteData{data, length}.dart_handle();

third_party/tonic/typed_data/dart_byte_data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace tonic {
1414

1515
class DartByteData {
1616
public:
17+
static const size_t kExternalSizeThreshold;
1718
static Dart_Handle Create(const void* data, size_t length);
1819

1920
explicit DartByteData(Dart_Handle list);

0 commit comments

Comments
 (0)