[libcxx-commits] [libcxx] [libc++] Optimize __hash_table copy constructors and assignment (PR #151951)
Nico Weber via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 25 10:02:32 PDT 2025
nico wrote:
This one also changes behavior, right? I think before this change, the copy of an unordered_foo had the same iteration order as the original unordered_foo, and after this change it's no longer true.
(This is fine by the standard, but still nice to mention in release notes.)
For example, this program used to print
```
url_1
url_2
```
but after this change it prints
```
url_2
url_1
```:
```
% cat repro.cc
#include <unordered_map>
#include <string>
#include <vector>
struct Context {
explicit Context(std::string session_id) : session_id(session_id) {}
Context(const Context&) = default;
std::string session_id;
std::unordered_map<std::string, std::vector<std::string>> url_passages_map;
};
void f(Context c) {
for (auto const& u : c.url_passages_map)
printf("%s\n", u.first.c_str());
}
int main() {
Context context("1");
context.url_passages_map.insert({"url_1", {"passage_11", "passage_12"}});
context.url_passages_map.insert({"url_2", {"passage_21", "passage_22"}});
f(context); // Copies.
}
```
https://github.com/llvm/llvm-project/pull/151951
More information about the libcxx-commits
mailing list