public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110287] _M_check_len is expensive Date: Mon, 19 Jun 2023 10:11:42 +0000 [thread overview] Message-ID: <bug-110287-4-4sbCHlkmqh@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110287-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110287 --- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jan Hubicka from comment #5) > > Do you mean something like this? > I sent my own version, but yours looks nicer. > > > > diff --git a/libstdc++-v3/include/bits/stl_vector.h > > b/libstdc++-v3/include/bits/stl_vector.h > > index 70ced3d101f..a4dbfeb8b5b 100644 > > --- a/libstdc++-v3/include/bits/stl_vector.h > > +++ b/libstdc++-v3/include/bits/stl_vector.h > > @@ -1902,6 +1902,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER > > return (__len < size() || __len > max_size()) ? max_size() : __len; > > } > > > > + // Called by _M_insert_aux etc. > > + _GLIBCXX20_CONSTEXPR > > + size_type > > + _M_check_len_1(const char* __s) const > > + { > > + if (__builtin_constant_p(size())) > Perhaps ruling this out for 32bit ports? Or can we assume that half of > address space can never be allocated in single block? No, I don't think we can assume that. > > + { > > + if (size() == 0) > > + return 1; > > + else if (size() < max_size() / 2) > I think even this conditional is safe to be assumed to be true, > since we can not allocate half of 64bit address space. There is no guarantee that std::vector<T, A>::max_size() is PTRDIFF_MAX. It depends on the Allocator type, A. A user-defined allocator could have max_size() == 100. > In general it is importnat to not fall through to _M_check_len. > > As I noticed, we may want to use assume attribute to make clear that > retval <= max_size () > to avoid other unnecesary throws downstream. > > Honza
next prev parent reply other threads:[~2023-06-19 10:11 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-16 14:43 [Bug libstdc++/110287] New: " hubicka at gcc dot gnu.org 2023-06-16 14:48 ` [Bug libstdc++/110287] " hubicka at gcc dot gnu.org 2023-06-16 15:37 ` hubicka at gcc dot gnu.org 2023-06-17 12:55 ` redi at gcc dot gnu.org 2023-06-17 13:01 ` redi at gcc dot gnu.org 2023-06-18 22:41 ` hubicka at ucw dot cz 2023-06-19 10:11 ` redi at gcc dot gnu.org [this message] 2023-06-19 10:23 ` Jan Hubicka 2023-06-19 10:24 ` hubicka at ucw dot cz 2023-06-23 16:09 ` hubicka at gcc dot gnu.org 2023-11-19 15:14 ` hubicka at gcc dot gnu.org 2023-11-19 15:46 ` hubicka at gcc dot gnu.org 2023-11-21 13:36 ` hubicka at gcc dot gnu.org 2023-11-21 14:17 ` cvs-commit at gcc dot gnu.org 2023-11-21 15:12 ` hubicka at gcc dot gnu.org 2023-11-27 9:44 ` rguenth at gcc dot gnu.org 2023-11-27 14:39 ` rguenth at gcc dot gnu.org
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: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110287-4-4sbCHlkmqh@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe 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).