@@ -53,8 +53,15 @@ export function supportsDirectArrayBuffers() {
53
53
return _supportsDirectArrayBuffers ;
54
54
}
55
55
56
+ export function createArrayBufferOrNativeArray ( length : number , useInts = false ) {
57
+ if ( ! supportsDirectArrayBuffers ( ) ) {
58
+ return createNativeArray ( length , useInts ) ;
59
+ } else {
60
+ return createArrayBuffer ( length , useInts ) ;
61
+ }
62
+ }
56
63
export function createArrayBuffer ( length : number , useInts = false ) {
57
- if ( global . isAndroid && ! supportsDirectArrayBuffers ( ) ) {
64
+ if ( ! supportsDirectArrayBuffers ( ) ) {
58
65
let bb : java . nio . ByteBuffer ;
59
66
if ( useInts ) {
60
67
bb = java . nio . ByteBuffer . allocateDirect ( length ) ;
@@ -67,7 +74,7 @@ export function createArrayBuffer(length: number, useInts = false) {
67
74
return useInts ? new Int8Array ( length ) : new Float32Array ( length ) ;
68
75
}
69
76
export function pointsFromBuffer ( typedArray : Float32Array | Int8Array , useInts = false ) {
70
- if ( global . isAndroid && ! supportsDirectArrayBuffers ( ) ) {
77
+ if ( ! supportsDirectArrayBuffers ( ) ) {
71
78
if ( useInts ) {
72
79
const buffer = typedArray . buffer ;
73
80
return ( ( buffer as any ) . nativeObject as java . nio . ByteBuffer ) . array ( ) ;
@@ -92,8 +99,8 @@ export function arrayToNativeArray(array, useInts = false) {
92
99
}
93
100
94
101
// export const nativeArrayToArray = profile('nativeArrayToArray', function(array) {
95
- export function nativeArrayToArray ( array ) {
96
- if ( global . isAndroid && ! supportsDirectArrayBuffers ( ) ) {
102
+ export function nativeArrayToArray ( array ) : number [ ] {
103
+ if ( ! supportsDirectArrayBuffers ( ) ) {
97
104
const result = [ ] ;
98
105
for ( let index = 0 ; index < array . length ; index ++ ) {
99
106
result [ index ] = array [ index ] ;
@@ -103,12 +110,12 @@ export function nativeArrayToArray(array) {
103
110
}
104
111
return array ;
105
112
}
106
- export function createNativeArray ( length ) {
107
- if ( global . isAndroid ) {
113
+ export function createNativeArray ( length , useInts = false ) : number [ ] {
114
+ if ( useInts ) {
115
+ return Array . create ( 'int' , length ) ;
116
+ } else {
108
117
return Array . create ( 'float' , length ) ;
109
118
}
110
- // At least, set length to use it for iterations
111
- return new Array ( length ) ;
112
119
}
113
120
114
121
export function parseDashEffect ( value : string ) {
0 commit comments