Conversation
|
I'm not in favor of this optimization because it generates a temporary object in each case that may produce slower code: Array.prototype.splice.apply(a, [1, 2, b, c]);
Object.prototype.hasOwnProperty.call(d, "foo");
String.prototype.indexOf.call(e, "bar");---> [].splice.apply(a, [1, 2, b, c]);
({}).hasOwnProperty.call(d, "foo");
"".indexOf.call(e, "bar");Maybe if it were under a different option other than If you can demonstrate in micro-benchmarks on Chrome, FireFox, IE, Edge, Webkit/Safari that it is of equivalent speed to the original, I could be persuaded to keep it under |
|
@kzc your concern is reasonable, let's keep it under a new flag... any suggestions for a name? 😉 |
|
|
|
Adjustment of whitespaces would be dramatic 😅 |
|
|
| unsafe_prototype: true, | ||
| } | ||
| input: { | ||
| Array.prototype.splice.apply(a, [1, 2, b, c]); |
There was a problem hiding this comment.
Bad args for splice - were you thinking of concat?
There was a problem hiding this comment.
Eh?
> var a = [1,2,3], b = "b", c = "c";
undefined
> Array.prototype.splice.apply(a, [1, 2, b, c]);
[ 2, 3 ]
> a
[ 1, 'b', 'c' ]There was a problem hiding this comment.
I was mistaken. Not familiar with that usage.
There was a problem hiding this comment.
Confession: I always double-check with the docs when I use [].splice
There was a problem hiding this comment.
nevermind - it's using apply - groan!
:-)
0cd491f to
a1cbce0
Compare
- `Array.prototype.slice` => `[].slice`
a1cbce0 to
ca8fbd6
Compare
|
@kzc as for #1491 (comment), I've found the following jsperf links that might be relevant: https://jsperf.com/array-prototype-slice-call-vs-slice-call/17 Edit: great minds think alike, I see 😅 |
|
I just created this: https://jsperf.com/prototype-call-vs-literal-call |
|
|
|
The Would be curious if you could run it on older browsers - like IE8/9/10. I don't have any handy. |
|
|
IE8 is useless. Otherwise much like the timings for modern engines. Are you still okay with using the flag |
|
I'm happy with the extra flag either way - extra granularity is never an issue for me. |
- `Array.prototype.slice` => `[].slice` closes mishoo#1491
Array.prototype.slice➡️[].sliceThe optimisation rule works on all except two libraries within
test/benchmark.js(lodash.jsstatus unknown due to #1445 pending to be merged).master
This PR