_.size ludicrous speed improvement

This commit is contained in:
Raymond May Jr
2012-03-19 19:08:36 -05:00
parent 33be5c62b8
commit 2d3edb88f0

View File

@@ -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