Skip to content

Commit 289a9e9

Browse files
committed
better code re-use
1 parent 70e864b commit 289a9e9

1 file changed

Lines changed: 19 additions & 54 deletions

File tree

src/Data/ArrayBuffer/Typed.js

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,60 +37,25 @@ exports.lengthImpl = function lemgthImpl (v) {
3737

3838
// Typed Arrays
3939

40-
exports.newUint8ClampedArray = function newUint8ClampedArray (a,mb,mc) {
41-
return mc === null ? ( mb === null ? new Uint8ClampedArray(a)
42-
: new Uint8ClampedArray(a,mb)
43-
)
44-
: new Uint8ClampedArray(a,mb,mc);
45-
};
46-
exports.newUint32Array = function newUint32Array (a,mb,mc) {
47-
return mc === null ? ( mb === null ? new Uint32Array(a)
48-
: new Uint32Array(a,mb)
49-
)
50-
: new Uint32Array(a,mb,mc);
51-
};
52-
exports.newUint16Array = function newUint16Array (a,mb,mc) {
53-
return mc === null ? ( mb === null ? new Uint16Array(a)
54-
: new Uint16Array(a,mb)
55-
)
56-
: new Uint16Array(a,mb,mc);
57-
};
58-
exports.newUint8Array = function newUint8Array (a,mb,mc) {
59-
return mc === null ? ( mb === null ? new Uint8Array(a)
60-
: new Uint8Array(a,mb)
61-
)
62-
: new Uint8Array(a,mb,mc);
63-
};
64-
exports.newInt32Array = function newInt32Array (a,mb,mc) {
65-
return mc === null ? ( mb === null ? new Int32Array(a)
66-
: new Int32Array(a,mb)
67-
)
68-
: new Int32Array(a,mb,mc);
69-
};
70-
exports.newInt16Array = function newInt16Array (a,mb,mc) {
71-
return mc === null ? ( mb === null ? new Int16Array(a)
72-
: new Int16Array(a,mb)
73-
)
74-
: new Int16Array(a,mb,mc);
75-
};
76-
exports.newInt8Array = function newInt8Array (a,mb,mc) {
77-
return mc === null ? ( mb === null ? new Int8Array(a)
78-
: new Int8Array(a,mb)
79-
)
80-
: new Int8Array(a,mb,mc);
81-
};
82-
exports.newFloat32Array = function newFloat32Array (a,mb,mc) {
83-
return mc === null ? ( mb === null ? new Float32Array(a)
84-
: new Float32Array(a,mb)
85-
)
86-
: new Float32Array(a,mb,mc);
87-
};
88-
exports.newFloat64Array = function newFloat64Array (a,mb,mc) {
89-
return mc === null ? ( mb === null ? new Float64Array(a)
90-
: new Float64Array(a,mb)
91-
)
92-
: new Float64Array(a,mb,mc);
93-
};
40+
41+
function newArray (f) {
42+
return function newArray_ (a,mb,mc) {
43+
return mc === null ? ( mb === null ? new f(a)
44+
: new f(a,mb)
45+
)
46+
: new f(a,mb,mc);
47+
};
48+
}
49+
50+
exports.newUint8ClampedArray = newArray(Uint8ClampedArray);
51+
exports.newUint32Array = newArray(Uint32Array);
52+
exports.newUint16Array = newArray(Uint16Array);
53+
exports.newUint8Array = newArray(Uint8Array);
54+
exports.newInt32Array = newArray(Int32Array);
55+
exports.newInt16Array = newArray(Int16Array);
56+
exports.newInt8Array = newArray(Int8Array);
57+
exports.newFloat32Array = newArray(Float32Array);
58+
exports.newFloat64Array = newArray(Float64Array);
9459

9560

9661
// ------

0 commit comments

Comments
 (0)