Skip to content

Commit

Permalink
js engines tend to create sparse arrays under the good when given arr…
Browse files Browse the repository at this point in the history
…ay lengths at construction. Use literal [] instead
  • Loading branch information
marcuswestin committed Jun 23, 2013
1 parent a3a7393 commit 0bbf61d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion asyncMap.js
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion map.js
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion pack.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion range.js
Expand Up @@ -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
Expand Down

0 comments on commit 0bbf61d

Please sign in to comment.