Fix failing unit test in Opera < 10.52 and add _.toArray benchmarks.

Former-commit-id: 0ed6d5c52b2486be4ccc212da7bbc7cb6d67cf7f
This commit is contained in:
John-David Dalton
2012-07-11 11:26:49 -04:00
parent 60ed65a73a
commit d496361555
3 changed files with 29 additions and 4 deletions

View File

@@ -814,7 +814,7 @@
// remove IE `shift` and `splice` fix from mutator Array functions mixin
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
// remove `noCharByIndex` from `_.reduceRight` and `_.toArray`
// remove `noCharByIndex` from `_.reduceRight`
source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1');
source = removeVar(source, 'extendIteratorOptions');

View File

@@ -129,12 +129,15 @@
var hasDontEnumBug = !propertyIsEnumerable.call({ 'valueOf': 0 }, 'valueOf');
/**
* Detect support for accessing string characters by index:
* Detect lack of support for accessing string characters by index:
* IE < 8 can't access characters by index and IE 8 can only access
* characters by index on string literals.
*/
var noCharByIndex = ('x'[0] + Object('x')[0]) != 'xx';
/** Detect if `Array#slice` cannot be used to convert strings to arrays (e.g. Opera < 10.52) */
var noArraySliceOnStrings = slice.call('x')[0] != 'x';
/* Detect if `Function#bind` exists and is inferred to be fast (i.e. all but V8) */
var isBindFast = nativeBind && /\n|Opera/.test(nativeBind + toString.call(window.opera));
@@ -727,7 +730,7 @@
'beforeLoop': {
'array': 'if (toString.call(iteratee) == stringClass) return collection.indexOf(target) > -1'
},
'inLoop': 'if (iteratee[index] === target) return true',
'inLoop': 'if (iteratee[index] === target) return true'
});
/**
@@ -1171,7 +1174,7 @@
}
var length = collection.length;
if (length === length >>> 0) {
return noCharByIndex && toString.call(collection) == stringClass
return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string')
? collection.split('')
: slice.call(collection);
}

View File

@@ -872,6 +872,28 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.toArray` with an array')
.add('Lo-Dash', function() {
lodash.toArray(numbers);
})
.add('Underscore', function() {
_.toArray(numbers);
})
);
suites.push(
Benchmark.Suite('`_.toArray` with an object')
.add('Lo-Dash', function() {
lodash.toArray(object);
})
.add('Underscore', function() {
_.toArray(object);
})
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.union`')
.add('Lo-Dash', function() {