This speeds-up thin-link for ~29% for large programs.
Details
Diff Detail
- Build Status
Buildable 8062 Build 8062: arc lint + arc unit
Event Timeline
LGTM
My understanding is that resize copies in the default value whereas emplace_back constructs one in place, and the latter is more efficient (especially when only 1 element being added to the list). Dehao - is that the reasoning you had?
To calculate size(), one needs to traverse the entire list, which is O(n). resize also need to traverse to the end of the list and append on the tail.
Looks like it's implementation dependent, both gcc and clang uses loop to implement std::list::size:
#cat test.cc
#include <list>
int p(std::list<int> t) {
return t.size();
}
#g++ --std=c++11 test.cc -S -O2 -o - |grep jne -B4
.L4:
movq (%rdx), %rdx
addq $1, %rax
cmpq %rdx, %rdi
jne .L4
#clang --std=c++11 test.cc -S -O2 -o - |grep jne -B4
.LBB0_1: # =>This Inner Loop Header: Depth=1
movq (%rcx), %rcx
incl %eax
cmpq %rcx, %rdi
jne .LBB0_1
Hmm I was going off this complexity section here http://en.cppreference.com/w/cpp/container/list/size