Optimize _.pairs.

Former-commit-id: 1de87609a8635fb8d48bc558fbdabc545da53b4b
This commit is contained in:
John-David Dalton
2012-08-31 15:45:27 -07:00
parent 84d69fa2a1
commit 2c31411ffb
4 changed files with 29 additions and 4 deletions

View File

@@ -209,7 +209,6 @@ require({
* `_.defer`
* `_.difference`
* `_.each`
* `_.escape`
* `_.every`, `_.all`
* `_.extend`
* `_.filter`, `_.select`
@@ -220,6 +219,7 @@ require({
* `_.groupBy`
* `_.indexOf`
* `_.intersection`
* `_.invert`
* `_.invoke`
* `_.isArguments`
* `_.isDate`
@@ -238,6 +238,7 @@ require({
* `_.min`
* `_.mixin`
* `_.omit`
* `_.pairs`
* `_.pick`
* `_.pluck`
* `_.reduce`, `_.foldl`, `_.inject`

View File

@@ -595,7 +595,7 @@
.replace(/(?: *\/\/.*\n)*\s*'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, '$2')
// remove `isKeysFast` from `beforeLoop.object` of `mapIteratorOptions`
.replace(/=\s*'\s*\+\s*\(isKeysFast.+/, "= []'")
// remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pluck`, and `sortBy`
// remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pairs`, `pluck`, and `sortBy`
.replace(/'\s*\+\s*\(isKeysFast[^)]+?\)\s*\+\s*'/g, '.push')
// remove data object property assignment in `createIterator`
.replace(/\s*.+?\.isKeysFast *=.+/, '');

View File

@@ -1865,7 +1865,7 @@
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to inspect..
* @param {Object} object The object to inspect.
* @returns {Array} Returns new array of key-value pairs.
* @example
*
@@ -1875,7 +1875,7 @@
var pairs = createIterator({
'args': 'object',
'init':'[]',
'inLoop': 'result.push([index, value])'
'inLoop': 'result' + (isKeysFast ? '[ownIndex] = ' : '.push') + '([index, value])'
});
/**

View File

@@ -864,6 +864,18 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.invert`')
.add('Lo-Dash', '\
lodash.invert(object)'
)
.add('Underscore', '\
_.invert(object)'
)
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.invoke` iterating an array')
.add('Lo-Dash', '\
@@ -1104,6 +1116,18 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.pairs`')
.add('Lo-Dash', '\
lodash.pairs(object)'
)
.add('Underscore', '\
_.pairs(object)'
)
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.pick`')
.add('Lo-Dash', '\