On 2014-02-24, 1:25 PM, Chris Peterson wrote:
On 2/23/14, 4:05 PM, Neil wrote:
Both ArrayLength and MOZ_ARRAY_LENGTH are typesafe when compiled as C++,
however ArrayLength has the disadvantage that it's not a constant
expression in MSVC. In unoptimised builds this is direly slow as the
templated function does not even get inlined, but even in optimised
builds the MSVC compiler is unable to completely optimise away static
variables. In particular, the variable is treated as if it is
forward-declared: the value is fetched from memory in each function that
uses it. (In my simple test there were enough registers to avoid
fetching the value more than once, but I don't know what happens if this
is not the case. And at least the optimiser was able to avoid creating
any static constructors.) Would it therefore be preferable to use
MOZ_ARRAY_LENGTH in such cases?

Which cases are those exactly? Note that I don't think that we need to care about the performance of ArrayLength() in non-optimized builds.

To avoid developers and reviewers from having to remember special cases,
maybe MOZ_ARRAY_LENGTH should just be the standard everywhere.

They're not quivalent.

Cheers,
Ehsan

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to