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

Function LegacyByteString

common/internal/byte_string.cc:1041–1072  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1039}
1040
1041absl::string_view LegacyByteString(const ByteString& string, bool stable,
1042 google::protobuf::Arena* absl_nonnull arena) {
1043 ABSL_DCHECK(arena != nullptr);
1044 if (string.empty()) {
1045 return absl::string_view();
1046 }
1047 const ByteStringKind kind = string.GetKind();
1048 if (kind == ByteStringKind::kMedium && string.GetMediumArena() == arena) {
1049 google::protobuf::Arena* absl_nullable other_arena = string.GetMediumArena();
1050 if (other_arena == arena || other_arena == nullptr) {
1051 // Legacy values do not preserve arena. For speed, we assume the arena is
1052 // compatible.
1053 return string.GetMedium();
1054 }
1055 }
1056 if (stable && kind == ByteStringKind::kSmall) {
1057 return string.GetSmall();
1058 }
1059 std::string* absl_nonnull result = google::protobuf::Arena::Create<std::string>(arena);
1060 switch (kind) {
1061 case ByteStringKind::kSmall:
1062 result->assign(string.GetSmall());
1063 break;
1064 case ByteStringKind::kMedium:
1065 result->assign(string.GetMedium());
1066 break;
1067 case ByteStringKind::kLarge:
1068 absl::CopyCordToString(string.GetLarge(), result);
1069 break;
1070 }
1071 return absl::string_view(*result);
1072}
1073
1074} // namespace cel::common_internal

Callers 3

TEST_PFunction · 0.85
LegacyStringValueFunction · 0.85
LegacyBytesValueFunction · 0.85

Calls 3

GetKindMethod · 0.80
GetMediumArenaMethod · 0.80
emptyMethod · 0.45

Tested by 1

TEST_PFunction · 0.68