Internal change

PiperOrigin-RevId: 311474047
Change-Id: I2c8bcfc0c13d5bf82eaeeadc43202171eeecab8b
This commit is contained in:
A. Unique TensorFlower 2020-05-13 22:52:09 -07:00 committed by TensorFlower Gardener
parent 4afee5f519
commit 9173c6c3d3
2 changed files with 8 additions and 19 deletions

View File

@ -503,12 +503,10 @@ Status Reader::ReadTensors(std::vector<Tensor>* read_tensors) {
size_t tensor_proto_size = tensor_proto_strs[complex_index].second;
TensorProto tp;
#if defined(PLATFORM_GOOGLE)
auto tensor_proto_ptr = tensor_proto_str.release();
absl::Cord c;
c.AppendExternalMemory(
absl::string_view(tensor_proto_ptr, tensor_proto_size),
tensor_proto_ptr,
[](void* arg) { delete[] static_cast<char*>(arg); });
absl::string_view tensor_proto_view(tensor_proto_str.get(),
tensor_proto_size);
absl::Cord c = absl::MakeCordFromExternal(
tensor_proto_view, [s = std::move(tensor_proto_str)] {});
if (!tp.ParseFromCord(c)) {
return errors::Internal("Could not parse TensorProto");
}
@ -615,11 +613,9 @@ Status Reader::ReadRecord(absl::Cord* record) {
} else {
auto tmp_str = absl::make_unique<tstring>();
TF_RETURN_IF_ERROR(input_stream_->ReadNBytes(length, tmp_str.get()));
tstring* tmp_str_raw = tmp_str.release();
record->AppendExternalMemory(*tmp_str_raw, tmp_str_raw,
[](absl::string_view unused_data, void* arg) {
delete static_cast<tstring*>(arg);
});
absl::string_view tmp_str_view(*tmp_str);
record->Append(
absl::MakeCordFromExternal(tmp_str_view, [s = std::move(tmp_str)] {}));
return Status::OK();
}
}

View File

@ -134,14 +134,7 @@ std::unique_ptr<StringListDecoder> NewStringListDecoder(const string& in) {
#if defined(TENSORFLOW_PROTOBUF_USES_CORD)
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
// memory. +[] converts the lambda to a C style function pointer.
auto cleanup = +[](absl::string_view donotcare, void* obj) {
reinterpret_cast<core::RefCounted*>(obj)->Unref();
};
out->AppendExternalMemory(absl::string_view(src.data(), src.size()), obj,
cleanup);
*out = absl::MakeCordFromExternal(src, [obj] { obj->Unref(); });
}
void EncodeStringList(const tstring* strings, int64 n, absl::Cord* out) {