public inbox for
 help / color / mirror / Atom feed
From: Jason Merrill <>
Subject: [PATCH RFA] libstdc++: small dynamic_cast optimization
Date: Tue,  6 Sep 2022 21:44:44 -0400	[thread overview]
Message-ID: <> (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?


	* libsupc++/ (__dynamic_cast): Avoid virtual function
	call in simple success case.
 libstdc++-v3/libsupc++/ | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/libsupc++/ b/libstdc++-v3/libsupc++/
index 853c911a4cf..616e4c05766 100644
--- a/libstdc++-v3/libsupc++/
+++ b/libstdc++-v3/libsupc++/
@@ -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

             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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* 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).