From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org
Subject: [PATCH RFA] libstdc++: small dynamic_cast optimization
Date: Tue, 6 Sep 2022 21:44:44 -0400 [thread overview]
Message-ID: <20220907014444.1469136-1-jason@redhat.com> (raw)
An email discussion of optimizing EH led me to wonder why we weren't doing
this already. Not that this change affects EH at all.
Tested x86_64-pc-linux-gnu. Does this seem worthwhile?
libstdc++-v3/ChangeLog:
* libsupc++/dyncast.cc (__dynamic_cast): Avoid virtual function
call in simple success case.
---
libstdc++-v3/libsupc++/dyncast.cc | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libstdc++-v3/libsupc++/dyncast.cc b/libstdc++-v3/libsupc++/dyncast.cc
index 853c911a4cf..616e4c05766 100644
--- a/libstdc++-v3/libsupc++/dyncast.cc
+++ b/libstdc++-v3/libsupc++/dyncast.cc
@@ -71,6 +71,12 @@ __dynamic_cast (const void *src_ptr, // object started from
if (whole_prefix->whole_type != whole_type)
return NULL;
+ // Avoid virtual function call in the simple success case.
+ if (src2dst >= 0
+ && src2dst == -prefix->whole_object
+ && *whole_type == *dst_type)
+ return const_cast <void *> (whole_ptr);
+
whole_type->__do_dyncast (src2dst, __class_type_info::__contained_public,
dst_type, whole_ptr, src_type, src_ptr, result);
if (!result.dst_ptr)
base-commit: 0a2fba3697411c07a8330abfe7460ce62bce5e7f
--
2.31.1
next reply other threads:[~2022-09-07 1:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 1:44 Jason Merrill [this message]
2022-09-07 8:20 ` Jonathan Wakely
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=20220907014444.1469136-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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: link
Be 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).