public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101203] New: Remove unnecessary empty check in std::function
@ 2021-06-25  4:49 lutztonineubert at gmail dot com
  2021-06-25  6:25 ` [Bug libstdc++/101203] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: lutztonineubert at gmail dot com @ 2021-06-25  4:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101203
           Summary: Remove unnecessary empty check in std::function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

Hello,

this empty() check in std_function.h:

https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/bits/std_function.h#L558

      _Res
      operator()(_ArgTypes... __args) const
      {
        if (_M_empty())
          __throw_bad_function_call();
        return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
      }

can, as I assume, be removed to gain better performance.

An empty, default constructed std::function could be initialized with
__throw_bad_function_call() instead with nullptr/zeros.

If std::function::operator()(...) gets called, still
__throw_bad_function_call() would get called as before.

The implementation of `explicit operator bool()` or better `_M_empty()` would
then check if the function is initialized with the address of
__throw_bad_function_call.

This would be a similar technic as used in std::any:
https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/experimental/any#L436

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

end of thread, other threads:[~2024-02-28 10:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25  4:49 [Bug libstdc++/101203] New: Remove unnecessary empty check in std::function lutztonineubert at gmail dot com
2021-06-25  6:25 ` [Bug libstdc++/101203] " redi at gcc dot gnu.org
2021-06-25  6:28 ` redi at gcc dot gnu.org
2021-06-28  4:09 ` lutztonineubert at gmail dot com
2021-06-28  9:16 ` redi at gcc dot gnu.org
2024-02-28 10:41 ` lutztonineubert at gmail dot com

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