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

Method Swap

common/internal/byte_string.cc:869–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

867}
868
869void ByteString::Swap(ByteString& other) {
870 ABSL_DCHECK_NE(&other, this);
871 using std::swap;
872
873 switch (other.GetKind()) {
874 case ByteStringKind::kSmall:
875 switch (GetKind()) {
876 case ByteStringKind::kSmall:
877 // small <=> small
878 swap(rep_.small, other.rep_.small);
879 break;
880 case ByteStringKind::kMedium:
881 // medium <=> small
882 swap(rep_, other.rep_);
883 break;
884 case ByteStringKind::kLarge: {
885 absl::Cord cord = std::move(GetLarge());
886 DestroyLarge();
887 rep_ = other.rep_;
888 other.SetLarge(std::move(cord));
889 } break;
890 }
891 break;
892 case ByteStringKind::kMedium:
893 switch (GetKind()) {
894 case ByteStringKind::kSmall:
895 swap(rep_, other.rep_);
896 break;
897 case ByteStringKind::kMedium:
898 swap(rep_.medium, other.rep_.medium);
899 break;
900 case ByteStringKind::kLarge: {
901 absl::Cord cord = std::move(GetLarge());
902 DestroyLarge();
903 rep_ = other.rep_;
904 other.SetLarge(std::move(cord));
905 } break;
906 }
907 break;
908 case ByteStringKind::kLarge:
909 switch (GetKind()) {
910 case ByteStringKind::kSmall: {
911 absl::Cord cord = std::move(other.GetLarge());
912 other.DestroyLarge();
913 other.rep_.small = rep_.small;
914 SetLarge(std::move(cord));
915 } break;
916 case ByteStringKind::kMedium: {
917 absl::Cord cord = std::move(other.GetLarge());
918 other.DestroyLarge();
919 other.rep_.medium = rep_.medium;
920 SetLarge(std::move(cord));
921 } break;
922 case ByteStringKind::kLarge:
923 swap(GetLarge(), other.GetLarge());
924 break;
925 }
926 break;

Callers 4

TEST_PFunction · 0.80
RegexPrecompilationBenchFunction · 0.80
FromMessageMethod · 0.80
swapFunction · 0.80

Calls 5

GetKindFunction · 0.85
DestroyLargeFunction · 0.85
GetKindMethod · 0.80
SetLargeMethod · 0.80
swapFunction · 0.70

Tested by 2

TEST_PFunction · 0.64
RegexPrecompilationBenchFunction · 0.64