public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-3082] libstdc++: Use __builtin_expect in __dynamic_cast Date: Mon, 23 Aug 2021 13:46:18 +0000 (GMT) [thread overview] Message-ID: <20210823134618.520E53857814@sourceware.org> (raw) https://gcc.gnu.org/g:da6ce351069bda74d814b723934008d75bd4e8b0 commit r12-3082-gda6ce351069bda74d814b723934008d75bd4e8b0 Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Aug 23 13:12:24 2021 +0100 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. Diff: --- libstdc++-v3/libsupc++/dyncast.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/libsupc++/dyncast.cc b/libstdc++-v3/libsupc++/dyncast.cc index f8f707ee4d4..a1138d04f6d 100644 --- a/libstdc++-v3/libsupc++/dyncast.cc +++ b/libstdc++-v3/libsupc++/dyncast.cc @@ -47,9 +47,9 @@ __dynamic_cast (const void *src_ptr, // object started from const __class_type_info *dst_type, // desired target type ptrdiff_t src2dst) // how src and dst are related { - if (!src_ptr) - /* Handle precondition violations gracefully. */ - return NULL; + if (__builtin_expect(!src_ptr, 0)) + return NULL; // Handle precondition violations gracefully. + const void *vtable = *static_cast <const void *const *> (src_ptr); const vtable_prefix *prefix = (adjust_pointer <vtable_prefix> @@ -70,7 +70,7 @@ __dynamic_cast (const void *src_ptr, // object started from (whole_vtable, -ptrdiff_t (offsetof (vtable_prefix, origin)))); if (whole_prefix->whole_type != whole_type) return NULL; - + whole_type->__do_dyncast (src2dst, __class_type_info::__contained_public, dst_type, whole_ptr, src_type, src_ptr, result); if (!result.dst_ptr)
reply other threads:[~2021-08-23 13:46 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210823134618.520E53857814@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).