@@ -8,13 +8,20 @@ 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;
11
+ final _dart_memcpy? _memcpyNative = _lookupMemcpyOrNull ();
12
+
13
+ _dart_memcpy? _lookupMemcpyOrNull () {
14
+ try {
15
+ return _stdlib.lookupFunction <_c_memcpy, _dart_memcpy>('memcpy' );
16
+ } catch (_) {
17
+ return null ;
18
+ }
19
+ }
20
+
21
+ /// If the native memcpy function is not available
22
+ /// and a Dart implementation is used.
23
+ final isMemcpyNotAvailable = _memcpyNative == null ;
24
+
18
25
final _dart_memcpy _memcpyDart = (dest, src, length) {
19
26
dest
20
27
.asTypedList (length)
@@ -23,9 +30,12 @@ final _dart_memcpy _memcpyDart = (dest, src, length) {
23
30
24
31
/// memcpy (destination, source, num) copies the values of num bytes from the
25
32
/// data pointed to by source to the memory block pointed to by destination.
26
- final _dart_memcpy memcpy = isMemcpyNotAvailable
27
- ? _memcpyDart
28
- : _stdlib.lookupFunction <_c_memcpy, _dart_memcpy>('memcpy' );
33
+ ///
34
+ /// Note: the native memcpy might not be available
35
+ /// (e.g. for Flutter on iOS 15 simulator), then a Dart implementation is used
36
+ /// to copy data via asTypedList (which is much slower).
37
+ /// https://github.com/objectbox/objectbox-dart/issues/313
38
+ final _dart_memcpy memcpy = _memcpyNative ?? _memcpyDart;
29
39
30
40
// FFI signature
31
41
typedef _dart_memset = void Function (Pointer <Uint8 >, int , int );
0 commit comments