diff options
-rw-r--r-- | tensorflow/contrib/makefile/proto_text_cc_files.txt | 1 | ||||
-rw-r--r-- | tensorflow/core/BUILD | 23 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/eager/context.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/lib/core/stringpiece.cc | 54 | ||||
-rw-r--r-- | tensorflow/core/lib/core/stringpiece.h | 117 | ||||
-rw-r--r-- | tensorflow/core/lib/strings/strcat.h | 3 | ||||
-rw-r--r-- | tensorflow/tensorflow.bzl | 3 |
7 files changed, 27 insertions, 176 deletions
diff --git a/tensorflow/contrib/makefile/proto_text_cc_files.txt b/tensorflow/contrib/makefile/proto_text_cc_files.txt index 7d26429f9c..22b11f1c57 100644 --- a/tensorflow/contrib/makefile/proto_text_cc_files.txt +++ b/tensorflow/contrib/makefile/proto_text_cc_files.txt @@ -56,7 +56,6 @@ tensorflow/core/lib/hash/hash.cc tensorflow/core/lib/hash/crc32c.cc tensorflow/core/lib/hash/crc32c_accelerate.cc tensorflow/core/lib/core/threadpool.cc -tensorflow/core/lib/core/stringpiece.cc tensorflow/core/lib/core/status.cc tensorflow/core/lib/core/coding.cc tensorflow/core/lib/core/arena.cc diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 51225f34bc..7648db9c12 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -612,6 +612,7 @@ cc_library( copts = tf_copts(), deps = tf_lib_proto_parsing_deps() + [ ":platform_base", + "@com_google_absl//absl/strings", "@double_conversion//:double-conversion", ], ) @@ -694,6 +695,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":lib_internal", + "@com_google_absl//absl/strings", ], ) @@ -730,10 +732,12 @@ cc_library( # required to use tf_cc_test, and that rule will change / into _ cc_library( name = "core_stringpiece", - srcs = ["lib/core/stringpiece.cc"], hdrs = ["lib/core/stringpiece.h"], copts = tf_copts(), - deps = [":platform_base"], + deps = [ + ":platform_base", + "@com_google_absl//absl/strings", + ], ) # Test support library needed for all tests @@ -1589,7 +1593,9 @@ cc_library( cc_library( name = "mobile_additional_lib_deps", - deps = tf_additional_lib_deps(), + deps = tf_additional_lib_deps() + [ + "@com_google_absl//absl/strings", + ], ) # Native library support for iOS applications. @@ -2067,6 +2073,7 @@ cc_library( ], }), deps = tf_additional_lib_deps() + [ + "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core/platform/default/build_config:platformlib", ] + if_static([":lib_internal_impl"]), @@ -2084,7 +2091,6 @@ cc_library( exclude = [ "**/*test*", "framework/variant.cc", - "lib/core/stringpiece.cc", "lib/hash/crc32c_accelerate.cc", "lib/gif/**/*", "lib/jpeg/**/*", @@ -2099,7 +2105,6 @@ cc_library( ) + tf_additional_lib_srcs( exclude = [ "**/*test*", - "lib/core/stringpiece.cc", "platform/**/cuda.h", "platform/**/cuda_libdevice_path.cc", "platform/**/stream_executor.h", @@ -2210,6 +2215,7 @@ cc_library( ":lib", ":lib_internal", "//tensorflow/core/platform/default/build_config:png", + "@com_google_absl//absl/strings", "@zlib_archive//:zlib", ], ) @@ -2260,6 +2266,7 @@ cc_library( deps = [ "//tensorflow/core/platform/default/build_config:jpeg", "//tensorflow/core/platform/default/build_config:logging", + "@com_google_absl//absl/strings", ], ) @@ -2291,6 +2298,7 @@ cc_library( deps = [ "//tensorflow/core/platform/default/build_config:gif", "//tensorflow/core/platform/default/build_config:logging", + "@com_google_absl//absl/strings", ], ) @@ -2318,6 +2326,7 @@ cc_library( linkopts = ["-ldl"], deps = [ "//tensorflow/core/platform/default/build_config:logging", + "@com_google_absl//absl/strings", "@png_archive//:png", ], ) @@ -2546,6 +2555,10 @@ tf_cuda_library( cc_header_only_library( name = "framework_headers_lib", + extra_deps = [ + # ABSL headers get dropped, so we add them back here. + "@com_google_absl//absl/strings", + ], visibility = ["//visibility:public"], deps = [ ":framework", diff --git a/tensorflow/core/common_runtime/eager/context.cc b/tensorflow/core/common_runtime/eager/context.cc index b859b06fa0..39a3b49cd1 100644 --- a/tensorflow/core/common_runtime/eager/context.cc +++ b/tensorflow/core/common_runtime/eager/context.cc @@ -26,7 +26,7 @@ namespace { bool ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val) { bool val; - if (ReadBoolFromEnvVar(env_var_name, default_val, &val).ok()) { + if (tensorflow::ReadBoolFromEnvVar(env_var_name, default_val, &val).ok()) { return val; } return default_val; diff --git a/tensorflow/core/lib/core/stringpiece.cc b/tensorflow/core/lib/core/stringpiece.cc deleted file mode 100644 index 4c488066e4..0000000000 --- a/tensorflow/core/lib/core/stringpiece.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* 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. -==============================================================================*/ - -#include "tensorflow/core/lib/core/stringpiece.h" - -#include <algorithm> -#include <iostream> - -namespace tensorflow { - -std::ostream& operator<<(std::ostream& o, StringPiece piece) { - o.write(piece.data(), piece.size()); - return o; -} - -size_t StringPiece::find(char c, size_t pos) const { - if (pos >= size_) { - return npos; - } - const char* result = - reinterpret_cast<const char*>(memchr(data_ + pos, c, size_ - pos)); - return result != nullptr ? result - data_ : npos; -} - -// Search range is [0..pos] inclusive. If pos == npos, search everything. -size_t StringPiece::rfind(char c, size_t pos) const { - if (size_ == 0) return npos; - for (const char* p = data_ + std::min(pos, size_ - 1); p >= data_; p--) { - if (*p == c) { - return p - data_; - } - } - return npos; -} - -StringPiece StringPiece::substr(size_t pos, size_t n) const { - if (pos > size_) pos = size_; - if (n > size_ - pos) n = size_ - pos; - return StringPiece(data_ + pos, n); -} - -} // namespace tensorflow diff --git a/tensorflow/core/lib/core/stringpiece.h b/tensorflow/core/lib/core/stringpiece.h index 02dded42c1..e7b17c9b36 100644 --- a/tensorflow/core/lib/core/stringpiece.h +++ b/tensorflow/core/lib/core/stringpiece.h @@ -31,124 +31,13 @@ limitations under the License. #include <string.h> #include <iosfwd> #include <string> -#include <type_traits> +#include "absl/strings/string_view.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { -class StringPiece { - public: - typedef size_t size_type; - - // Create an empty slice. - StringPiece() : data_(nullptr), size_(0) {} - - // Create a slice that refers to d[0,n-1]. - StringPiece(const char* d, size_t n) : data_(d), size_(n) {} - - // Create a slice that refers to the contents of "s" - StringPiece(const string& s) : data_(s.data()), size_(s.size()) {} - - // Create a slice that refers to s[0,strlen(s)-1] - StringPiece(const char* s) : data_(s), size_(strlen(s)) {} - - // Return a pointer to the beginning of the referenced data - const char* data() const { return data_; } - - // Return the length (in bytes) of the referenced data - size_t size() const { return size_; } - - // Return true iff the length of the referenced data is zero - bool empty() const { return size_ == 0; } - - typedef const char* const_iterator; - typedef const char* iterator; - iterator begin() const { return data_; } - iterator end() const { return data_ + size_; } - - static const size_t npos = size_type(-1); - - // Return the ith byte in the referenced data. - // REQUIRES: n < size() - char operator[](size_t n) const { - assert(n < size()); - return data_[n]; - } - - // Drop the first "n" bytes from this slice. - void remove_prefix(size_t n) { - assert(n <= size()); - data_ += n; - size_ -= n; - } - - void remove_suffix(size_t n) { - assert(size_ >= n); - size_ -= n; - } - - size_t find(char c, size_t pos = 0) const; - size_t rfind(char c, size_t pos = npos) const; - - StringPiece substr(size_t pos, size_t n = npos) const; - - // Three-way comparison. Returns value: - // < 0 iff "*this" < "b", - // == 0 iff "*this" == "b", - // > 0 iff "*this" > "b" - int compare(StringPiece b) const; - - // Converts to various kinds of strings, including `std::basic_string`. - template <typename S> - explicit operator S() const { - static_assert( - std::is_same<char, typename S::value_type>::value, - "Type mismatch: S must be a string with character type char."); - static_assert( - std::is_same<std::char_traits<char>, typename S::traits_type>::value, - "Type mismatch: S must be a string with traits type " - "std::char_traits<char>."); - if (!data()) return {}; - return S(data(), size()); - } - - private: - const char* data_; - size_t size_; - - // Intentionally copyable -}; - -inline bool operator==(StringPiece x, StringPiece y) { - return ((x.size() == y.size()) && - (memcmp(x.data(), y.data(), x.size()) == 0)); -} - -inline bool operator!=(StringPiece x, StringPiece y) { return !(x == y); } - -inline bool operator<(StringPiece x, StringPiece y) { return x.compare(y) < 0; } -inline bool operator>(StringPiece x, StringPiece y) { return x.compare(y) > 0; } -inline bool operator<=(StringPiece x, StringPiece y) { - return x.compare(y) <= 0; -} -inline bool operator>=(StringPiece x, StringPiece y) { - return x.compare(y) >= 0; -} - -inline int StringPiece::compare(StringPiece b) const { - const size_t min_len = (size_ < b.size_) ? size_ : b.size_; - int r = memcmp(data_, b.data_, min_len); - if (r == 0) { - if (size_ < b.size_) - r = -1; - else if (size_ > b.size_) - r = +1; - } - return r; -} - -// allow StringPiece to be logged -extern std::ostream& operator<<(std::ostream& o, tensorflow::StringPiece piece); +// Deprecated: please use absl::string_view directly. +using StringPiece = absl::string_view; } // namespace tensorflow diff --git a/tensorflow/core/lib/strings/strcat.h b/tensorflow/core/lib/strings/strcat.h index 5ae3d220e3..2c036a3040 100644 --- a/tensorflow/core/lib/strings/strcat.h +++ b/tensorflow/core/lib/strings/strcat.h @@ -124,6 +124,9 @@ class AlphaNum { AlphaNum(const StringPiece &pc) : piece_(pc) {} // NOLINT(runtime/explicit) AlphaNum(const tensorflow::string &str) // NOLINT(runtime/explicit) : piece_(str) {} + template <typename A> + AlphaNum(const std::basic_string<char, std::char_traits<char>, A> &str) + : piece_(str) {} // NOLINT(runtime/explicit) StringPiece::size_type size() const { return piece_.size(); } const char *data() const { return piece_.data(); } diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index b9f26898c4..adac895a17 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -1365,12 +1365,13 @@ def transitive_hdrs(name, deps = [], **kwargs): # Create a header only library that includes all the headers exported by # the libraries in deps. -def cc_header_only_library(name, deps = [], includes = [], **kwargs): +def cc_header_only_library(name, deps = [], includes = [], extra_deps = [], **kwargs): _transitive_hdrs(name = name + "_gather", deps = deps) native.cc_library( name = name, hdrs = [":" + name + "_gather"], includes = includes, + deps = extra_deps, **kwargs ) |