Permalink
Browse files

js engines tend to create sparse arrays under the good when given arr…

…ay lengths at construction. Use literal [] instead
  • Loading branch information...
1 parent a3a7393 commit 0bbf61d306167f18df546bad5311f3ffd02dc0b9 @marcuswestin committed Jun 23, 2013
Showing with 4 additions and 4 deletions.
  1. +1 −1 asyncMap.js
  2. +1 −1 map.js
  3. +1 −1 pack.js
  4. +1 −1 range.js
View
@@ -2,7 +2,7 @@ var asyncEach = require('std/asyncEach')
var isList = require('std/isList')
module.exports = function asyncMap(items, opts) {
- var result = isList(items) ? new Array(items.length) : {}
+ var result = isList(items) ? [] : {}
var includeNullValues = !opts.filterNulls
var context = opts.context || this
View
2 map.js
@@ -6,7 +6,7 @@ module.exports = function map(obj, fn) {
if (!obj) { return null }
if (obj.map == Array.prototype.map) { return obj.map(fn) }
- var result = isList(obj) ? new Array(obj.length) : {}
+ var result = isList(obj) ? [] : {}
each(obj, function(val, key) {
result[key] = fn(val, key)
})
View
@@ -221,7 +221,7 @@ module.exports = function pack (format) {
status = isNaN(n = parseFloat(argument)) || n === -Infinity || n === +Infinity ? n : 0;
exp = 0;
len = 2 * bias + 1 + precisionBits + 3;
- bin = new Array(len);
+ bin = [];
signal = (n = status !== 0 ? 0 : n) < 0;
n = Math.abs(n);
intPart = Math.floor(n);
View
@@ -7,7 +7,7 @@ module.exports = function range(start, stop, step) {
var length = Math.max(Math.ceil((stop - start) / step), 0)
var index = 0
- var result = new Array(length)
+ var result = []
while (index < length) {
result[index++] = start

0 comments on commit 0bbf61d

Please sign in to comment.