Replace arrays.map with Array.prototype.map

See #441.
redux
David Majda 8 years ago
parent b044a021c4
commit 5f65de92bc

@ -222,7 +222,7 @@ function generateBytecode(ast) {
} }
function buildCall(functionIndex, delta, env, sp) { function buildCall(functionIndex, delta, env, sp) {
var params = arrays.map(objects.values(env), function(p) { return sp - p; }); var params = objects.values(env).map(function(p) { return sp - p; });
return [op.CALL, functionIndex, delta, params.length].concat(params); return [op.CALL, functionIndex, delta, params.length].concat(params);
} }
@ -574,7 +574,7 @@ function generateBytecode(ast) {
if (node.parts.length > 0) { if (node.parts.length > 0) {
regexp = '/^[' regexp = '/^['
+ (node.inverted ? '^' : '') + (node.inverted ? '^' : '')
+ arrays.map(node.parts, function(part) { + node.parts.map(function(part) {
return part instanceof Array return part instanceof Array
? js.regexpClassEscape(part[0]) ? js.regexpClassEscape(part[0])
+ '-' + '-'
@ -591,7 +591,7 @@ function generateBytecode(ast) {
} }
parts = '[' parts = '['
+ arrays.map(node.parts, function(part) { + node.parts.map(function(part) {
return part instanceof Array return part instanceof Array
? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]' ? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]'
: '"' + js.stringEscape(part) + '"'; : '"' + js.stringEscape(part) + '"';

@ -21,10 +21,9 @@ function generateJS(ast, options) {
'],', '],',
'', '',
'peg$bytecode = [', 'peg$bytecode = [',
indent2(arrays.map(ast.rules, function(rule) { indent2(ast.rules.map(function(rule) {
return 'peg$decode("' return 'peg$decode("'
+ js.stringEscape(arrays.map( + js.stringEscape(rule.bytecode.map(
rule.bytecode,
function(b) { return String.fromCharCode(b + 32); } function(b) { return String.fromCharCode(b + 32); }
).join('')) ).join(''))
+ '")'; + '")';
@ -32,8 +31,7 @@ function generateJS(ast, options) {
'],' '],'
].join('\n'); ].join('\n');
} else { } else {
return arrays.map( return ast.consts.map(
ast.consts,
function(c, i) { return 'peg$c' + i + ' = ' + c + ','; } function(c, i) { return 'peg$c' + i + ' = ' + c + ','; }
).join('\n'); ).join('\n');
} }
@ -443,7 +441,7 @@ function generateJS(ast, options) {
if (n === void 0) { if (n === void 0) {
return s(this.sp--); return s(this.sp--);
} else { } else {
values = arrays.map(arrays.range(this.sp - n + 1, this.sp + 1), s); values = arrays.range(this.sp - n + 1, this.sp + 1).map(s);
this.sp -= n; this.sp -= n;
return values; return values;
@ -524,8 +522,7 @@ function generateJS(ast, options) {
paramsLength = bc[ip + baseLength - 1]; paramsLength = bc[ip + baseLength - 1];
var value = c(bc[ip + 1]) + '(' var value = c(bc[ip + 1]) + '('
+ arrays.map( + bc.slice(ip + baseLength, ip + baseLength + paramsLength).map(
bc.slice(ip + baseLength, ip + baseLength + paramsLength),
function(p) { return stack.index(p); } function(p) { return stack.index(p); }
).join(', ') ).join(', ')
+ ')'; + ')';
@ -731,12 +728,12 @@ function generateJS(ast, options) {
if (options.trace) { if (options.trace) {
parts.push([ parts.push([
' var ' + arrays.map(arrays.range(0, stack.maxSp + 1), s).join(', ') + ',', ' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ',',
' startPos = peg$currPos;' ' startPos = peg$currPos;'
].join('\n')); ].join('\n'));
} else { } else {
parts.push( parts.push(
' var ' + arrays.map(arrays.range(0, stack.maxSp + 1), s).join(', ') + ';' ' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ';'
); );
} }
@ -959,8 +956,7 @@ function generateJS(ast, options) {
if (options.optimize === "size") { if (options.optimize === "size") {
startRuleIndices = '{ ' startRuleIndices = '{ '
+ arrays.map( + options.allowedStartRules.map(
options.allowedStartRules,
function(r) { return r + ': ' + asts.indexOfRule(ast, r); } function(r) { return r + ': ' + asts.indexOfRule(ast, r); }
).join(', ') ).join(', ')
+ ' }'; + ' }';
@ -972,8 +968,7 @@ function generateJS(ast, options) {
].join('\n')); ].join('\n'));
} else { } else {
startRuleFunctions = '{ ' startRuleFunctions = '{ '
+ arrays.map( + options.allowedStartRules.map(
options.allowedStartRules,
function(r) { return r + ': peg$parse' + r; } function(r) { return r + ': peg$parse' + r; }
).join(', ') ).join(', ')
+ ' }'; + ' }';
@ -1010,8 +1005,7 @@ function generateJS(ast, options) {
if (options.trace) { if (options.trace) {
if (options.optimize === "size") { if (options.optimize === "size") {
ruleNames = '[' ruleNames = '['
+ arrays.map( + ast.rules.map(
ast.rules,
function(r) { return '"' + js.stringEscape(r.name) + '"'; } function(r) { return '"' + js.stringEscape(r.name) + '"'; }
).join(', ') ).join(', ')
+ ']'; + ']';
@ -1267,8 +1261,7 @@ function generateJS(ast, options) {
commonjs: function() { commonjs: function() {
var parts = [], var parts = [],
dependencyVars = objects.keys(options.dependencies), dependencyVars = objects.keys(options.dependencies),
requires = arrays.map( requires = dependencyVars.map(
dependencyVars,
function(variable) { function(variable) {
return variable return variable
+ ' = require("' + ' = require("'
@ -1303,8 +1296,7 @@ function generateJS(ast, options) {
var dependencyIds = objects.values(options.dependencies), var dependencyIds = objects.values(options.dependencies),
dependencyVars = objects.keys(options.dependencies), dependencyVars = objects.keys(options.dependencies),
dependencies = '[' dependencies = '['
+ arrays.map( + dependencyIds.map(
dependencyIds,
function(id) { return '"' + js.stringEscape(id) + '"'; } function(id) { return '"' + js.stringEscape(id) + '"'; }
).join(', ') ).join(', ')
+ ']', + ']',
@ -1342,13 +1334,11 @@ function generateJS(ast, options) {
dependencyIds = objects.values(options.dependencies), dependencyIds = objects.values(options.dependencies),
dependencyVars = objects.keys(options.dependencies), dependencyVars = objects.keys(options.dependencies),
dependencies = '[' dependencies = '['
+ arrays.map( + dependencyIds.map(
dependencyIds,
function(id) { return '"' + js.stringEscape(id) + '"'; } function(id) { return '"' + js.stringEscape(id) + '"'; }
).join(', ') ).join(', ')
+ ']', + ']',
requires = arrays.map( requires = dependencyIds.map(
dependencyIds,
function(id) { return 'require("' + js.stringEscape(id) + '")'; } function(id) { return 'require("' + js.stringEscape(id) + '")'; }
).join(', '), ).join(', '),
params = dependencyVars.join(', '); params = dependencyVars.join(', ');

@ -56,20 +56,8 @@ var arrays = {
return arrays.indexOf(array, valueOrPredicate) !== -1; return arrays.indexOf(array, valueOrPredicate) !== -1;
}, },
map: function(array, iterator) {
var length = array.length,
result = new Array(length),
i;
for (i = 0; i < length; i++) {
result[i] = iterator(array[i], i);
}
return result;
},
pluck: function(array, key) { pluck: function(array, key) {
return arrays.map(array, function (e) { return e[key]; }); return array.map(function (e) { return e[key]; });
}, },
every: function(array, predicate) { every: function(array, predicate) {

Loading…
Cancel
Save