paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Optimize Map/Set fast key path. #397

Closed cscott closed 8 years ago

cscott commented 8 years ago

The expression typeof x === 'some string' is treated as a peephole optimization by JavaScript runtimes and optimized as a simple type test without an explicit string comparison. Refactoring the typeof x part into a variable cause this to be deoptimized: the type information is lost and we end up doing actual string comparison operations at runtime.

ljharb commented 8 years ago

Thanks!