public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/96088] New: Range insertion into unordered_map is less effective than a loop with insertion
@ 2020-07-06 18:37 antoshkka at gmail dot com
  2020-07-09  6:23 ` [Bug libstdc++/96088] " fdumont at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: antoshkka at gmail dot com @ 2020-07-06 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96088
           Summary: Range insertion into unordered_map is less effective
                    than a loop with insertion
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the function f1:

static constexpr std::initializer_list<std::pair<const char*, int>> lst = {
    {"long_str_for_dynamic_allocating", 1}};

void f1() {
    std::unordered_map<std::string, int> m(1);
    m.insert(lst.begin(), lst.end());
}


It creates a temporary and as a result makes 4 allocations. Meanwhile f2 does
not create a temporary and does aonly 3 allocations:

void f2() {
    std::unordered_map<std::string, int> m(1);
    for (const auto& x : lst) {
        m.insert(x);
    }
}


Godbolt playground: https://godbolt.org/z/VapmBU

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

end of thread, other threads:[~2021-06-02 12:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 18:37 [Bug libstdc++/96088] New: Range insertion into unordered_map is less effective than a loop with insertion antoshkka at gmail dot com
2020-07-09  6:23 ` [Bug libstdc++/96088] " fdumont at gcc dot gnu.org
2020-07-09  8:31 ` redi at gcc dot gnu.org
2020-07-09 10:50 ` glisse at gcc dot gnu.org
2020-07-09 14:46 ` redi at gcc dot gnu.org
2020-08-04 17:36 ` fdumont at gcc dot gnu.org
2021-05-25 19:27 ` fdumont at gcc dot gnu.org
2021-06-02 12:33 ` cvs-commit 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).