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

Method RemovePrefix

common/internal/byte_string.cc:402–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400}
401
402void 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
436void ByteString::RemoveSuffix(size_t n) {
437 ABSL_DCHECK_LE(n, size());

Callers 6

ConsumePrefixMethod · 0.80
PeekMethod · 0.80
AdvanceMethod · 0.80
TEST_PFunction · 0.80
IndexOfMethod · 0.80
LastIndexOfMethod · 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