libstdc++: Use __builtin_expect in __dynamic_cast
The null pointer check is never needed for correct code, only to gracefully handle undefined cases. Add __builtin_expect to be sure that we don't pessimize the valid uses. libstdc++-v3/ChangeLog: * libsupc++/dyncast.cc (__dynamic_cast): Add __builtin_expect to precondition check.
This commit is contained in:
parent
bc97e736a5
commit
da6ce35106
|
@ -47,9 +47,9 @@ __dynamic_cast (const void *src_ptr, // object started from
|
||||||
const __class_type_info *dst_type, // desired target type
|
const __class_type_info *dst_type, // desired target type
|
||||||
ptrdiff_t src2dst) // how src and dst are related
|
ptrdiff_t src2dst) // how src and dst are related
|
||||||
{
|
{
|
||||||
if (!src_ptr)
|
if (__builtin_expect(!src_ptr, 0))
|
||||||
/* Handle precondition violations gracefully. */
|
return NULL; // Handle precondition violations gracefully.
|
||||||
return NULL;
|
|
||||||
const void *vtable = *static_cast <const void *const *> (src_ptr);
|
const void *vtable = *static_cast <const void *const *> (src_ptr);
|
||||||
const vtable_prefix *prefix =
|
const vtable_prefix *prefix =
|
||||||
(adjust_pointer <vtable_prefix>
|
(adjust_pointer <vtable_prefix>
|
||||||
|
|
Loading…
Reference in New Issue