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
* [Bug libstdc++/101203] Remove unnecessary empty check in std::function 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 ` redi at gcc dot gnu.org 2021-06-25 6:28 ` redi at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2021-06-25 6:25 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203 --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- PR 56551 uses a similar idea. It wouldn't be ABI compatible with existing code though. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/101203] Remove unnecessary empty check in std::function 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 ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2021-06-25 6:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203 --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- We also can't guarantee that the address of the new function is unique across shared libraries, making the test in _M_equal unreliable. The technique in std::any has a fallback to using RTTI. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/101203] Remove unnecessary empty check in std::function 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 4 siblings, 0 replies; 6+ messages in thread From: lutztonineubert at gmail dot com @ 2021-06-28 4:09 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203 --- Comment #3 from Toni Neubert <lutztonineubert at gmail dot com> --- Thank you Jonathan for your fast answer. To sad but the shared library issue seems valid. Can shared libraries exist is a freestanding environment (like a bare-metal microcontroller running without OS)? So there could maybe an optimization for some targets? ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/101203] Remove unnecessary empty check in std::function 2021-06-25 4:49 [Bug libstdc++/101203] New: Remove unnecessary empty check in std::function lutztonineubert at gmail dot com ` (2 preceding siblings ...) 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 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2021-06-28 9:16 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203 --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- You can't use std::function at all in those environments. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/101203] Remove unnecessary empty check in std::function 2021-06-25 4:49 [Bug libstdc++/101203] New: Remove unnecessary empty check in std::function lutztonineubert at gmail dot com ` (3 preceding siblings ...) 2021-06-28 9:16 ` redi at gcc dot gnu.org @ 2024-02-28 10:41 ` lutztonineubert at gmail dot com 4 siblings, 0 replies; 6+ messages in thread From: lutztonineubert at gmail dot com @ 2024-02-28 10:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203 Toni Neubert <lutztonineubert at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |WONTFIX --- Comment #5 from Toni Neubert <lutztonineubert at gmail dot com> --- Improvement not possible for all environment. ^ 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).