Replacing ::Cord with absl::Cord.

PiperOrigin-RevId: 309958768
Change-Id: I91aa6ffea8bd35384bdcc2f29f934c8cb33ca44e
This commit is contained in:
A. Unique TensorFlower 2020-05-05 09:16:10 -07:00 committed by TensorFlower Gardener
parent cbec9ecd13
commit f9a3aaf60d
5 changed files with 25 additions and 23 deletions

View File

@ -79,10 +79,10 @@ inline void SetProtobufStringSwapAllowed(std::string* src, std::string* dest) {
// tools/proto_text's generated code. They have the same name as the versions
// in core/platform/protobuf.h, so the generation code doesn't need to determine
// if the type is Cord or string at generation time.
inline std::string ProtobufStringToString(const Cord& s) {
inline std::string ProtobufStringToString(const absl::Cord& s) {
return s.ToString();
}
inline void SetProtobufStringSwapAllowed(std::string* src, Cord* dest) {
inline void SetProtobufStringSwapAllowed(std::string* src, absl::Cord* dest) {
dest->CopyFrom(*src);
}
#endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)

View File

@ -132,7 +132,7 @@ std::unique_ptr<StringListDecoder> NewStringListDecoder(const string& in) {
}
#if defined(TENSORFLOW_PROTOBUF_USES_CORD)
void AssignRefCounted(StringPiece src, core::RefCounted* obj, Cord* out) {
void AssignRefCounted(StringPiece src, core::RefCounted* obj, absl::Cord* out) {
obj->Ref();
out->Clear();
// Defines a lambda to unref "obj" when Cord deletes this piece of
@ -144,7 +144,7 @@ void AssignRefCounted(StringPiece src, core::RefCounted* obj, Cord* out) {
cleanup);
}
void EncodeStringList(const tstring* strings, int64 n, Cord* out) {
void EncodeStringList(const tstring* strings, int64 n, absl::Cord* out) {
out->Clear();
for (int i = 0; i < n; ++i) {
::strings::CordAppendVarint(strings[i].size(), out);
@ -154,7 +154,7 @@ void EncodeStringList(const tstring* strings, int64 n, Cord* out) {
}
}
bool DecodeStringList(const Cord& src, string* strings, int64 n) {
bool DecodeStringList(const absl::Cord& src, string* strings, int64 n) {
std::vector<uint32> sizes(n);
CordReader reader(src);
int64 tot = 0;
@ -177,7 +177,7 @@ bool DecodeStringList(const Cord& src, string* strings, int64 n) {
return true;
}
bool DecodeStringList(const Cord& src, tstring* strings, int64 n) {
bool DecodeStringList(const absl::Cord& src, tstring* strings, int64 n) {
std::vector<uint32> sizes(n);
CordReader reader(src);
int64 tot = 0;
@ -200,13 +200,13 @@ bool DecodeStringList(const Cord& src, tstring* strings, int64 n) {
return true;
}
void CopyFromArray(Cord* c, const char* base, size_t bytes) {
void CopyFromArray(absl::Cord* c, const char* base, size_t bytes) {
c->CopyFrom(base, bytes);
}
class CordStringListEncoderImpl : public StringListEncoder {
public:
explicit CordStringListEncoderImpl(Cord* out) : out_(out) {}
explicit CordStringListEncoderImpl(absl::Cord* out) : out_(out) {}
~CordStringListEncoderImpl() override = default;
void Append(const protobuf::MessageLite& m) override {
@ -222,13 +222,13 @@ class CordStringListEncoderImpl : public StringListEncoder {
void Finalize() override { out_->Append(rest_); }
private:
Cord* out_;
absl::Cord* out_;
string rest_;
};
class CordStringListDecoderImpl : public StringListDecoder {
public:
explicit CordStringListDecoderImpl(const Cord& in) : reader_(in) {}
explicit CordStringListDecoderImpl(const absl::Cord& in) : reader_(in) {}
~CordStringListDecoderImpl() override = default;
bool ReadSizes(std::vector<uint32>* sizes) override {
@ -254,11 +254,11 @@ class CordStringListDecoderImpl : public StringListDecoder {
std::vector<char> tmp_;
};
std::unique_ptr<StringListEncoder> NewStringListEncoder(Cord* out) {
std::unique_ptr<StringListEncoder> NewStringListEncoder(absl::Cord* out) {
return std::unique_ptr<StringListEncoder>(new CordStringListEncoderImpl(out));
}
std::unique_ptr<StringListDecoder> NewStringListDecoder(const Cord& in) {
std::unique_ptr<StringListDecoder> NewStringListDecoder(const absl::Cord& in) {
return std::unique_ptr<StringListDecoder>(new CordStringListDecoderImpl(in));
}

View File

@ -100,31 +100,33 @@ std::unique_ptr<StringListDecoder> NewStringListDecoder(const string& in);
// Store src contents in *out. If backing memory for src is shared with *out,
// will ref obj during the call and will arrange to unref obj when no
// longer needed.
void AssignRefCounted(StringPiece src, core::RefCounted* obj, Cord* out);
void AssignRefCounted(StringPiece src, core::RefCounted* obj, absl::Cord* out);
// TODO(kmensah): Macro guard this with a check for Cord support.
inline void CopyToArray(const Cord& src, char* dst) { src.CopyToArray(dst); }
inline void CopyToArray(const absl::Cord& src, char* dst) {
src.CopyToArray(dst);
}
// Copy n bytes of src to dst. If pos >= src.size() the result is empty.
// If pos + n > src.size() the subrange [pos, size()) is copied.
inline void CopySubrangeToArray(const Cord& src, int64 pos, int64 n,
inline void CopySubrangeToArray(const absl::Cord& src, int64 pos, int64 n,
char* dst) {
src.Subcord(pos, n).CopyToArray(dst);
}
// Store encoding of strings[0..n-1] in *out.
void EncodeStringList(const tstring* strings, int64 n, Cord* out);
void EncodeStringList(const tstring* strings, int64 n, absl::Cord* out);
// Decode n strings from src and store in strings[0..n-1].
// Returns true if successful, false on parse error.
bool DecodeStringList(const Cord& src, std::string* strings, int64 n);
bool DecodeStringList(const Cord& src, tstring* strings, int64 n);
bool DecodeStringList(const absl::Cord& src, std::string* strings, int64 n);
bool DecodeStringList(const absl::Cord& src, tstring* strings, int64 n);
// Assigns base[0..bytes-1] to *c
void CopyFromArray(Cord* c, const char* base, size_t bytes);
void CopyFromArray(absl::Cord* c, const char* base, size_t bytes);
std::unique_ptr<StringListEncoder> NewStringListEncoder(Cord* out);
std::unique_ptr<StringListDecoder> NewStringListDecoder(const Cord& in);
std::unique_ptr<StringListEncoder> NewStringListEncoder(absl::Cord* out);
std::unique_ptr<StringListDecoder> NewStringListDecoder(const absl::Cord& in);
#endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)
} // namespace port

View File

@ -33,7 +33,7 @@ void CopyToBuffer(const string& src, char* dest) {
}
#ifdef PLATFORM_GOOGLE
void CopyToBuffer(const Cord& src, char* dest) { src.CopyToArray(dest); }
void CopyToBuffer(const absl::Cord& src, char* dest) { src.CopyToArray(dest); }
#endif
} // namespace port
} // namespace toco

View File

@ -80,7 +80,7 @@ tensorflow::Status Exists(const string& filename, const Options& options);
// Copy `src` string to `dest`. User must ensure `dest` has enough space.
#if defined(PLATFORM_GOOGLE)
void CopyToBuffer(const ::Cord& src, char* dest);
void CopyToBuffer(const ::absl::Cord& src, char* dest);
#endif // PLATFORM_GOOGLE
void CopyToBuffer(const string& src, char* dest);