MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / RemoveSuffix

Method RemoveSuffix

common/internal/byte_string.cc:436–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434}
435
436void ByteString::RemoveSuffix(size_t n) {
437 ABSL_DCHECK_LE(n, size());
438 if (n == 0) {
439 return;
440 }
441 switch (GetKind()) {
442 case ByteStringKind::kSmall:
443 rep_.small.size -= n;
444 break;
445 case ByteStringKind::kMedium:
446 rep_.medium.size -= n;
447 if (rep_.medium.size <= kSmallByteStringCapacity) {
448 const auto* refcount = GetMediumReferenceCount();
449 SetSmall(GetMediumArena(), GetMedium());
450 StrongUnref(refcount);
451 }
452 break;
453 case ByteStringKind::kLarge: {
454 auto& large = GetLarge();
455 const auto large_size = large.size();
456 const auto new_large_pos = 0;
457 const auto new_large_size = large_size - n;
458 large = large.Subcord(new_large_pos, new_large_size);
459 if (new_large_size <= kSmallByteStringCapacity) {
460 auto large_copy = std::move(large);
461 DestroyLarge();
462 SetSmall(nullptr, large_copy);
463 }
464 } break;
465 }
466}
467
468void ByteString::CopyToArray(char* absl_nonnull out) const {
469 ABSL_DCHECK(out != nullptr);

Callers 1

TEST_PFunction · 0.80

Calls 6

GetKindFunction · 0.85
GetMediumFunction · 0.85
StrongUnrefFunction · 0.85
DestroyLargeFunction · 0.85
sizeFunction · 0.50
sizeMethod · 0.45

Tested by 1

TEST_PFunction · 0.64