-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.js
52 lines (40 loc) · 968 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
exports.arrayCreate = arrayCreate
exports.arrayExpand = arrayExpand
exports.arrayFill = arrayFill
exports.typedArrayExpand = typedArrayExpand
exports.FastMap = FastMap
// Arrays
// ------
function arrayCreate(length, value) {
return arrayFill(new Array(length), value, 0, length)
}
function arrayExpand(source, length, value) {
return arrayFill(source, value, source.length, length)
}
function arrayFill(target, value, start, end) {
for (var i = start; i < end; i++) {
target[i] = value
}
return target
}
// Typed arrays
// ------------
function typedArrayExpand(source, length) {
var SourceTypedArray = source.constructor
var target = new SourceTypedArray(length)
target.set(source)
return target
}
// Maps
// ------------
function map() {
this.x = 0
delete this.x
}
function FastMap() {
var self = new map()
function ForceEfficientMap() {}
ForceEfficientMap.prototype = self
new ForceEfficientMap()
return self
}