* [PATCH RFA] libstdc++: small dynamic_cast optimization
@ 2022-09-07 1:44 Jason Merrill
2022-09-07 8:20 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2022-09-07 1:44 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH RFA] libstdc++: small dynamic_cast optimization
2022-09-07 1:44 [PATCH RFA] libstdc++: small dynamic_cast optimization Jason Merrill
@ 2022-09-07 8:20 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-09-07 8:20 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches, libstdc++
On Wed, 7 Sept 2022 at 02:45, Jason Merrill via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> 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?
Yes, I think so. If there's a fast path, we should take it.
>
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-07 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 1:44 [PATCH RFA] libstdc++: small dynamic_cast optimization Jason Merrill
2022-09-07 8:20 ` Jonathan Wakely
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).