Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does babel implement Set / Map polyfills

My question is related to computational complexity of Set / Map, Weak Set / Weak Map polyfills by Babel? Afaik there are no ES5 language features allowing to implement Set / Map directly, and so it might happen that Set / Map might use Array structure under the hood to implement lookup by object reference which would yield to O(N) lookup performance. And so the question is:

What is the computational complexity of Set / Map lookup operations?

Thank you in advance!

like image 979
Lu4 Avatar asked Jan 14 '16 12:01

Lu4


1 Answers

Babel uses core-js for its polyfill, from the GitHub repo:

core-js uses native collections in most case, just fixes methods / constructor, if it's required, and in old environment uses fast polyfill (O(1) lookup).

(Emphasis mine)

And if you're interested in the exact lookup, it's in this file. It's not backed by an array.

like image 182
CodingIntrigue Avatar answered Sep 28 '22 03:09

CodingIntrigue