Cleanup some InlineData internal layout specific details from cord.h

This makes future platform specific internal layout changes easier to land.

PiperOrigin-RevId: 477843948
Change-Id: I4ca4fdea5e965261c029d08319aba0290721c227
pull/1283/head
Martijn Vels 2 years ago committed by Copybara-Service
parent 40ede06edc
commit cfa5dc7576
  1. 7
      absl/strings/cord.h

@ -894,9 +894,8 @@ class Cord {
// memcpy is much faster when operating on a known size. On most supported // memcpy is much faster when operating on a known size. On most supported
// platforms, the small string optimization is large enough that resizing // platforms, the small string optimization is large enough that resizing
// to 15 bytes does not cause a memory allocation. // to 15 bytes does not cause a memory allocation.
absl::strings_internal::STLStringResizeUninitialized(dst, absl::strings_internal::STLStringResizeUninitialized(dst, kMaxInline);
sizeof(data_) - 1); memcpy(&(*dst)[0], data_.as_chars(), kMaxInline);
memcpy(&(*dst)[0], &data_, sizeof(data_) - 1);
// erase is faster than resize because the logic for memory allocation is // erase is faster than resize because the logic for memory allocation is
// not needed. // not needed.
dst->erase(inline_size()); dst->erase(inline_size());
@ -1189,7 +1188,7 @@ inline cord_internal::CordRepFlat* Cord::InlineRep::MakeFlatWithExtraCapacity(
size_t len = data_.inline_size(); size_t len = data_.inline_size();
auto* result = CordRepFlat::New(len + extra); auto* result = CordRepFlat::New(len + extra);
result->length = len; result->length = len;
memcpy(result->Data(), data_.as_chars(), sizeof(data_)); memcpy(result->Data(), data_.as_chars(), InlineRep::kMaxInline);
return result; return result;
} }

Loading…
Cancel
Save