File tree 2 files changed +19
-3
lines changed
objectbox/lib/src/native/bindings
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,9 @@ class ReaderWithCBuffer {
121
121
void clear () => malloc.free (_bufferPtr);
122
122
123
123
ByteData access (Pointer <Uint8 > dataPtr, int size) {
124
- if (size > _maxBuffer) {
124
+ // If memcpy is not available, instead of using Dart memcpy implementation,
125
+ // directly convert to view which is a little faster.
126
+ if (isMemcpyNotAvailable || size > _maxBuffer) {
125
127
final uint8List = dataPtr.asTypedList (size);
126
128
return ByteData .view (uint8List.buffer, uint8List.offsetInBytes, size);
127
129
} else {
Original file line number Diff line number Diff line change @@ -8,10 +8,24 @@ import 'dart:io';
8
8
final _dart_memset memset =
9
9
_stdlib.lookupFunction <_c_memset, _dart_memset>('memset' );
10
10
11
+ /// If the native memcpy function should not be used.
12
+ ///
13
+ /// memcpy is not available to Flutter on iOS 15 simulator,
14
+ /// so use Dart API to copy data via asTypedList (which is much slower but works).
15
+ ///
16
+ /// https://github.com/objectbox/objectbox-dart/issues/313
17
+ final isMemcpyNotAvailable = Platform .isIOS;
18
+ final _dart_memcpy _memcpyDart = (dest, src, length) {
19
+ dest
20
+ .asTypedList (length)
21
+ .setAll (0 , src.asTypedList (length).getRange (0 , length));
22
+ };
23
+
11
24
/// memcpy (destination, source, num) copies the values of num bytes from the
12
25
/// data pointed to by source to the memory block pointed to by destination.
13
- final _dart_memcpy memcpy =
14
- _stdlib.lookupFunction <_c_memcpy, _dart_memcpy>('memcpy' );
26
+ final _dart_memcpy memcpy = isMemcpyNotAvailable
27
+ ? _memcpyDart
28
+ : _stdlib.lookupFunction <_c_memcpy, _dart_memcpy>('memcpy' );
15
29
16
30
// FFI signature
17
31
typedef _dart_memset = void Function (Pointer <Uint8 >, int , int );
You can’t perform that action at this time.
0 commit comments