File indexing completed on 2024-11-15 09:01:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_STRINGS_INTERNAL_CORD_REP_CRC_H_
0016 #define ABSL_STRINGS_INTERNAL_CORD_REP_CRC_H_
0017
0018 #include <cassert>
0019 #include <cstdint>
0020
0021 #include "absl/base/config.h"
0022 #include "absl/base/optimization.h"
0023 #include "absl/crc/internal/crc_cord_state.h"
0024 #include "absl/strings/internal/cord_internal.h"
0025
0026 namespace absl {
0027 ABSL_NAMESPACE_BEGIN
0028 namespace cord_internal {
0029
0030
0031
0032
0033
0034
0035
0036 struct CordRepCrc : public CordRep {
0037 CordRep* child;
0038 absl::crc_internal::CrcCordState crc_cord_state;
0039
0040
0041
0042
0043
0044
0045 static CordRepCrc* New(CordRep* child, crc_internal::CrcCordState state);
0046
0047
0048 static void Destroy(CordRepCrc* node);
0049 };
0050
0051
0052
0053
0054 inline CordRep* RemoveCrcNode(CordRep* rep) {
0055 assert(rep != nullptr);
0056 if (ABSL_PREDICT_FALSE(rep->IsCrc())) {
0057 CordRep* child = rep->crc()->child;
0058 if (rep->refcount.IsOne()) {
0059 delete rep->crc();
0060 } else {
0061 CordRep::Ref(child);
0062 CordRep::Unref(rep);
0063 }
0064 return child;
0065 }
0066 return rep;
0067 }
0068
0069
0070
0071 inline CordRep* SkipCrcNode(CordRep* rep) {
0072 assert(rep != nullptr);
0073 if (ABSL_PREDICT_FALSE(rep->IsCrc())) {
0074 return rep->crc()->child;
0075 } else {
0076 return rep;
0077 }
0078 }
0079
0080 inline const CordRep* SkipCrcNode(const CordRep* rep) {
0081 assert(rep != nullptr);
0082 if (ABSL_PREDICT_FALSE(rep->IsCrc())) {
0083 return rep->crc()->child;
0084 } else {
0085 return rep;
0086 }
0087 }
0088
0089 inline CordRepCrc* CordRep::crc() {
0090 assert(IsCrc());
0091 return static_cast<CordRepCrc*>(this);
0092 }
0093
0094 inline const CordRepCrc* CordRep::crc() const {
0095 assert(IsCrc());
0096 return static_cast<const CordRepCrc*>(this);
0097 }
0098
0099 }
0100 ABSL_NAMESPACE_END
0101 }
0102
0103 #endif