libstdc++: Optimize std::any_cast by replacing indirect call
authorTim Adye <Tim.Adye@cern.ch>
Fri, 4 Jun 2021 14:59:38 +0000 (15:59 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 4 Jun 2021 14:59:38 +0000 (15:59 +0100)
commitf6bb145c0bff19767931d37733be11c8acc6fa00
tree369f46cbe40b2b8c2ee3bc73467bcebb07570723
parentf78f25f43864f38ae5a6a9fcce8f26c94fe45bcd
libstdc++: Optimize std::any_cast by replacing indirect call

This significantly improves the performance of std::any_cast, by
avoiding an indirect call to the _S_manage function through a function
pointer. Before we make that indirect call we've already established
that the contained value has the expected type, which means we also know
the manager type, and so can call one of its members directly.

We also know the precise type in the any::emplace functions, because
we've just constructed that type, so we can use the new member there
too. That doesn't seem to affect performance, but we might as well use
the new _S_access function anyway.

Signed-off-by: Tim Adye <Tim.Adye@cern.ch>
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/std/any (any::_Manager::_S_access): New static
function to access the contained value.
(any::emplace, __any_caster): Use _S_access member of the
manager type.
libstdc++-v3/include/std/any