This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ namespace flutter {
15
15
16
16
fml::MallocMapping CopyNSDataToMapping (NSData* data);
17
17
18
- NSData* CopyMappingToNSData (fml::MallocMapping buffer);
18
+ NSData* ConvertMappingToNSData (fml::MallocMapping buffer);
19
19
20
- std::unique_ptr<fml::Mapping> CopyNSDataToMappingPtr (NSData* data);
20
+ std::unique_ptr<fml::Mapping> ConvertNSDataToMappingPtr (NSData* data);
21
21
22
22
NSData* CopyMappingPtrToNSData (std::unique_ptr<fml::Mapping> mapping);
23
23
Original file line number Diff line number Diff line change 4
4
5
5
#import " flutter/shell/platform/darwin/common/buffer_conversions.h"
6
6
7
+ #include " flutter/fml/platform/darwin/scoped_nsobject.h"
8
+
7
9
namespace flutter {
10
+ namespace {
11
+ class NSDataMapping : public fml ::Mapping {
12
+ public:
13
+ NSDataMapping (NSData * data) : data_([data retain ]) {}
14
+
15
+ size_t GetSize () const override { return [data_.get () length ]; }
16
+
17
+ const uint8_t * GetMapping () const override {
18
+ return static_cast <const uint8_t *>([data_.get () bytes ]);
19
+ }
20
+
21
+ private:
22
+ fml::scoped_nsobject<NSData > data_;
23
+ FML_DISALLOW_COPY_AND_ASSIGN (NSDataMapping);
24
+ };
25
+ } // namespace
8
26
9
27
fml::MallocMapping CopyNSDataToMapping (NSData * data) {
10
28
const uint8_t * bytes = static_cast <const uint8_t *>(data.bytes );
11
29
return fml::MallocMapping::Copy (bytes, data.length );
12
30
}
13
31
14
- NSData * CopyMappingToNSData (fml::MallocMapping buffer) {
15
- return [NSData dataWithBytes: const_cast <uint8_t *>(buffer.GetMapping ()) length: buffer.GetSize ()];
32
+ NSData * ConvertMappingToNSData (fml::MallocMapping buffer) {
33
+ size_t size = buffer.GetSize ();
34
+ return [NSData dataWithBytesNoCopy: const_cast <uint8_t *>(buffer.Release ()) length: size];
16
35
}
17
36
18
- std::unique_ptr<fml::Mapping> CopyNSDataToMappingPtr (NSData * data) {
19
- auto mapping = CopyNSDataToMapping (data);
20
- return std::make_unique<fml::MallocMapping>(std::move (mapping));
37
+ std::unique_ptr<fml::Mapping> ConvertNSDataToMappingPtr (NSData * data) {
38
+ return std::make_unique<NSDataMapping>(data);
21
39
}
22
40
23
41
NSData * CopyMappingPtrToNSData (std::unique_ptr<fml::Mapping> mapping) {
Original file line number Diff line number Diff line change 22
22
FlutterBinaryMessageHandler handler = it->second ;
23
23
NSData * data = nil ;
24
24
if (message->hasData ()) {
25
- data = CopyMappingToNSData (message->releaseData ());
25
+ data = ConvertMappingToNSData (message->releaseData ());
26
26
}
27
27
handler (data, ^(NSData * reply) {
28
28
if (completer) {
29
29
if (reply) {
30
- completer->Complete (CopyNSDataToMappingPtr (reply));
30
+ completer->Complete (ConvertNSDataToMappingPtr (reply));
31
31
} else {
32
32
completer->CompleteEmpty ();
33
33
}
You can’t perform that action at this time.
0 commit comments