| 400 | } |
| 401 | |
| 402 | void ByteString::RemovePrefix(size_t n) { |
| 403 | ABSL_DCHECK_LE(n, size()); |
| 404 | if (n == 0) { |
| 405 | return; |
| 406 | } |
| 407 | switch (GetKind()) { |
| 408 | case ByteStringKind::kSmall: |
| 409 | std::memmove(rep_.small.data, rep_.small.data + n, rep_.small.size - n); |
| 410 | rep_.small.size -= n; |
| 411 | break; |
| 412 | case ByteStringKind::kMedium: |
| 413 | rep_.medium.data += n; |
| 414 | rep_.medium.size -= n; |
| 415 | if (rep_.medium.size <= kSmallByteStringCapacity) { |
| 416 | const auto* refcount = GetMediumReferenceCount(); |
| 417 | SetSmall(GetMediumArena(), GetMedium()); |
| 418 | StrongUnref(refcount); |
| 419 | } |
| 420 | break; |
| 421 | case ByteStringKind::kLarge: { |
| 422 | auto& large = GetLarge(); |
| 423 | const auto large_size = large.size(); |
| 424 | const auto new_large_pos = n; |
| 425 | const auto new_large_size = large_size - n; |
| 426 | large = large.Subcord(new_large_pos, new_large_size); |
| 427 | if (new_large_size <= kSmallByteStringCapacity) { |
| 428 | auto large_copy = std::move(large); |
| 429 | DestroyLarge(); |
| 430 | SetSmall(nullptr, large_copy); |
| 431 | } |
| 432 | } break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | void ByteString::RemoveSuffix(size_t n) { |
| 437 | ABSL_DCHECK_LE(n, size()); |