perf(map): use Array.prototype.map

Replace helper functions with the native ES5 method
This commit is contained in:
Rouven Weßling
2014-09-04 23:51:02 +02:00
committed by Brian Ford
parent 6b05105c08
commit a591e8b8d3
6 changed files with 5 additions and 16 deletions

View File

@@ -55,7 +55,6 @@
"trim": false,
"isElement": false,
"makeMap": false,
"map": false,
"size": false,
"includes": false,
"arrayRemove": false,

View File

@@ -50,7 +50,6 @@
trim: true,
isElement: true,
makeMap: true,
map: true,
size: true,
includes: true,
arrayRemove: true,
@@ -617,15 +616,6 @@ function nodeName_(element) {
}
function map(obj, iterator, context) {
var results = [];
forEach(obj, function(value, index, list) {
results.push(iterator.call(context, value, index, list));
});
return results;
}
/**
* @description
* Determines the number of elements in an array, the number of properties an object has, or

View File

@@ -118,7 +118,7 @@ function orderByFilter($parse){
if (!(isArrayLike(array))) return array;
if (!sortPredicate) return array;
sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
sortPredicate = map(sortPredicate, function(predicate){
sortPredicate = sortPredicate.map(function(predicate){
var descending = false, get = predicate || identity;
if (isString(predicate)) {
if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {

View File

@@ -335,7 +335,7 @@ var karmaDump = window.dump || function() {
};
window.dump = function () {
karmaDump.apply(undefined, map(arguments, function(arg) {
karmaDump.apply(undefined, Array.prototype.map.call(arguments, function(arg) {
return angular.mock.dump(arg);
}));
};

View File

@@ -147,12 +147,12 @@ describe('parser', function() {
it('should tokenize function invocation', function() {
var tokens = lex("a()");
expect(map(tokens, function(t) { return t.text;})).toEqual(['a', '(', ')']);
expect(tokens.map(function(t) { return t.text;})).toEqual(['a', '(', ')']);
});
it('should tokenize method invocation', function() {
var tokens = lex("a.b.c (d) - e.f()");
expect(map(tokens, function(t) { return t.text;})).
expect(tokens.map(function(t) { return t.text;})).
toEqual(['a.b', '.', 'c', '(', 'd', ')', '-', 'e', '.', 'f', '(', ')']);
});

View File

@@ -41,7 +41,7 @@ describe('q', function() {
}
function _argumentsToString(args) {
return map(sliceArgs(args), _argToString).join(',');
return sliceArgs(args).map(_argToString).join(',');
}
// Help log invocation of success(), finally(), progress() and error()