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

Commit

Permalink
jonahs feedback - faster smaller messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Jun 17, 2022
1 parent a01f692 commit 20ba04a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/ui/window/platform_message_response_dart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> 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,
Expand Down
10 changes: 4 additions & 6 deletions third_party/tonic/typed_data/dart_byte_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions third_party/tonic/typed_data/dart_byte_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 20ba04a

Please sign in to comment.