Permalink
Browse files

_.size ludicrous speed improvement

  • Loading branch information...
1 parent 33be5c6 commit 2d3edb88f0bfda175082a2f55cf3cda980e5e489 @octatone octatone committed Mar 20, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 underscore.js
View
6 underscore.js
@@ -309,7 +309,11 @@
// Return the number of elements in an object.
_.size = function(obj) {
- return _.toArray(obj).length;
+ if (_.isArray(obj)) {
+ return obj.length;
+ } else {
+ return _.keys(obj).length;
+ }
};
// Array Functions

0 comments on commit 2d3edb8

Please sign in to comment.