[llvm-bugs] [Bug 30317] New: Constructing a vector with an initializer list generates more code than push_back / emplace_back
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 7 15:02:53 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=30317
Bug ID: 30317
Summary: Constructing a vector with an initializer list
generates more code than push_back / emplace_back
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: dcheng at google.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Simple test case:
#include <stdio.h>
#include <string>
#include <vector>
void PrintVector(const std::vector<std::string>& strings) {
for (const auto& s : strings) {
printf("%s\n", s.data());
}
}
void Foo() {
std::vector<std::string> names;
names.push_back("abc");
names.push_back("def");
names.push_back("ghi");
PrintVector(names);
}
void Bar() {
std::vector<std::string> names{
"abc",
"def",
"ghi",
};
PrintVector(names);
}
int main() {
Foo();
Bar();
}
With -O2, the function sizes are roughly the same. Foo() is 847 bytes, Bar() is
844 bytes.
With -O1, Foo() is much smaller at 294 bytes, while Bar() is 396 bytes.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160907/04057607/attachment.html>
More information about the llvm-bugs
mailing list