Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use folly::IsRelocatable in folly::small_vector #1934

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions folly/small_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,8 @@ class small_vector
this->u.setCapacity(o.u.getCapacity());
}
} else {
if (kShouldCopyInlineTrivial) {
copyInlineTrivial<Value>(o);
o.resetSizePolicy();
if (kShouldRelocateInlineTrivial) {
relocateInlineTrivial(o);
} else {
auto n = o.size();
std::uninitialized_copy(
Expand Down Expand Up @@ -1047,6 +1046,14 @@ class small_vector
this->setSize(sz);
}

void relocateInlineTrivial(small_vector& o) {
// Copy the entire inline storage, instead of just size() values, to make
// the loop fixed-size and unrollable.
std::memcpy(u.buffer(), o.u.buffer(), MaxInline * kSizeOfValue);
this->setSize(o.size());
o.resetSizePolicy();
}

template <class T>
typename std::enable_if<is_trivially_copyable_v<T>>::type copyInlineTrivial(
small_vector const& o) {
Expand Down Expand Up @@ -1313,6 +1320,10 @@ class small_vector
is_trivially_copyable_v<Value> &&
sizeof(InlineStorageType) <= hardware_constructive_interference_size / 2;

static constexpr bool kShouldRelocateInlineTrivial =
IsRelocatable<Value>::value &&
sizeof(InlineStorageType) <= hardware_constructive_interference_size / 2;

static bool constexpr kHasInlineCapacity = !BaseType::kAlwaysUseHeap &&
sizeof(HeapPtrWithCapacity) < sizeof(InlineStorageType);

Expand Down