8000 Fix failing unit test in Opera < 10.52 and add `_.toArray` benchmarks. · lodash/lodash@d496361 · GitHub
[go: up one dir, main page]

Skip to content

Commit d496361

Browse files
committed
Fix failing unit test in Opera < 10.52 and add _.toArray benchmarks.
Former-commit-id: 0ed6d5c52b2486be4ccc212da7bbc7cb6d67cf7f
1 parent 60ed65a commit d496361

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@
814814
// remove IE `shift` and `splice` fix from mutator Array functions mixin
815815
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
816816

817-
// remove `noCharByIndex` from `_.reduceRight` and `_.toArray`
817+
// remove `noCharByIndex` from `_.reduceRight`
818818
source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1');
819819

820820
source = removeVar(source, 'extendIteratorOptions');

lodash.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@
129129
var hasDontEnumBug = !propertyIsEnumerable.call({ 'valueOf': 0 }, 'valueOf');
130130

131131
/**
132-
* Detect support for accessing string characters by index:
132+
* Detect lack of support for accessing string characters by index:
133133
* IE < 8 can't access characters by index and IE 8 can only access
134134
* characters by index on string literals.
135135
*/
136136
var noCharByIndex = ('x'[0] + Object('x')[0]) != 'xx';
137137

138+
/** Detect if `Array#slice` cannot be used to convert strings to arrays (e.g. Opera < 10.52) */
139+
var noArraySliceOnStrings = slice.call('x')[0] != 'x';
140+
138141
/* Detect if `Function#bind` exists and is inferred to be fast (i.e. all but V8) */
139142
var isBindFast = nativeBind && /\n|Opera/.test(nativeBind + toString.call(window.opera));
140143

@@ -727,7 +730,7 @@
727730
'beforeLoop': {
728731
'array': 'if (toString.call(iteratee) == stringClass) return collection.indexOf(target) > -1'
729732
},
730-
'inLoop': 'if (iteratee[index] === target) return true',
733+
'inLoop': 'if (iteratee[index] === target) return true'
731734
});
732735

733736
/**
@@ -1171,7 +1174,7 @@
11711174
}
11721175
var length = collection.length;
11731176
if (length === length >>> 0) {
1174-
return noCharByIndex && toString.call(collection) == stringClass
1177+
return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string')
11751178
? collection.split('')
11761179
: slice.call(collection);
11771180
}

perf/perf.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,28 @@
872872

873873
/*--------------------------------------------------------------------------*/
874874

875+
suites.push(
876+
Benchmark.Suite('`_.toArray` with an array')
877+
.add('Lo-Dash', function() {
878+
lodash.toArray(numbers);
879+
})
880+
.add('Underscore', function() {
881+
_.toArray(numbers);
882+
})
883+
);
884+
885+
suites.push(
886+
Benchmark.Suite('`_.toArray` with an object')
887+
.add('Lo-Dash', function() {
888+
lodash.toArray(object);
889+
})
890+
.add('Underscore', function() {
891+
_.toArray(object);
892+
})
893+
);
894+
895+
/*--------------------------------------------------------------------------*/
896+
875897
suites.push(
876898
Benchmark.Suite('`_.union`')
877899
.add('Lo-Dash', function() {

0 commit comments

Comments
 (0)
0