On Fri, Sep 01, 2017 at 04:43:31PM -0400, Ehsan Akhgari wrote:
On 09/01/2017 01:18 PM, Boris Zbarsky wrote:
That has the unfortunate side-effect of allocating a new JS string
for every call, but we can probably optimize it if it becomes
necessary.
We could add a hasClassName if we wanted.
I'm kind of missing what's better about this compared to the other
suggestion of hasInstance() (thanks to Botond for catching my English
mistake!) I'm worried a bit because of the string compare that this
involves.
I think for things like this, as micro-optimization-land as this may
sound, we should keep performance in mind, and before making a call we
should try to see which variant would be faster. Where we're
bikeshedding over the cosmetics of the API, we should consider letting
the faster variant win. It's easy to write this off as non-important
right now but generic facilities like this are bound to be used some
day in a hot loop somewhere and then fixing things may be too costly
due to having to change all of the existing code.
Well, the main thing is that it already exists (well, the
string-returning version), so it seemed worth mentioning. The other
potential issue is that the `instanceof Ci.nsIDOM...` checks tend to
appear in places like JSMs, where we don't have direct access to
constructors for DOM interfaces by default.
In those cases, we tend to need something like `elem instanceof
getGlobalForObject(elem).Element`, which is probably at least two orders
of magnitude more expensive than the equivalent `hasClassName` call
would be.
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform