diff options
author | Eugene Brevdo <ebrevdo@google.com> | 2018-09-12 17:54:13 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-12 17:58:37 -0700 |
commit | 30b711b07570b12c8880532aede428503c35e310 (patch) | |
tree | 05b039eaf4cd8b7f18ef5da4dde054d4e9fbcbd7 /tensorflow/core/platform | |
parent | e183b8d0328d7398cb6ffc530d1ae8fdbd2111c0 (diff) |
Modify signature of WritableFile::Append to accept StringPiece data by value.
PiperOrigin-RevId: 212736286
Diffstat (limited to 'tensorflow/core/platform')
-rw-r--r-- | tensorflow/core/platform/cloud/gcs_file_system.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/retrying_file_system.h | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/retrying_file_system_test.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/cord.h | 26 | ||||
-rw-r--r-- | tensorflow/core/platform/default/cord.h | 23 | ||||
-rw-r--r-- | tensorflow/core/platform/env_test.cc | 7 | ||||
-rw-r--r-- | tensorflow/core/platform/file_system.h | 8 | ||||
-rw-r--r-- | tensorflow/core/platform/hadoop/hadoop_file_system.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/posix/posix_file_system.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/s3/s3_file_system.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/windows/windows_file_system.cc | 2 |
11 files changed, 70 insertions, 8 deletions
diff --git a/tensorflow/core/platform/cloud/gcs_file_system.cc b/tensorflow/core/platform/cloud/gcs_file_system.cc index 8f959c018e..83228fab6f 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system.cc @@ -371,7 +371,7 @@ class GcsWritableFile : public WritableFile { ~GcsWritableFile() override { Close().IgnoreError(); } - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { TF_RETURN_IF_ERROR(CheckWritable()); sync_needed_ = true; outfile_ << data; diff --git a/tensorflow/core/platform/cloud/retrying_file_system.h b/tensorflow/core/platform/cloud/retrying_file_system.h index 92aa72be89..941ab7ad65 100644 --- a/tensorflow/core/platform/cloud/retrying_file_system.h +++ b/tensorflow/core/platform/cloud/retrying_file_system.h @@ -177,7 +177,7 @@ class RetryingWritableFile : public WritableFile { Close().IgnoreError(); } - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { return RetryingUtils::CallWithRetries( [this, &data]() { return base_file_->Append(data); }, initial_delay_microseconds_); diff --git a/tensorflow/core/platform/cloud/retrying_file_system_test.cc b/tensorflow/core/platform/cloud/retrying_file_system_test.cc index ec2c470db7..5910fef1d2 100644 --- a/tensorflow/core/platform/cloud/retrying_file_system_test.cc +++ b/tensorflow/core/platform/cloud/retrying_file_system_test.cc @@ -72,7 +72,7 @@ class MockRandomAccessFile : public RandomAccessFile { class MockWritableFile : public WritableFile { public: explicit MockWritableFile(const ExpectedCalls& calls) : calls_(calls) {} - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { return calls_.ConsumeNextCall("Append"); } Status Close() override { return calls_.ConsumeNextCall("Close"); } diff --git a/tensorflow/core/platform/cord.h b/tensorflow/core/platform/cord.h new file mode 100644 index 0000000000..7c5c6655be --- /dev/null +++ b/tensorflow/core/platform/cord.h @@ -0,0 +1,26 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_CORE_PLATFORM_CORD_H_ +#define TENSORFLOW_CORE_PLATFORM_CORD_H_ + +// Include appropriate platform-dependent implementations +#if defined(PLATFORM_GOOGLE) +#include "tensorflow/core/platform/google/cord.h" +#else +#include "tensorflow/core/platform/default/cord.h" +#endif + +#endif // TENSORFLOW_CORE_PLATFORM_CORD_H_ diff --git a/tensorflow/core/platform/default/cord.h b/tensorflow/core/platform/default/cord.h new file mode 100644 index 0000000000..f2e900d57b --- /dev/null +++ b/tensorflow/core/platform/default/cord.h @@ -0,0 +1,23 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_CORE_PLATFORM_DEFAULT_CORD_H_ +#define TENSORFLOW_CORE_PLATFORM_DEFAULT_CORD_H_ + +namespace absl { +class Cord; +} // namespace absl + +#endif // TENSORFLOW_CORE_PLATFORM_DEFAULT_CORD_H_ diff --git a/tensorflow/core/platform/env_test.cc b/tensorflow/core/platform/env_test.cc index 305a9a682f..2e32abdffb 100644 --- a/tensorflow/core/platform/env_test.cc +++ b/tensorflow/core/platform/env_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" +#include "tensorflow/core/platform/cord.h" #include "tensorflow/core/platform/null_file_system.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/test.h" @@ -345,7 +346,13 @@ TEST_F(DefaultEnvTest, LocalTempFilename) { // Write something to the temporary file. std::unique_ptr<WritableFile> file_to_write; TF_CHECK_OK(env->NewWritableFile(filename, &file_to_write)); +#if defined(PLATFORM_GOOGLE) + TF_CHECK_OK(file_to_write->Append("Nu")); + TF_CHECK_OK(file_to_write->Append(absl::Cord("ll"))); +#else + // TODO(ebrevdo): Remove this version. TF_CHECK_OK(file_to_write->Append("Null")); +#endif TF_CHECK_OK(file_to_write->Close()); TF_CHECK_OK(env->FileExists(filename)); diff --git a/tensorflow/core/platform/file_system.h b/tensorflow/core/platform/file_system.h index 077b1d79cf..30059dc02e 100644 --- a/tensorflow/core/platform/file_system.h +++ b/tensorflow/core/platform/file_system.h @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/platform/cord.h" #include "tensorflow/core/platform/file_statistics.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/platform.h" @@ -252,7 +253,12 @@ class WritableFile { virtual ~WritableFile(); /// \brief Append 'data' to the file. - virtual Status Append(const StringPiece& data) = 0; + virtual Status Append(StringPiece data) = 0; + + // \brief Append 'data' to the file. + virtual Status Append(const absl::Cord& cord) { + return errors::Unimplemented("Append(absl::Cord) is not implemented"); + } /// \brief Close the file. /// diff --git a/tensorflow/core/platform/hadoop/hadoop_file_system.cc b/tensorflow/core/platform/hadoop/hadoop_file_system.cc index 8cdb08f51b..eb35531e9f 100644 --- a/tensorflow/core/platform/hadoop/hadoop_file_system.cc +++ b/tensorflow/core/platform/hadoop/hadoop_file_system.cc @@ -282,7 +282,7 @@ class HDFSWritableFile : public WritableFile { } } - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { if (hdfs_->hdfsWrite(fs_, file_, data.data(), static_cast<tSize>(data.size())) == -1) { return IOError(filename_, errno); diff --git a/tensorflow/core/platform/posix/posix_file_system.cc b/tensorflow/core/platform/posix/posix_file_system.cc index 47bfa020ce..c7afab9583 100644 --- a/tensorflow/core/platform/posix/posix_file_system.cc +++ b/tensorflow/core/platform/posix/posix_file_system.cc @@ -91,7 +91,7 @@ class PosixWritableFile : public WritableFile { } } - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { size_t r = fwrite(data.data(), 1, data.size(), file_); if (r != data.size()) { return IOError(filename_, errno); diff --git a/tensorflow/core/platform/s3/s3_file_system.cc b/tensorflow/core/platform/s3/s3_file_system.cc index ce0f6cd741..e0b8e37745 100644 --- a/tensorflow/core/platform/s3/s3_file_system.cc +++ b/tensorflow/core/platform/s3/s3_file_system.cc @@ -211,7 +211,7 @@ class S3WritableFile : public WritableFile { std::ios_base::binary | std::ios_base::trunc | std::ios_base::in | std::ios_base::out)) {} - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { if (!outfile_) { return errors::FailedPrecondition( "The internal temporary file is not writable."); diff --git a/tensorflow/core/platform/windows/windows_file_system.cc b/tensorflow/core/platform/windows/windows_file_system.cc index 9079a5ccaa..6cf79634d7 100644 --- a/tensorflow/core/platform/windows/windows_file_system.cc +++ b/tensorflow/core/platform/windows/windows_file_system.cc @@ -150,7 +150,7 @@ class WindowsWritableFile : public WritableFile { } } - Status Append(const StringPiece& data) override { + Status Append(StringPiece data) override { DWORD bytes_written = 0; DWORD data_size = static_cast<DWORD>(data.size()); BOOL write_result = |