[PATCH] [libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.

Eric Fiselier eric at efcs.ca
Fri Mar 6 08:23:47 PST 2015


Hi mclow.lists, howard.hinnant,

In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++. 

This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.

This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`. 

This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.

On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.

http://reviews.llvm.org/D8109

Files:
  include/memory
  include/vector

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8109.21364.patch
Type: text/x-patch
Size: 5702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150306/4182dfd0/attachment.bin>


More information about the cfe-commits mailing list