Skip to content

Commit

Permalink
speedup underscore.js
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyl committed Jul 24, 2013
1 parent 9d525bf commit 1205c4e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,12 @@

// Convert an object into a list of `[key, value]` pairs.
_.pairs = function(obj) {
var pairs = [];
for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
var keys = _.keys(obj),
l = keys.length,
pairs = Array(l);
for (var i = 0; i < l; i++){
pairs[i] = ([keys[i], obj[keys[i]]]);
}
return pairs;
};

Expand Down

0 comments on commit 1205c4e

Please sign in to comment.