Map/Set.prototype.size is O(n)

Daniel Herman daniel.c.herman at gmail.com
Wed Mar 29 15:15:45 UTC 2017


In reading the relevant section for the `size` accessors (http://www.ecma-
international.org/ecma-262/7.0/index.html#sec-get-map.prototype.size), I'm
confused and wondering why this was defined as an O(n) operation in the
`get` accessor rather than as an additional step in the `set`, `delete`,
and `clear` methods to track an internal `[[Size]]` variable or something,
making the public `size` accessor capable of being O(1).

It seems surprising to me that in order to be spec compliant, Map and Set
implementations must implement accessors that have surprising perf
implications.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170329/c9455b0b/attachment.html>


More information about the es-discuss mailing list