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

Commit ac5c3e7

Browse files
committed
jonahs feedback - faster smaller messages
1 parent dece935 commit ac5c3e7

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

lib/ui/window/platform_message_response_dart.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,28 @@ PlatformMessageResponseDart::~PlatformMessageResponseDart() {
6969
}
7070

7171
void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
72-
PostCompletion(std::move(callback_), ui_task_runner_, &is_complete_, channel_,
73-
[data = std::move(data)]() mutable {
74-
void* mapping = data->GetMutableMapping();
75-
Dart_Handle byte_buffer;
76-
if (mapping) {
77-
size_t data_size = data->GetSize();
78-
byte_buffer = Dart_NewExternalTypedDataWithFinalizer(
79-
/*type=*/Dart_TypedData_kByteData,
80-
/*data=*/mapping,
81-
/*length=*/data_size,
82-
/*peer=*/data.release(),
83-
/*external_allocation_size=*/data_size,
84-
/*callback=*/MappingFinalizer);
72+
PostCompletion(
73+
std::move(callback_), ui_task_runner_, &is_complete_, channel_,
74+
[data = std::move(data)]() mutable {
75+
void* mapping = data->GetMutableMapping();
76+
Dart_Handle byte_buffer;
77+
size_t data_size = data->GetSize();
78+
if (mapping &&
79+
data_size >= tonic::DartByteData::kExternalSizeThreshold) {
80+
byte_buffer = Dart_NewExternalTypedDataWithFinalizer(
81+
/*type=*/Dart_TypedData_kByteData,
82+
/*data=*/mapping,
83+
/*length=*/data_size,
84+
/*peer=*/data.release(),
85+
/*external_allocation_size=*/data_size,
86+
/*callback=*/MappingFinalizer);
8587

86-
} else {
87-
byte_buffer = tonic::DartByteData::Create(
88-
data->GetMapping(), data->GetSize());
89-
}
90-
return byte_buffer;
91-
});
88+
} else {
89+
byte_buffer =
90+
tonic::DartByteData::Create(data->GetMapping(), data->GetSize());
91+
}
92+
return byte_buffer;
93+
});
9294
}
9395

9496
void PlatformMessageResponseDart::CompleteEmpty() {

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)