public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109383] New: [QoI] std::type_index::operator<=> should not call __builtin_strcmp twice
@ 2023-04-03  3:12 de34 at live dot cn
  2023-04-03 10:05 ` [Bug libstdc++/109383] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: de34 at live dot cn @ 2023-04-03  3:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109383

            Bug ID: 109383
           Summary: [QoI] std::type_index::operator<=> should not call
                    __builtin_strcmp twice
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

The current the current implementation of type_index::operator<=> in libstdc++
is the following:
```
    strong_ordering
    operator<=>(const type_index& __rhs) const noexcept
    {
      if (*_M_target == *__rhs._M_target)
        return strong_ordering::equal;
      if (_M_target->before(*__rhs._M_target))
        return strong_ordering::less;
      return strong_ordering::greater;
    }
```

When the two referenced type_info are not equal, the current implementation may
needed to call __builtin_strcmp twice (each in type_info::operator== and
type_info::before).

IIUC whenever it's necessary to call __builtin_strcmp from operator<=>, we
should just call it once and return __builtin_strcmp(...) <=> 0. Perhaps it
would be better to add a member function to type_info for convenience.


It's a bit strange to me that while all implementations I investigated (libc++,
libstdc++, and msvc stl) need to use strcmp/__builtin_strcmp for type_info
comparison in some cases, currently none of them avoids calling it twice from
type_index::operator<=>, although strcmp/__builtin_strcmp is already performing
three-way comparison.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-04  0:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03  3:12 [Bug libstdc++/109383] New: [QoI] std::type_index::operator<=> should not call __builtin_strcmp twice de34 at live dot cn
2023-04-03 10:05 ` [Bug libstdc++/109383] " redi at gcc dot gnu.org
2023-04-03 10:35 ` redi at gcc dot gnu.org
2023-04-03 10:37 ` redi at gcc dot gnu.org
2023-04-04  0:50 ` pinskia at gcc dot gnu.org

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