From 3f23f4ddeabbdc0704444d84c158bd6c348a9f10 Mon Sep 17 00:00:00 2001 From: Peter Hawkins <phawkins@google.com> Date: Mon, 15 Oct 2018 11:07:58 -0700 Subject: [PATCH] Automated rollback of commit 6fa6bd045c98bdc89424a3425e15b5161586a9a7 PiperOrigin-RevId: 217173355 --- tensorflow/c/BUILD | 3 - tensorflow/c/c_api.cc | 8 +- tensorflow/c/c_api_function.cc | 5 +- tensorflow/c/c_api_test.cc | 3 +- tensorflow/c/eager/BUILD | 1 - tensorflow/c/eager/c_api.cc | 10 +- tensorflow/cc/BUILD | 4 - tensorflow/cc/framework/cc_op_gen.cc | 23 ++- tensorflow/cc/framework/cc_op_gen_main.cc | 4 +- tensorflow/cc/framework/cc_op_gen_test.cc | 5 +- tensorflow/cc/framework/scope.cc | 3 +- tensorflow/cc/saved_model/BUILD | 1 - tensorflow/cc/saved_model/loader.cc | 10 +- tensorflow/cc/tutorials/example_trainer.cc | 7 +- .../jit/encapsulate_xla_computations_pass.cc | 5 +- tensorflow/compiler/tf2xla/kernels/BUILD | 1 - .../tf2xla/kernels/conv_op_helpers.cc | 23 ++- .../compiler/tf2xla/kernels/conv_op_helpers.h | 9 +- .../xla/tools/hex_floats_to_packed_literal.cc | 4 +- .../android/asset_manager_filesystem.cc | 11 +- .../bigtable/kernels/bigtable_kernels.cc | 4 +- .../kernels/bigtable_range_helpers.cc | 7 +- .../bigtable/kernels/bigtable_range_helpers.h | 4 +- tensorflow/contrib/cloud/kernels/BUILD | 3 - .../cloud/kernels/bigquery_table_accessor.cc | 11 +- .../kernels/bigquery_table_accessor_test.cc | 3 +- .../contrib/cloud/kernels/gcs_config_ops.cc | 5 +- tensorflow/contrib/ffmpeg/BUILD | 2 - tensorflow/contrib/ffmpeg/decode_audio_op.cc | 8 +- tensorflow/contrib/ffmpeg/decode_video_op.cc | 3 +- tensorflow/contrib/ffmpeg/default/BUILD | 1 - .../contrib/ffmpeg/default/ffmpeg_lib.cc | 3 +- tensorflow/contrib/ffmpeg/ffmpeg_lib.h | 3 +- tensorflow/contrib/gdr/BUILD | 1 - tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc | 3 +- tensorflow/contrib/layers/kernels/BUILD | 1 - .../kernels/sparse_feature_cross_kernel.cc | 10 +- .../libsvm/kernels/decode_libsvm_op.cc | 7 +- tensorflow/contrib/lite/delegates/flex/BUILD | 2 - .../contrib/lite/delegates/flex/delegate.cc | 3 +- .../lite/delegates/flex/kernel_test.cc | 7 +- .../contrib/nccl/kernels/nccl_rewrite.cc | 7 +- .../contrib/saved_model/cc/saved_model/BUILD | 1 - .../cc/saved_model/signature_def_utils.cc | 4 +- tensorflow/contrib/session_bundle/BUILD | 4 - .../contrib/session_bundle/bundle_shim.cc | 4 +- .../contrib/session_bundle/session_bundle.cc | 32 ++--- .../contrib/session_bundle/session_bundle.h | 8 +- .../contrib/session_bundle/signature_test.cc | 4 +- tensorflow/contrib/tensorboard/db/BUILD | 1 - .../tensorboard/db/summary_db_writer.cc | 15 +- tensorflow/contrib/tpu/profiler/BUILD | 1 - .../contrib/tpu/profiler/dump_tpu_profile.cc | 8 +- tensorflow/contrib/verbs/BUILD | 1 - tensorflow/contrib/verbs/verbs_util.cc | 4 +- tensorflow/core/BUILD | 26 ---- .../common_runtime/constant_folding_test.cc | 3 +- tensorflow/core/common_runtime/copy_tensor.cc | 8 +- tensorflow/core/common_runtime/copy_tensor.h | 4 +- tensorflow/core/common_runtime/device_mgr.cc | 9 +- tensorflow/core/common_runtime/device_mgr.h | 8 +- tensorflow/core/common_runtime/device_set.cc | 4 +- .../core/common_runtime/direct_session.cc | 3 +- .../core/common_runtime/direct_session.h | 4 +- .../common_runtime/direct_session_test.cc | 5 +- tensorflow/core/common_runtime/eager/BUILD | 3 - .../core/common_runtime/eager/attr_builder.cc | 16 +-- .../core/common_runtime/eager/attr_builder.h | 17 ++- .../core/common_runtime/eager/context.cc | 3 +- .../core/common_runtime/eager/execute.cc | 5 +- tensorflow/core/common_runtime/function.cc | 3 +- tensorflow/core/common_runtime/function.h | 3 +- .../core/common_runtime/function_test.cc | 3 +- .../common_runtime/gpu/gpu_device_test.cc | 3 +- .../gpu/gpu_util_platform_specific.cc | 3 +- .../core/common_runtime/gpu_device_context.h | 7 +- .../common_runtime/lower_if_while_test.cc | 3 +- tensorflow/core/common_runtime/placer.cc | 17 ++- .../core/common_runtime/profile_handler.h | 7 +- .../core/common_runtime/shape_refiner.cc | 5 +- .../common_runtime/step_stats_collector.cc | 15 +- tensorflow/core/debug/BUILD | 2 - tensorflow/core/debug/debug_graph_utils.cc | 3 +- tensorflow/core/debug/debug_io_utils.cc | 3 +- tensorflow/core/distributed_runtime/BUILD | 4 - .../base_rendezvous_mgr.cc | 5 +- .../distributed_runtime/master_session.cc | 21 ++- .../core/distributed_runtime/remote_device.cc | 5 +- tensorflow/core/distributed_runtime/rpc/BUILD | 7 - .../rpc/grpc_master_service.cc | 7 +- .../rpc/grpc_remote_master.cc | 3 +- .../rpc/grpc_session_test.cc | 3 +- .../rpc/grpc_tensor_coding.cc | 5 +- .../rpc/grpc_tensorflow_server.cc | 3 +- .../rpc/grpc_testlib_server.cc | 3 +- .../rpc/rpc_rendezvous_mgr.cc | 3 +- .../core/distributed_runtime/tensor_coding.cc | 3 +- tensorflow/core/example/feature_util.h | 4 +- tensorflow/core/framework/attr_value_util.cc | 18 ++- tensorflow/core/framework/attr_value_util.h | 11 +- tensorflow/core/framework/dataset.cc | 3 +- tensorflow/core/framework/dataset.h | 30 ++-- tensorflow/core/framework/device_base.h | 7 +- tensorflow/core/framework/function.cc | 13 +- tensorflow/core/framework/function.h | 8 +- tensorflow/core/framework/function_testlib.cc | 4 +- tensorflow/core/framework/function_testlib.h | 4 +- tensorflow/core/framework/node_def_builder.cc | 37 +++-- tensorflow/core/framework/node_def_builder.h | 79 +++++----- .../core/framework/node_def_builder_test.cc | 4 +- tensorflow/core/framework/node_def_util.cc | 131 ++++++++--------- tensorflow/core/framework/node_def_util.h | 136 +++++++++--------- .../core/framework/node_def_util_test.cc | 4 +- tensorflow/core/framework/op.h | 13 +- tensorflow/core/framework/op_def_builder.cc | 74 +++++----- .../core/framework/op_def_builder_test.cc | 6 +- tensorflow/core/framework/op_def_util.cc | 16 +-- tensorflow/core/framework/op_def_util.h | 9 +- tensorflow/core/framework/op_gen_lib.cc | 49 ++++--- tensorflow/core/framework/op_gen_lib.h | 10 +- tensorflow/core/framework/op_kernel.cc | 57 ++++---- tensorflow/core/framework/op_kernel.h | 67 ++++----- tensorflow/core/framework/rendezvous.cc | 33 +++-- tensorflow/core/framework/rendezvous.h | 11 +- tensorflow/core/framework/resource_mgr.cc | 5 +- tensorflow/core/framework/resource_mgr.h | 3 +- tensorflow/core/framework/shape_inference.cc | 7 +- tensorflow/core/framework/shape_inference.h | 12 +- .../framework/shape_inference_testutil.cc | 7 +- .../core/framework/shape_inference_testutil.h | 4 +- tensorflow/core/framework/tensor.cc | 12 +- tensorflow/core/framework/tensor.h | 4 +- tensorflow/core/framework/tensor_util.cc | 14 +- tensorflow/core/framework/types.cc | 3 +- tensorflow/core/framework/types.h | 7 +- .../core/framework/variant_op_registry.cc | 10 +- .../core/framework/variant_op_registry.h | 23 ++- tensorflow/core/graph/costmodel.h | 4 +- tensorflow/core/graph/graph.cc | 7 +- tensorflow/core/graph/graph.h | 6 +- tensorflow/core/graph/graph_constructor.cc | 57 ++++---- .../core/graph/graph_constructor_test.cc | 3 +- tensorflow/core/graph/graph_def_builder.cc | 11 +- tensorflow/core/graph/graph_def_builder.h | 18 +-- tensorflow/core/graph/graph_partition.cc | 5 +- tensorflow/core/graph/node_builder.cc | 11 +- tensorflow/core/graph/node_builder.h | 21 ++- tensorflow/core/graph/quantize_training.cc | 9 +- tensorflow/core/graph/subgraph.cc | 4 +- tensorflow/core/graph/subgraph_test.cc | 3 +- tensorflow/core/graph/tensor_id.cc | 10 +- tensorflow/core/graph/tensor_id.h | 8 +- tensorflow/core/graph/while_context.cc | 3 +- tensorflow/core/graph/while_context.h | 3 +- tensorflow/core/grappler/BUILD | 2 - tensorflow/core/grappler/optimizers/BUILD | 4 - .../optimizers/arithmetic_optimizer.cc | 20 +-- .../grappler/optimizers/constant_folding.cc | 6 +- .../grappler/optimizers/constant_folding.h | 5 +- .../core/grappler/optimizers/data/BUILD | 10 -- .../optimizers/data/function_utils.cc | 31 ++-- .../grappler/optimizers/data/function_utils.h | 27 ++-- .../grappler/optimizers/data/fusion_utils.cc | 14 +- .../grappler/optimizers/data/fusion_utils.h | 14 +- .../optimizers/data/graph_test_utils.cc | 21 ++- .../optimizers/data/graph_test_utils.h | 22 ++- .../grappler/optimizers/data/graph_utils.cc | 22 ++- .../grappler/optimizers/data/graph_utils.h | 23 ++- .../optimizers/data/graph_utils_test.cc | 3 +- .../optimizers/data/latency_all_edges.cc | 5 +- .../data/map_and_batch_fusion_test.cc | 7 +- .../optimizers/data/map_vectorization_test.cc | 24 ++-- .../optimizers/data/noop_elimination_test.cc | 9 +- .../optimizers/data/vectorization_utils.cc | 3 +- .../data/vectorization_utils_test.cc | 5 +- .../optimizers/dependency_optimizer.cc | 6 +- .../optimizers/scoped_allocator_optimizer.cc | 3 +- .../optimizers/scoped_allocator_optimizer.h | 4 +- tensorflow/core/grappler/utils.cc | 8 +- tensorflow/core/grappler/utils.h | 30 ++-- tensorflow/core/grappler/utils/BUILD | 1 - tensorflow/core/grappler/utils/functions.cc | 5 +- tensorflow/core/grappler/utils_test.cc | 22 ++- tensorflow/core/kernels/BUILD | 17 +-- tensorflow/core/kernels/conv_grad_ops.cc | 22 +-- tensorflow/core/kernels/conv_grad_ops.h | 19 +-- tensorflow/core/kernels/data/BUILD | 4 - .../core/kernels/data/cache_dataset_ops.cc | 5 +- tensorflow/core/kernels/data/dataset_utils.cc | 5 +- tensorflow/core/kernels/data/dataset_utils.h | 5 +- .../core/kernels/data/experimental/BUILD | 1 - .../data/experimental/csv_dataset_op.cc | 37 +++-- .../data/experimental/indexed_dataset.h | 4 +- tensorflow/core/kernels/data/iterator_ops.cc | 23 ++- tensorflow/core/kernels/data/writer_ops.cc | 4 +- tensorflow/core/kernels/decode_bmp_op.cc | 3 +- tensorflow/core/kernels/decode_csv_op.cc | 5 +- tensorflow/core/kernels/decode_image_op.cc | 13 +- tensorflow/core/kernels/deep_conv2d.cc | 3 +- .../core/kernels/extract_jpeg_shape_op.cc | 3 +- tensorflow/core/kernels/gpu_utils.h | 3 +- tensorflow/core/kernels/hexagon/BUILD | 2 - .../kernels/hexagon/graph_transfer_utils.cc | 3 +- .../core/kernels/hexagon/graph_transferer.cc | 5 +- .../kernels/hexagon/graph_transferer_test.cc | 5 +- .../hexagon/hexagon_control_wrapper.cc | 3 +- .../kernels/immutable_constant_op_test.cc | 7 +- tensorflow/core/kernels/list_kernels.cc | 3 +- tensorflow/core/kernels/reduce_join_op.cc | 4 +- .../remote_fused_graph_execute_op_test.cc | 3 +- tensorflow/core/kernels/restore_v2_op_test.cc | 3 +- tensorflow/core/kernels/shape_op_test.cc | 3 +- tensorflow/core/kernels/sparse_cross_op.cc | 10 +- .../sparse_dense_binary_op_shared_test.cc | 3 +- tensorflow/core/kernels/sparse_reduce_op.cc | 5 +- .../core/kernels/spectrogram_test_utils.cc | 31 ++-- tensorflow/core/kernels/string_join_op.cc | 3 +- tensorflow/core/kernels/string_split_op.cc | 52 ++++--- tensorflow/core/kernels/string_strip_op.cc | 3 +- .../core/kernels/string_to_hash_bucket_op.h | 3 +- tensorflow/core/kernels/string_util.h | 5 +- tensorflow/core/kernels/substr_op.cc | 35 +++-- tensorflow/core/kernels/tensor_array_ops.cc | 5 +- tensorflow/core/kernels/word2vec_kernels.cc | 8 +- tensorflow/core/lib/core/coding.cc | 9 +- tensorflow/core/lib/core/coding.h | 6 +- tensorflow/core/lib/core/status.cc | 3 +- tensorflow/core/lib/core/status.h | 4 +- tensorflow/core/lib/core/stringpiece_test.cc | 17 +-- tensorflow/core/lib/db/BUILD | 2 - tensorflow/core/lib/db/sqlite.cc | 10 +- tensorflow/core/lib/db/sqlite.h | 26 ++-- tensorflow/core/lib/db/sqlite_test.cc | 4 +- tensorflow/core/lib/hash/hash.h | 8 +- tensorflow/core/lib/hash/hash_test.cc | 17 ++- tensorflow/core/lib/io/block.cc | 20 ++- tensorflow/core/lib/io/block_builder.cc | 12 +- tensorflow/core/lib/io/block_builder.h | 6 +- tensorflow/core/lib/io/format.cc | 17 ++- tensorflow/core/lib/io/format.h | 8 +- tensorflow/core/lib/io/inputbuffer.cc | 3 +- tensorflow/core/lib/io/inputbuffer_test.cc | 19 ++- tensorflow/core/lib/io/iterator.cc | 11 +- tensorflow/core/lib/io/iterator.h | 8 +- tensorflow/core/lib/io/path.cc | 61 ++++---- tensorflow/core/lib/io/path.h | 22 +-- tensorflow/core/lib/io/path_test.cc | 5 +- tensorflow/core/lib/io/proto_encode_helper.h | 6 +- tensorflow/core/lib/io/random_inputstream.cc | 7 +- tensorflow/core/lib/io/record_writer.cc | 7 +- tensorflow/core/lib/io/record_writer.h | 4 +- tensorflow/core/lib/io/recordio_test.cc | 11 +- .../core/lib/io/snappy/snappy_buffers_test.cc | 13 +- .../core/lib/io/snappy/snappy_inputbuffer.cc | 3 +- .../core/lib/io/snappy/snappy_outputbuffer.cc | 7 +- .../core/lib/io/snappy/snappy_outputbuffer.h | 5 +- tensorflow/core/lib/io/table.cc | 17 ++- tensorflow/core/lib/io/table.h | 12 +- tensorflow/core/lib/io/table_builder.cc | 22 ++- tensorflow/core/lib/io/table_builder.h | 5 +- tensorflow/core/lib/io/table_test.cc | 37 +++-- tensorflow/core/lib/io/two_level_iterator.cc | 13 +- tensorflow/core/lib/io/two_level_iterator.h | 4 +- tensorflow/core/lib/io/zlib_buffers_test.cc | 9 +- tensorflow/core/lib/io/zlib_outputbuffer.cc | 7 +- tensorflow/core/lib/io/zlib_outputbuffer.h | 5 +- tensorflow/core/lib/jpeg/jpeg_mem.h | 4 +- .../lib/monitoring/collection_registry.cc | 3 +- .../core/lib/monitoring/collection_registry.h | 4 +- tensorflow/core/lib/monitoring/metric_def.h | 11 +- tensorflow/core/lib/png/png_io.cc | 5 +- tensorflow/core/lib/png/png_io.h | 6 +- tensorflow/core/lib/strings/base64.cc | 8 +- tensorflow/core/lib/strings/base64.h | 8 +- tensorflow/core/lib/strings/numbers.cc | 23 ++- tensorflow/core/lib/strings/numbers.h | 32 ++--- tensorflow/core/lib/strings/numbers_test.cc | 27 ++-- tensorflow/core/lib/strings/ordered_code.cc | 15 +- tensorflow/core/lib/strings/ordered_code.h | 10 +- .../core/lib/strings/ordered_code_test.cc | 40 +++--- .../core/lib/strings/proto_text_util.cc | 5 +- tensorflow/core/lib/strings/proto_text_util.h | 6 +- tensorflow/core/lib/strings/scanner.cc | 6 +- tensorflow/core/lib/strings/scanner.h | 16 +-- tensorflow/core/lib/strings/scanner_test.cc | 31 ++-- tensorflow/core/lib/strings/str_util.cc | 57 ++++---- tensorflow/core/lib/strings/str_util.h | 74 +++++----- tensorflow/core/lib/strings/str_util_test.cc | 55 ++++--- tensorflow/core/lib/strings/strcat.cc | 16 +-- tensorflow/core/lib/strings/strcat.h | 16 +-- tensorflow/core/lib/strings/strcat_test.cc | 5 +- tensorflow/core/platform/cloud/BUILD | 12 -- .../cloud/compute_engine_zone_provider.cc | 3 +- .../core/platform/cloud/curl_http_request.cc | 20 ++- .../core/platform/cloud/curl_http_request.h | 6 +- .../platform/cloud/curl_http_request_test.cc | 5 +- .../core/platform/cloud/gcs_file_system.cc | 49 ++++--- .../platform/cloud/gcs_file_system_test.cc | 32 ++--- .../platform/cloud/google_auth_provider.cc | 5 +- .../cloud/google_auth_provider_test.cc | 8 +- .../core/platform/cloud/http_request_fake.h | 4 +- .../core/platform/cloud/oauth_client.cc | 30 ++-- tensorflow/core/platform/cloud/oauth_client.h | 14 +- .../core/platform/cloud/oauth_client_test.cc | 3 +- .../platform/cloud/retrying_file_system.h | 5 +- .../cloud/retrying_file_system_test.cc | 13 +- .../core/platform/default/device_tracer.cc | 6 +- .../core/platform/default/fingerprint.h | 6 +- .../platform/default/human_readable_json.cc | 19 +-- .../core/platform/default/string_coding.h | 3 +- .../core/platform/default/test_benchmark.cc | 3 +- tensorflow/core/platform/env.cc | 13 +- tensorflow/core/platform/env.h | 4 +- tensorflow/core/platform/env_test.cc | 10 +- tensorflow/core/platform/file_system.cc | 7 +- tensorflow/core/platform/file_system.h | 6 +- tensorflow/core/platform/file_system_test.cc | 7 +- tensorflow/core/platform/fingerprint.h | 6 +- tensorflow/core/platform/hadoop/BUILD | 2 - .../platform/hadoop/hadoop_file_system.cc | 15 +- .../core/platform/hadoop/hadoop_file_system.h | 3 +- .../hadoop/hadoop_file_system_test.cc | 7 +- .../core/platform/posix/posix_file_system.cc | 9 +- .../core/platform/posix/posix_file_system.h | 3 +- tensorflow/core/platform/s3/BUILD | 1 - tensorflow/core/platform/s3/s3_file_system.cc | 16 +-- tensorflow/core/platform/tensor_coding.cc | 7 +- tensorflow/core/platform/tensor_coding.h | 5 +- tensorflow/core/platform/tracing.cc | 6 +- tensorflow/core/platform/tracing.h | 25 ++-- .../platform/windows/windows_file_system.cc | 9 +- .../platform/windows/windows_file_system.h | 3 +- tensorflow/core/profiler/internal/BUILD | 1 - .../core/profiler/internal/tfprof_utils.cc | 5 +- tensorflow/core/util/command_line_flags.cc | 12 +- tensorflow/core/util/device_name_utils.cc | 28 ++-- tensorflow/core/util/device_name_utils.h | 19 ++- .../core/util/device_name_utils_test.cc | 5 +- tensorflow/core/util/env_var.cc | 9 +- tensorflow/core/util/env_var.h | 10 +- tensorflow/core/util/events_writer.cc | 3 +- tensorflow/core/util/events_writer.h | 3 +- .../core/util/example_proto_fast_parsing.cc | 60 ++++---- tensorflow/core/util/memmapped_file_system.cc | 9 +- .../core/util/memmapped_file_system_test.cc | 5 +- .../core/util/memmapped_file_system_writer.cc | 5 +- tensorflow/core/util/mirror_pad_mode.cc | 3 +- tensorflow/core/util/mirror_pad_mode.h | 3 +- tensorflow/core/util/padding.cc | 3 +- tensorflow/core/util/padding.h | 3 +- tensorflow/core/util/reporter_test.cc | 3 +- .../core/util/saved_tensor_slice_util.cc | 3 +- tensorflow/core/util/semver_test.cc | 12 +- tensorflow/core/util/tensor_bundle/BUILD | 7 +- tensorflow/core/util/tensor_bundle/naming.cc | 6 +- tensorflow/core/util/tensor_bundle/naming.h | 6 +- .../core/util/tensor_bundle/tensor_bundle.cc | 46 +++--- .../core/util/tensor_bundle/tensor_bundle.h | 37 +++-- .../util/tensor_bundle/tensor_bundle_test.cc | 9 +- tensorflow/core/util/tensor_slice_reader.cc | 3 +- tensorflow/core/util/tensor_slice_writer.cc | 3 +- tensorflow/core/util/tensor_slice_writer.h | 4 +- tensorflow/core/util/util.cc | 17 ++- tensorflow/core/util/util.h | 6 +- tensorflow/examples/label_image/BUILD | 2 +- tensorflow/examples/label_image/main.cc | 4 +- tensorflow/java/BUILD | 1 - tensorflow/java/src/gen/cc/op_specs.cc | 3 +- tensorflow/java/src/gen/cc/source_writer.cc | 5 +- tensorflow/java/src/gen/cc/source_writer.h | 12 +- tensorflow/js/BUILD | 1 - tensorflow/js/ops/ts_op_gen_test.cc | 5 +- tensorflow/python/BUILD | 6 - tensorflow/python/eager/pywrap_tfe_src.cc | 13 +- tensorflow/python/framework/python_op_gen.cc | 5 +- .../framework/python_op_gen_internal.cc | 17 ++- .../python/framework/python_op_gen_main.cc | 7 +- .../python/framework/test_file_system.cc | 5 +- tensorflow/python/lib/core/py_func.cc | 5 +- tensorflow/python/lib/core/strings.i | 26 ++-- tensorflow/python/lib/io/py_record_writer.cc | 4 +- tensorflow/python/lib/io/py_record_writer.h | 4 +- tensorflow/python/util/util.cc | 7 +- tensorflow/tools/graph_transforms/BUILD | 4 - .../graph_transforms/fold_constants_lib.cc | 11 +- .../graph_transforms/fold_constants_test.cc | 3 +- .../freeze_requantization_ranges.cc | 3 +- .../graph_transforms/sparsify_gather_test.cc | 5 +- .../tools/graph_transforms/transform_graph.cc | 11 +- .../tools/graph_transforms/transform_utils.cc | 7 +- .../gen_proto_text_functions_lib.cc | 4 +- 391 files changed, 1914 insertions(+), 2459 deletions(-) diff --git a/tensorflow/c/BUILD b/tensorflow/c/BUILD index 762afaee875..56f5e6767ac 100644 --- a/tensorflow/c/BUILD +++ b/tensorflow/c/BUILD @@ -78,12 +78,10 @@ tf_cuda_library( deps = select({ "//tensorflow:android": [ ":c_api_internal", - "@com_google_absl//absl/strings", "//tensorflow/core:android_tensorflow_lib_lite", ], "//conditions:default": [ ":c_api_internal", - "@com_google_absl//absl/strings", "//tensorflow/cc/saved_model:loader", "//tensorflow/cc:gradients", "//tensorflow/cc:ops", @@ -230,7 +228,6 @@ tf_cuda_cc_test( "//tensorflow/core/kernels:array", "//tensorflow/core/kernels:control_flow_ops", "//tensorflow/core/kernels:math", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc index 7cd7e198c4a..1726db12fa6 100644 --- a/tensorflow/c/c_api.cc +++ b/tensorflow/c/c_api.cc @@ -19,7 +19,6 @@ limitations under the License. #include <limits> #include <memory> #include <vector> -#include "absl/strings/string_view.h" #ifndef __ANDROID__ #include "tensorflow/cc/framework/gradients.h" @@ -52,6 +51,7 @@ limitations under the License. #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -120,7 +120,7 @@ void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg) { s->status = Status::OK(); return; } - s->status = Status(static_cast<Code>(code), absl::string_view(msg)); + s->status = Status(static_cast<Code>(code), tensorflow::StringPiece(msg)); } TF_Code TF_GetCode(const TF_Status* s) { @@ -1160,7 +1160,7 @@ void TF_ColocateWith(TF_OperationDescription* desc, TF_Operation* op) { void TF_SetAttrString(TF_OperationDescription* desc, const char* attr_name, const void* value, size_t length) { - absl::string_view s(static_cast<const char*>(value), length); + tensorflow::StringPiece s(static_cast<const char*>(value), length); desc->node_builder.Attr(attr_name, s); } @@ -1174,7 +1174,7 @@ void TF_SetAttrStringList(TF_OperationDescription* desc, const char* attr_name, lengths[i]); } } else { - std::vector<absl::string_view> v; + std::vector<tensorflow::StringPiece> v; v.reserve(num_values); for (int i = 0; i < num_values; ++i) { v.emplace_back(static_cast<const char*>(values[i]), lengths[i]); diff --git a/tensorflow/c/c_api_function.cc b/tensorflow/c/c_api_function.cc index 604e12eef6a..f68f8a3e90a 100644 --- a/tensorflow/c/c_api_function.cc +++ b/tensorflow/c/c_api_function.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/c/c_api_internal.h" #include <algorithm> @@ -325,7 +324,7 @@ Status GraphToFunctionDef(const Graph& fn_body, const string& fn_name, TF_RETURN_IF_ERROR( NameRangesForNode(*node, node->op_def(), nullptr, &output_ranges)); for (const auto& output : output_ranges) { - const absl::string_view& output_name = output.first; + const StringPiece& output_name = output.first; int index_start = output.second.first; int index_end = output.second.second; for (int i = index_start; i < index_end; ++i) { @@ -365,7 +364,7 @@ Status GraphToFunctionDef(const Graph& fn_body, const string& fn_name, const uint64 hash = FunctionDefHash(*fdef); string encoded; TF_RETURN_IF_ERROR(Base64Encode( - absl::string_view(reinterpret_cast<const char*>(&hash), sizeof(hash)), + StringPiece(reinterpret_cast<const char*>(&hash), sizeof(hash)), &encoded)); // Besides letters and digits our Base64 encoding uses '_' and '-'. // Dash is invalid in operation names and multiple underscores in random diff --git a/tensorflow/c/c_api_test.cc b/tensorflow/c/c_api_test.cc index a8ecd7b7260..c4746b4990b 100644 --- a/tensorflow/c/c_api_test.cc +++ b/tensorflow/c/c_api_test.cc @@ -21,7 +21,6 @@ limitations under the License. #include <memory> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/c/c_test_util.h" #include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/cc/saved_model/tag_constants.h" @@ -56,7 +55,7 @@ Status TF_TensorToTensor(const TF_Tensor* src, Tensor* dst); namespace { -static void ExpectHasSubstr(absl::string_view s, absl::string_view expected) { +static void ExpectHasSubstr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/c/eager/BUILD b/tensorflow/c/eager/BUILD index 8e38a4675b4..3ee31a6a7ac 100644 --- a/tensorflow/c/eager/BUILD +++ b/tensorflow/c/eager/BUILD @@ -50,7 +50,6 @@ tf_cuda_library( ], "//conditions:default": [], }) + [ - "@com_google_absl//absl/strings", "//tensorflow/core/common_runtime/eager:eager_operation", "//tensorflow/core/distributed_runtime/eager:eager_client", "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_client", diff --git a/tensorflow/c/eager/c_api.cc b/tensorflow/c/eager/c_api.cc index f4215ab77ac..3554ec0bf32 100755 --- a/tensorflow/c/eager/c_api.cc +++ b/tensorflow/c/eager/c_api.cc @@ -21,7 +21,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/c/c_api.h" #include "tensorflow/c/c_api_internal.h" #include "tensorflow/c/eager/c_api_internal.h" @@ -47,6 +46,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/refcount.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/cleanup.h" #include "tensorflow/core/lib/gtl/flatmap.h" #include "tensorflow/core/lib/gtl/map_util.h" @@ -526,7 +526,8 @@ TF_AttrType TFE_OpNameGetAttrType(TFE_Context* ctx, void TFE_OpSetAttrString(TFE_Op* op, const char* attr_name, const void* value, size_t length) { op->operation.MutableAttrs()->Set( - attr_name, absl::string_view(static_cast<const char*>(value), length)); + attr_name, + tensorflow::StringPiece(static_cast<const char*>(value), length)); } void TFE_OpSetAttrInt(TFE_Op* op, const char* attr_name, int64_t value) { @@ -595,9 +596,10 @@ void TFE_OpSetAttrTensor(TFE_Op* op, const char* attr_name, TF_Tensor* tensor, void TFE_OpSetAttrStringList(TFE_Op* op, const char* attr_name, const void* const* values, const size_t* lengths, int num_values) { - std::vector<absl::string_view> v(num_values); + std::vector<tensorflow::StringPiece> v(num_values); for (int i = 0; i < num_values; ++i) { - v[i] = absl::string_view(static_cast<const char*>(values[i]), lengths[i]); + v[i] = tensorflow::StringPiece(static_cast<const char*>(values[i]), + lengths[i]); } op->operation.MutableAttrs()->Set(attr_name, v); } diff --git a/tensorflow/cc/BUILD b/tensorflow/cc/BUILD index e3859014cf9..c18b07603ae 100644 --- a/tensorflow/cc/BUILD +++ b/tensorflow/cc/BUILD @@ -170,7 +170,6 @@ cc_library_with_android_deps( "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -604,7 +603,6 @@ cc_library_with_android_deps( "//tensorflow/core:op_gen_lib", "//tensorflow/core:proto_text", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -624,7 +622,6 @@ tf_cc_test( "//tensorflow/core:protos_all_cc", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) @@ -686,7 +683,6 @@ tf_cc_binary( "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", "//tensorflow/core:tensorflow", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/cc/framework/cc_op_gen.cc b/tensorflow/cc/framework/cc_op_gen.cc index aeec0580307..39593370d1c 100644 --- a/tensorflow/cc/framework/cc_op_gen.cc +++ b/tensorflow/cc/framework/cc_op_gen.cc @@ -17,7 +17,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/cc/framework/cc_op_gen.h" #include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/attr_value.pb.h" @@ -108,7 +107,7 @@ string ToTitle(const string& name) { // ABC /// ABC // /// // DEF /// DEF -string MakeComment(absl::string_view text, absl::string_view indent) { +string MakeComment(StringPiece text, StringPiece indent) { string ret; while (!text.empty()) { int last_non_space = -1; @@ -303,9 +302,9 @@ string ToCamelCase(const string& str) { // attr_type when defining an object of that type. The bool is a flag to // indicate whether to treat the type as const when accepting the C++ type as an // argument to a function. -std::pair<const char*, bool> AttrTypeName(absl::string_view attr_type) { +std::pair<const char*, bool> AttrTypeName(StringPiece attr_type) { static const auto* attr_type_map = - new std::unordered_map<absl::string_view, std::pair<const char*, bool>, + new std::unordered_map<StringPiece, std::pair<const char*, bool>, StringPieceHasher>{ {"string", {"StringPiece", false}}, {"list(string)", {"gtl::ArraySlice<string>", true}}, @@ -332,9 +331,9 @@ std::pair<const char*, bool> AttrTypeName(absl::string_view attr_type) { return entry->second; } -const char* ListElementTypeName(absl::string_view attr_type) { +const char* ListElementTypeName(StringPiece attr_type) { static const auto* attr_list_type_map = - new std::unordered_map<absl::string_view, const char*, StringPieceHasher>{ + new std::unordered_map<StringPiece, const char*, StringPieceHasher>{ {"list(string)", "string"}, {"list(int)", "int"}, {"list(float)", "float"}, @@ -352,8 +351,8 @@ const char* ListElementTypeName(absl::string_view attr_type) { return entry->second; } -bool IsCPPKeyword(absl::string_view name) { - static const std::unordered_set<absl::string_view, StringPieceHasher> +bool IsCPPKeyword(StringPiece name) { + static const std::unordered_set<StringPiece, StringPieceHasher> // Keywords obtained from http://en.cppreference.com/w/cpp/keyword kCPPReserved{ "alignas", @@ -463,7 +462,7 @@ bool IsCPPKeyword(absl::string_view name) { return kCPPReserved.count(name) > 0; } -string AvoidCPPKeywords(absl::string_view name) { +string AvoidCPPKeywords(StringPiece name) { if (IsCPPKeyword(name)) { return strings::StrCat(name, "_"); } @@ -517,7 +516,7 @@ struct OpInfo { explicit OpInfo(const OpDef& graph_op_def, const ApiDef& api_def, const std::vector<string>& aliases); string GetOpAttrStruct() const; - string GetConstructorDecl(absl::string_view op_name_prefix, + string GetConstructorDecl(StringPiece op_name_prefix, bool include_attr) const; void WriteClassDecl(WritableFile* h) const; void GetOutput(string* out) const; @@ -575,7 +574,7 @@ OpInfo::OpInfo(const OpDef& graph_op_def, const ApiDef& api_def, arg_names.push_back(AvoidCPPKeywords(api_def_arg.rename_to())); // TODO(keveman): Include input type information. - absl::string_view description = api_def_arg.description(); + StringPiece description = api_def_arg.description(); if (!description.empty()) { ConsumeEquals(&description); strings::StrAppend(&comment, "* ", @@ -769,7 +768,7 @@ string OpInfo::GetOpAttrStruct() const { return struct_decl; } -string OpInfo::GetConstructorDecl(absl::string_view op_name_prefix, +string OpInfo::GetConstructorDecl(StringPiece op_name_prefix, bool include_attr) const { const string prefix = strings::StrCat(op_name_prefix, op_name, "("); string c_decl; diff --git a/tensorflow/cc/framework/cc_op_gen_main.cc b/tensorflow/cc/framework/cc_op_gen_main.cc index a9759fcee93..3157792e15a 100644 --- a/tensorflow/cc/framework/cc_op_gen_main.cc +++ b/tensorflow/cc/framework/cc_op_gen_main.cc @@ -13,11 +13,11 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/cc/framework/cc_op_gen.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_gen_lib.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) { exit(1); } - bool include_internal = absl::string_view("1") == argv[3]; + bool include_internal = tensorflow::StringPiece("1") == argv[3]; std::vector<tensorflow::string> api_def_dirs = tensorflow::str_util::Split( argv[4], ",", tensorflow::str_util::SkipEmpty()); tensorflow::PrintAllCCOps(argv[1], argv[2], include_internal, api_def_dirs); diff --git a/tensorflow/cc/framework/cc_op_gen_test.cc b/tensorflow/cc/framework/cc_op_gen_test.cc index 327e3c6bacc..5d9dfd95a55 100644 --- a/tensorflow/cc/framework/cc_op_gen_test.cc +++ b/tensorflow/cc/framework/cc_op_gen_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/cc/framework/cc_op_gen.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_gen_lib.h" #include "tensorflow/core/lib/core/status_test_util.h" @@ -62,12 +61,12 @@ op { } )"; -void ExpectHasSubstr(absl::string_view s, absl::string_view expected) { +void ExpectHasSubstr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } -void ExpectDoesNotHaveSubstr(absl::string_view s, absl::string_view expected) { +void ExpectDoesNotHaveSubstr(StringPiece s, StringPiece expected) { EXPECT_FALSE(str_util::StrContains(s, expected)) << "'" << s << "' contains '" << expected << "'"; } diff --git a/tensorflow/cc/framework/scope.cc b/tensorflow/cc/framework/scope.cc index 3bc2e5fa2b8..6abc9e268e3 100644 --- a/tensorflow/cc/framework/scope.cc +++ b/tensorflow/cc/framework/scope.cc @@ -16,7 +16,6 @@ limitations under the License. #include <algorithm> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/cc/framework/scope_internal.h" #include "tensorflow/core/common_runtime/shape_refiner.h" #include "tensorflow/core/framework/node_def_util.h" @@ -248,7 +247,7 @@ std::unordered_set<string> Scope::Impl::GetColocationConstraints( std::vector<string> node_constraints; if (GetNodeAttr(attrs, kColocationAttrName, &node_constraints).ok()) { for (const string& entry : node_constraints) { - absl::string_view s(entry); + StringPiece s(entry); if (str_util::ConsumePrefix(&s, kColocationGroupPrefix)) { current_constraints.emplace(s); } diff --git a/tensorflow/cc/saved_model/BUILD b/tensorflow/cc/saved_model/BUILD index 43106c82c9d..3d3895c8fa8 100644 --- a/tensorflow/cc/saved_model/BUILD +++ b/tensorflow/cc/saved_model/BUILD @@ -95,7 +95,6 @@ cc_library( deps = [ ":constants", ":reader", - "@com_google_absl//absl/strings", ] + if_not_mobile([ "//tensorflow/core:core_cpu", "//tensorflow/core:framework", diff --git a/tensorflow/cc/saved_model/loader.cc b/tensorflow/cc/saved_model/loader.cc index e33c584ed77..c6abe2f41b9 100644 --- a/tensorflow/cc/saved_model/loader.cc +++ b/tensorflow/cc/saved_model/loader.cc @@ -17,7 +17,6 @@ limitations under the License. #include <unordered_set> -#include "absl/strings/string_view.h" #include "tensorflow/cc/saved_model/constants.h" #include "tensorflow/cc/saved_model/reader.h" #include "tensorflow/core/lib/io/path.h" @@ -61,7 +60,7 @@ Tensor CreateStringTensor(const string& value) { return tensor; } -void AddAssetsTensorsToInputs(const absl::string_view export_dir, +void AddAssetsTensorsToInputs(const StringPiece export_dir, const std::vector<AssetFileDef>& asset_file_defs, std::vector<std::pair<string, Tensor>>* inputs) { if (asset_file_defs.empty()) { @@ -148,8 +147,7 @@ Status RunMainOp(const RunOptions& run_options, const string& export_dir, std::vector<std::pair<string, Tensor>> inputs; AddAssetsTensorsToInputs(export_dir, asset_file_defs, &inputs); RunMetadata run_metadata; - const absl::string_view main_op_name = - main_op_it->second.node_list().value(0); + const StringPiece main_op_name = main_op_it->second.node_list().value(0); return RunOnce(run_options, inputs, {}, {string(main_op_name)}, nullptr /* outputs */, &run_metadata, session); } @@ -157,8 +155,8 @@ Status RunMainOp(const RunOptions& run_options, const string& export_dir, } Status RunRestore(const RunOptions& run_options, const string& export_dir, - const absl::string_view restore_op_name, - const absl::string_view variable_filename_const_op_name, + const StringPiece restore_op_name, + const StringPiece variable_filename_const_op_name, const std::vector<AssetFileDef>& asset_file_defs, Session* session) { LOG(INFO) << "Restoring SavedModel bundle."; diff --git a/tensorflow/cc/tutorials/example_trainer.cc b/tensorflow/cc/tutorials/example_trainer.cc index 1a76a1a3a23..5dbc4f5f6aa 100644 --- a/tensorflow/cc/tutorials/example_trainer.cc +++ b/tensorflow/cc/tutorials/example_trainer.cc @@ -18,7 +18,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/standard_ops.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/tensor.h" @@ -166,7 +165,8 @@ void ConcurrentSessions(const Options& opts) { namespace { -bool ParseInt32Flag(absl::string_view arg, absl::string_view flag, int32* dst) { +bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, + int32* dst) { if (tensorflow::str_util::ConsumePrefix(&arg, flag) && tensorflow::str_util::ConsumePrefix(&arg, "=")) { char extra; @@ -176,7 +176,8 @@ bool ParseInt32Flag(absl::string_view arg, absl::string_view flag, int32* dst) { return false; } -bool ParseBoolFlag(absl::string_view arg, absl::string_view flag, bool* dst) { +bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, + bool* dst) { if (tensorflow::str_util::ConsumePrefix(&arg, flag)) { if (arg.empty()) { *dst = true; diff --git a/tensorflow/compiler/jit/encapsulate_xla_computations_pass.cc b/tensorflow/compiler/jit/encapsulate_xla_computations_pass.cc index c2d58552e78..2ce6fa73fc4 100644 --- a/tensorflow/compiler/jit/encapsulate_xla_computations_pass.cc +++ b/tensorflow/compiler/jit/encapsulate_xla_computations_pass.cc @@ -18,7 +18,6 @@ limitations under the License. #include "absl/container/flat_hash_set.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "tensorflow/compiler/jit/encapsulate_subgraphs_pass.h" #include "tensorflow/compiler/tf2xla/dump_graph.h" #include "tensorflow/compiler/xla/status_macros.h" @@ -124,8 +123,8 @@ Status RewriteSubgraph(const std::vector<OutputTensor>& arg_source_tensors, bool a_is_resource = (a->output_type(0) == DT_RESOURCE); bool b_is_resource = (b->output_type(0) == DT_RESOURCE); // Uses the name as a tiebreaker so the output is deterministic. - absl::string_view a_name(a->name()); - absl::string_view b_name(b->name()); + StringPiece a_name(a->name()); + StringPiece b_name(b->name()); return std::tie(a_is_resource, a_name) < std::tie(b_is_resource, b_name); }); diff --git a/tensorflow/compiler/tf2xla/kernels/BUILD b/tensorflow/compiler/tf2xla/kernels/BUILD index 4a7318359df..224e5ea123b 100644 --- a/tensorflow/compiler/tf2xla/kernels/BUILD +++ b/tensorflow/compiler/tf2xla/kernels/BUILD @@ -194,7 +194,6 @@ cc_library( "//tensorflow/core/kernels:bounds_check", "//tensorflow/core/kernels:conv_ops", "//tensorflow/core/kernels:ops_util", - "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", ], ) diff --git a/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.cc b/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.cc index 4be61e23b21..c9a1be49406 100644 --- a/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.cc +++ b/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.cc @@ -16,7 +16,6 @@ limitations under the License. // XLA-specific Ops for 2D convolution. #include "tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h" -#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "tensorflow/compiler/tf2xla/shape_util.h" #include "tensorflow/compiler/tf2xla/type_util.h" @@ -199,11 +198,10 @@ Status CheckConvAttrs(const ConvOpAttrs& attrs) { // Wrapper around ConvBackpropComputeDimensions that converts from XLA shapes // to TensorShapes. Status ConvBackpropComputeDimensionsV2XlaShapes( - absl::string_view label, int num_spatial_dims, - const xla::Shape& input_shape, const xla::Shape& filter_shape, - const xla::Shape& out_backprop_shape, absl::Span<const int32> dilations, - const std::vector<int32>& strides, Padding padding, - TensorFormat data_format, ConvBackpropDimensions* dims) { + StringPiece label, int num_spatial_dims, const xla::Shape& input_shape, + const xla::Shape& filter_shape, const xla::Shape& out_backprop_shape, + absl::Span<const int32> dilations, const std::vector<int32>& strides, + Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims) { TensorShape input_tensor_shape, filter_tensor_shape, out_backprop_tensor_shape; TF_RETURN_IF_ERROR(XLAShapeToTensorShape(input_shape, &input_tensor_shape)); @@ -237,9 +235,10 @@ xla::StatusOr<ConvOpAttrs> ConvOpAttrs::Create(int num_spatial_dims, return attrs; } -xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp( - absl::string_view /*type_string*/, xla::XlaOp conv_input, xla::XlaOp filter, - const ConvOpAttrs& attrs) { +xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(StringPiece /*type_string*/, + xla::XlaOp conv_input, + xla::XlaOp filter, + const ConvOpAttrs& attrs) { TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); auto* builder = conv_input.builder(); @@ -310,8 +309,8 @@ xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp( } xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp( - absl::string_view type_string, const xla::Shape& input_shape, - xla::XlaOp filter, xla::XlaOp out_backprop, const ConvOpAttrs& attrs) { + StringPiece type_string, const xla::Shape& input_shape, xla::XlaOp filter, + xla::XlaOp out_backprop, const ConvOpAttrs& attrs) { TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); int num_dims = attrs.num_spatial_dims + 2; @@ -381,7 +380,7 @@ xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp( } xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp( - absl::string_view type_string, xla::XlaOp activations, + StringPiece type_string, xla::XlaOp activations, const xla::Shape& filter_shape, xla::XlaOp gradients, const ConvOpAttrs& attrs) { TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); diff --git a/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h b/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h index bcd846dd022..6e1b70a4785 100644 --- a/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h +++ b/tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h @@ -18,7 +18,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/compiler/xla/client/xla_builder.h" #include "tensorflow/compiler/xla/statusor.h" #include "tensorflow/core/framework/op_kernel.h" @@ -53,15 +52,15 @@ struct ConvOpAttrs { // Creates a new XLA forward or backward convolution with the given inputs and // attributes. -xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(absl::string_view type_string, +xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(StringPiece type_string, xla::XlaOp conv_input, xla::XlaOp filter, const ConvOpAttrs& attrs); xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp( - absl::string_view type_string, const xla::Shape& input_shape, - xla::XlaOp filter, xla::XlaOp out_backprop, const ConvOpAttrs& attrs); + StringPiece type_string, const xla::Shape& input_shape, xla::XlaOp filter, + xla::XlaOp out_backprop, const ConvOpAttrs& attrs); xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp( - absl::string_view type_string, xla::XlaOp activations, + StringPiece type_string, xla::XlaOp activations, const xla::Shape& filter_shape, xla::XlaOp gradients, const ConvOpAttrs& attrs); diff --git a/tensorflow/compiler/xla/tools/hex_floats_to_packed_literal.cc b/tensorflow/compiler/xla/tools/hex_floats_to_packed_literal.cc index 23ce1d235b9..0c3ec5934e5 100644 --- a/tensorflow/compiler/xla/tools/hex_floats_to_packed_literal.cc +++ b/tensorflow/compiler/xla/tools/hex_floats_to_packed_literal.cc @@ -67,8 +67,8 @@ int main(int argc, char** argv) { floats.push_back(value); } - absl::string_view content(absl::bit_cast<const char*>(floats.data()), - floats.size() * sizeof(float)); + tensorflow::StringPiece content(absl::bit_cast<const char*>(floats.data()), + floats.size() * sizeof(float)); TF_CHECK_OK(tensorflow::WriteStringToFile(tensorflow::Env::Default(), output_file, content)); return 0; diff --git a/tensorflow/contrib/android/asset_manager_filesystem.cc b/tensorflow/contrib/android/asset_manager_filesystem.cc index ed1f88b160d..d14b2126a0f 100644 --- a/tensorflow/contrib/android/asset_manager_filesystem.cc +++ b/tensorflow/contrib/android/asset_manager_filesystem.cc @@ -17,7 +17,6 @@ limitations under the License. #include <unistd.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/file_system_helper.h" @@ -27,7 +26,7 @@ namespace { string RemoveSuffix(const string& name, const string& suffix) { string output(name); - absl::string_view piece(output); + StringPiece piece(output); str_util::ConsumeSuffix(&piece, suffix); return string(piece); } @@ -88,7 +87,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile { : asset_manager_(asset_manager), file_name_(name) {} ~RandomAccessFileFromAsset() override = default; - Status Read(uint64 offset, size_t to_read, absl::string_view* result, + Status Read(uint64 offset, size_t to_read, StringPiece* result, char* scratch) const override { auto asset = ScopedAsset(AAssetManager_open( asset_manager_, file_name_.c_str(), AASSET_MODE_RANDOM)); @@ -99,7 +98,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile { off64_t new_offset = AAsset_seek64(asset.get(), offset, SEEK_SET); off64_t length = AAsset_getLength64(asset.get()); if (new_offset < 0) { - *result = absl::string_view(scratch, 0); + *result = StringPiece(scratch, 0); return errors::OutOfRange("Read after file end."); } const off64_t region_left = @@ -108,7 +107,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile { if (read < 0) { return errors::Internal("Error reading from asset."); } - *result = absl::string_view(scratch, region_left); + *result = StringPiece(scratch, region_left); return (region_left == to_read) ? Status::OK() : errors::OutOfRange("Read less bytes than requested."); @@ -230,7 +229,7 @@ string AssetManagerFileSystem::NormalizeDirectoryPath(const string& fname) { } string AssetManagerFileSystem::RemoveAssetPrefix(const string& name) { - absl::string_view piece(name); + StringPiece piece(name); str_util::ConsumePrefix(&piece, prefix_); return string(piece); } diff --git a/tensorflow/contrib/bigtable/kernels/bigtable_kernels.cc b/tensorflow/contrib/bigtable/kernels/bigtable_kernels.cc index ce77a4c01c4..6138d791260 100644 --- a/tensorflow/contrib/bigtable/kernels/bigtable_kernels.cc +++ b/tensorflow/contrib/bigtable/kernels/bigtable_kernels.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/contrib/bigtable/kernels/bigtable_lib.h" #include "tensorflow/core/framework/op_kernel.h" @@ -343,8 +342,7 @@ class ToBigtableOp : public AsyncOpKernel { template <typename T> Status ParseScalarArgument(OpKernelContext* ctx, - const absl::string_view& argument_name, - T* output) { + const StringPiece& argument_name, T* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); if (!TensorShapeUtils::IsScalar(argument_t->shape())) { diff --git a/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.cc b/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.cc index 1b4be1cbcd6..51965f62144 100644 --- a/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.cc +++ b/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { @@ -56,11 +55,11 @@ const string& MultiModeKeyRange::begin_key() const { return begin_; } const string& MultiModeKeyRange::end_key() const { return end_; } -bool MultiModeKeyRange::contains_key(absl::string_view key) const { - if (absl::string_view(begin_) > key) { +bool MultiModeKeyRange::contains_key(StringPiece key) const { + if (StringPiece(begin_) > key) { return false; } - if (absl::string_view(end_) <= key && !end_.empty()) { + if (StringPiece(end_) <= key && !end_.empty()) { return false; } return true; diff --git a/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h b/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h index d55c6d8f6a0..44c628e366c 100644 --- a/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h +++ b/tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h @@ -18,7 +18,7 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -52,7 +52,7 @@ class MultiModeKeyRange { // The first invalid key after the valid range. const string& end_key() const; // Returns true if the provided key is a part of the range, false otherwise. - bool contains_key(absl::string_view key) const; + bool contains_key(StringPiece key) const; private: MultiModeKeyRange(string begin, string end) diff --git a/tensorflow/contrib/cloud/kernels/BUILD b/tensorflow/contrib/cloud/kernels/BUILD index 84cf6a80f1b..1311063ec02 100644 --- a/tensorflow/contrib/cloud/kernels/BUILD +++ b/tensorflow/contrib/cloud/kernels/BUILD @@ -46,7 +46,6 @@ cc_library( "//tensorflow/core:protos_all_cc", "//tensorflow/core/platform/cloud:curl_http_request", "//tensorflow/core/platform/cloud:google_auth_provider", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -66,7 +65,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core/platform/cloud:http_request_fake", - "@com_google_absl//absl/strings", ], ) @@ -87,7 +85,6 @@ tf_kernel_library( "//tensorflow/core/platform/cloud:curl_http_request", "//tensorflow/core/platform/cloud:gcs_file_system", "//tensorflow/core/platform/cloud:oauth_client", - "@com_google_absl//absl/strings", "@jsoncpp_git//:jsoncpp", ], ) diff --git a/tensorflow/contrib/cloud/kernels/bigquery_table_accessor.cc b/tensorflow/contrib/cloud/kernels/bigquery_table_accessor.cc index ba7678d5a88..e57a66b99f6 100644 --- a/tensorflow/contrib/cloud/kernels/bigquery_table_accessor.cc +++ b/tensorflow/contrib/cloud/kernels/bigquery_table_accessor.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/example/feature.pb.h" #include "tensorflow/core/lib/strings/numbers.h" @@ -32,7 +31,7 @@ bool IsPartitionEmpty(const BigQueryTablePartition& partition) { return false; } -Status ParseJson(absl::string_view json, Json::Value* result) { +Status ParseJson(StringPiece json, Json::Value* result) { Json::Reader reader; if (!reader.parse(string(json), *result)) { return errors::Internal("Couldn't parse JSON response from BigQuery."); @@ -184,8 +183,8 @@ Status BigQueryTableAccessor::ReadRow(int64* row_id, Example* example) { FullTableName()); // Parse the returned row. - absl::string_view response_piece = - absl::string_view(&output_buffer[0], output_buffer.size()); + StringPiece response_piece = + StringPiece(&output_buffer[0], output_buffer.size()); Json::Value root; TF_RETURN_IF_ERROR(ParseJson(response_piece, &root)); for (unsigned int i = 0; i < root["rows"].size(); ++i) { @@ -262,8 +261,8 @@ Status BigQueryTableAccessor::ReadSchema() { FullTableName()); // Parse the schema. - absl::string_view response_piece = - absl::string_view(&output_buffer[0], output_buffer.size()); + StringPiece response_piece = + StringPiece(&output_buffer[0], output_buffer.size()); Json::Value root; TF_RETURN_IF_ERROR(ParseJson(response_piece, &root)); diff --git a/tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test.cc b/tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test.cc index c85f240c2cc..7416eb19d33 100644 --- a/tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test.cc +++ b/tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h" -#include "absl/strings/string_view.h" #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test_data.h" #include "tensorflow/core/example/feature.pb.h" #include "tensorflow/core/lib/core/status_test_util.h" @@ -30,7 +29,7 @@ constexpr char kTestProject[] = "test-project"; constexpr char kTestDataset[] = "test-dataset"; constexpr char kTestTable[] = "test-table"; -bool HasSubstr(absl::string_view base, absl::string_view substr) { +bool HasSubstr(StringPiece base, StringPiece substr) { bool ok = str_util::StrContains(base, substr); EXPECT_TRUE(ok) << base << ", expected substring " << substr; return ok; diff --git a/tensorflow/contrib/cloud/kernels/gcs_config_ops.cc b/tensorflow/contrib/cloud/kernels/gcs_config_ops.cc index fc8197c7628..648a219fb87 100644 --- a/tensorflow/contrib/cloud/kernels/gcs_config_ops.cc +++ b/tensorflow/contrib/cloud/kernels/gcs_config_ops.cc @@ -15,7 +15,6 @@ limitations under the License. #include <sstream> -#include "absl/strings/string_view.h" #include "include/json/json.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -64,8 +63,8 @@ Status RetrieveGcsFs(OpKernelContext* ctx, RetryingGcsFileSystem** fs) { } template <typename T> -Status ParseScalarArgument(OpKernelContext* ctx, - absl::string_view argument_name, T* output) { +Status ParseScalarArgument(OpKernelContext* ctx, StringPiece argument_name, + T* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); if (!TensorShapeUtils::IsScalar(argument_t->shape())) { diff --git a/tensorflow/contrib/ffmpeg/BUILD b/tensorflow/contrib/ffmpeg/BUILD index 1eb3e358b2c..f7b3273a4d3 100644 --- a/tensorflow/contrib/ffmpeg/BUILD +++ b/tensorflow/contrib/ffmpeg/BUILD @@ -29,7 +29,6 @@ cc_library( "//tensorflow/contrib/ffmpeg/default:ffmpeg_lib", "//tensorflow/core:framework_headers_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -58,7 +57,6 @@ cc_library( "//tensorflow/contrib/ffmpeg/default:ffmpeg_lib", "//tensorflow/core:framework_headers_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) diff --git a/tensorflow/contrib/ffmpeg/decode_audio_op.cc b/tensorflow/contrib/ffmpeg/decode_audio_op.cc index f4905a02de2..5ab57ca4cd4 100644 --- a/tensorflow/contrib/ffmpeg/decode_audio_op.cc +++ b/tensorflow/contrib/ffmpeg/decode_audio_op.cc @@ -18,7 +18,6 @@ #include <cstdio> #include <set> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_kernel.h" @@ -42,7 +41,8 @@ const char* kValidFileFormats[] = {"mp3", "mp4", "ogg", "wav"}; * Decoding implementation, shared across V1 and V2 ops. Creates a new * output in the context. */ -void Decode(OpKernelContext* context, const absl::string_view& file_contents, +void Decode(OpKernelContext* context, + const tensorflow::StringPiece& file_contents, const string& file_format, const int32 samples_per_second, const int32 channel_count, const string& stream) { // Write the input data to a temp file. @@ -135,7 +135,7 @@ class DecodeAudioOpV2 : public OpKernel { "channel_count must be a rank-0 tensor but got shape ", channel_count_tensor.shape().DebugString())); - const absl::string_view contents = contents_tensor.scalar<string>()(); + const tensorflow::StringPiece contents = contents_tensor.scalar<string>()(); const string file_format = str_util::Lowercase(file_format_tensor.scalar<string>()()); const int32 samples_per_second = @@ -245,7 +245,7 @@ class DecodeAudioOp : public OpKernel { errors::InvalidArgument("contents must be scalar but got shape ", contents.shape().DebugString())); - const absl::string_view file_contents = contents.scalar<string>()(); + const tensorflow::StringPiece file_contents = contents.scalar<string>()(); Decode(context, file_contents, file_format_, samples_per_second_, channel_count_, ""); } diff --git a/tensorflow/contrib/ffmpeg/decode_video_op.cc b/tensorflow/contrib/ffmpeg/decode_video_op.cc index e9c1e783de2..6f8ad486d10 100644 --- a/tensorflow/contrib/ffmpeg/decode_video_op.cc +++ b/tensorflow/contrib/ffmpeg/decode_video_op.cc @@ -18,7 +18,6 @@ #include <cstdio> #include <set> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_kernel.h" @@ -46,7 +45,7 @@ class DecodeVideoOp : public OpKernel { errors::InvalidArgument( "contents must be a rank-0 tensor but got shape ", contents_tensor.shape().DebugString())); - const absl::string_view contents = contents_tensor.scalar<string>()(); + const tensorflow::StringPiece contents = contents_tensor.scalar<string>()(); // Write the input data to a temp file. string extension; diff --git a/tensorflow/contrib/ffmpeg/default/BUILD b/tensorflow/contrib/ffmpeg/default/BUILD index 0c155414122..59bad8982dd 100644 --- a/tensorflow/contrib/ffmpeg/default/BUILD +++ b/tensorflow/contrib/ffmpeg/default/BUILD @@ -20,7 +20,6 @@ cc_library( deps = [ "//tensorflow/core:framework_headers_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", "@protobuf_archive//:protobuf_headers", ], ) diff --git a/tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc b/tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc index ccbf48b3173..cca1a054193 100644 --- a/tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc +++ b/tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc @@ -25,7 +25,6 @@ #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -304,7 +303,7 @@ FileDeleter::~FileDeleter() { env.DeleteFile(filename_).IgnoreError(); } -Status WriteFile(const string& filename, absl::string_view contents) { +Status WriteFile(const string& filename, StringPiece contents) { Env& env = *Env::Default(); std::unique_ptr<WritableFile> file; TF_RETURN_IF_ERROR(env.NewWritableFile(filename, &file)); diff --git a/tensorflow/contrib/ffmpeg/ffmpeg_lib.h b/tensorflow/contrib/ffmpeg/ffmpeg_lib.h index 0b81848668d..bf2aa755458 100644 --- a/tensorflow/contrib/ffmpeg/ffmpeg_lib.h +++ b/tensorflow/contrib/ffmpeg/ffmpeg_lib.h @@ -19,7 +19,6 @@ #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" namespace tensorflow { @@ -36,7 +35,7 @@ class FileDeleter { }; // Writes binary data to a file. -Status WriteFile(const string& filename, absl::string_view contents); +Status WriteFile(const string& filename, tensorflow::StringPiece contents); // Reads an audio file using ffmpeg and converts it into an array of samples in // [-1.0, 1.0]. If there are multiple channels in the audio then each frame will diff --git a/tensorflow/contrib/gdr/BUILD b/tensorflow/contrib/gdr/BUILD index 0fc8cd7ebd9..e534fdc1774 100644 --- a/tensorflow/contrib/gdr/BUILD +++ b/tensorflow/contrib/gdr/BUILD @@ -97,7 +97,6 @@ cc_library( "//tensorflow/core/distributed_runtime:worker_cache", "//tensorflow/core/distributed_runtime:worker_env", "//tensorflow/core/distributed_runtime:worker_interface", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc b/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc index cf4218c7169..94f522c04e5 100644 --- a/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc +++ b/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/contrib/gdr/gdr_rendezvous_mgr.h" #include "google/protobuf/any.pb.h" -#include "absl/strings/string_view.h" #include "tensorflow/contrib/gdr/gdr_memory_manager.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_mgr.h" @@ -42,7 +41,7 @@ class GdrRecvTensorCall : public BaseRecvTensorCall { GdrRecvTensorCall(WorkerInterface* wi, Device* dst_device, RemoteMemoryManager* remote_memory_manager, const Rendezvous::Args& recv_args, int64 step_id, - absl::string_view key) + StringPiece key) : wi_(wi), dst_device_(dst_device), remote_memory_manager_(remote_memory_manager), diff --git a/tensorflow/contrib/layers/kernels/BUILD b/tensorflow/contrib/layers/kernels/BUILD index d97d518bb67..7aae09ff3e9 100644 --- a/tensorflow/contrib/layers/kernels/BUILD +++ b/tensorflow/contrib/layers/kernels/BUILD @@ -13,7 +13,6 @@ cc_library( deps = [ "//tensorflow/core:framework_headers_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", "@farmhash_archive//:farmhash", "@protobuf_archive//:protobuf_headers", ], diff --git a/tensorflow/contrib/layers/kernels/sparse_feature_cross_kernel.cc b/tensorflow/contrib/layers/kernels/sparse_feature_cross_kernel.cc index 61852df9ad2..01893d60615 100644 --- a/tensorflow/contrib/layers/kernels/sparse_feature_cross_kernel.cc +++ b/tensorflow/contrib/layers/kernels/sparse_feature_cross_kernel.cc @@ -19,7 +19,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_def_builder.h" @@ -27,6 +26,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/types.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/fingerprint.h" #include "tensorflow/core/util/work_sharder.h" @@ -92,8 +92,8 @@ string SparseTensorColumn<string>::Feature(int64 batch, int64 n) const { } template <> -absl::string_view SparseTensorColumn<absl::string_view>::Feature( - int64 batch, int64 n) const { +StringPiece SparseTensorColumn<StringPiece>::Feature(int64 batch, + int64 n) const { const int64 start = feature_start_indices_[batch]; return values_.vec<string>().data()[start + n]; } @@ -130,8 +130,8 @@ string DenseTensorColumn<string>::Feature(int64 batch, int64 n) const { } template <> -absl::string_view DenseTensorColumn<absl::string_view>::Feature(int64 batch, - int64 n) const { +StringPiece DenseTensorColumn<StringPiece>::Feature(int64 batch, + int64 n) const { return tensor_.matrix<string>()(batch, n); } diff --git a/tensorflow/contrib/libsvm/kernels/decode_libsvm_op.cc b/tensorflow/contrib/libsvm/kernels/decode_libsvm_op.cc index 2e9f6096829..720c74e3de5 100644 --- a/tensorflow/contrib/libsvm/kernels/decode_libsvm_op.cc +++ b/tensorflow/contrib/libsvm/kernels/decode_libsvm_op.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -47,10 +46,10 @@ class DecodeLibsvmOp : public OpKernel { std::vector<T> out_values; std::vector<std::pair<int64, int64>> out_indices; for (int i = 0; i < input_flat.size(); ++i) { - absl::string_view line(input_flat(i)); + StringPiece line(input_flat(i)); str_util::RemoveWhitespaceContext(&line); - absl::string_view piece; + StringPiece piece; OP_REQUIRES(ctx, str_util::ConsumeNonWhitespace(&line, &piece), errors::InvalidArgument("No label found for input[", i, "]: \"", input_flat(i), "\"")); @@ -65,7 +64,7 @@ class DecodeLibsvmOp : public OpKernel { str_util::RemoveLeadingWhitespace(&line); while (str_util::ConsumeNonWhitespace(&line, &piece)) { size_t p = piece.find(':'); - OP_REQUIRES(ctx, (p != absl::string_view::npos), + OP_REQUIRES(ctx, (p != StringPiece::npos), errors::InvalidArgument("Invalid feature \"", piece, "\"")); int64 feature_index; diff --git a/tensorflow/contrib/lite/delegates/flex/BUILD b/tensorflow/contrib/lite/delegates/flex/BUILD index 55f1e8a4129..2f866eaecb8 100644 --- a/tensorflow/contrib/lite/delegates/flex/BUILD +++ b/tensorflow/contrib/lite/delegates/flex/BUILD @@ -79,7 +79,6 @@ cc_library( ":delegate_data", ":kernel", ":util", - "@com_google_absl//absl/strings", "//tensorflow/contrib/lite/c:c_api_internal", "//tensorflow/contrib/lite:kernel_api", "//tensorflow/contrib/lite:util", @@ -177,7 +176,6 @@ tf_cc_test( ":kernel", ":test_util", "@com_google_googletest//:gtest", - "@com_google_absl//absl/strings", ] + select({ "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib", diff --git a/tensorflow/contrib/lite/delegates/flex/delegate.cc b/tensorflow/contrib/lite/delegates/flex/delegate.cc index aa749ab0e5f..c72b0cf5138 100644 --- a/tensorflow/contrib/lite/delegates/flex/delegate.cc +++ b/tensorflow/contrib/lite/delegates/flex/delegate.cc @@ -16,7 +16,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/lite/context_util.h" #include "tensorflow/contrib/lite/delegates/flex/buffer_map.h" #include "tensorflow/contrib/lite/delegates/flex/kernel.h" @@ -69,7 +68,7 @@ TfLiteStatus CopyFromBufferHandle(TfLiteContext* context, } tensorflow::Tensor t = buffer_map->GetTensor(buffer_handle); - absl::string_view t_data = t.tensor_data(); + tensorflow::StringPiece t_data = t.tensor_data(); if (size != t_data.size()) { context->ReportError( diff --git a/tensorflow/contrib/lite/delegates/flex/kernel_test.cc b/tensorflow/contrib/lite/delegates/flex/kernel_test.cc index c084c35e4f5..94a6f8b61ad 100644 --- a/tensorflow/contrib/lite/delegates/flex/kernel_test.cc +++ b/tensorflow/contrib/lite/delegates/flex/kernel_test.cc @@ -16,7 +16,6 @@ limitations under the License. #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/lite/delegates/flex/delegate_data.h" #include "tensorflow/contrib/lite/delegates/flex/test_util.h" @@ -61,9 +60,9 @@ class KernelTest : public testing::FlexModelTest { TfLiteBufferHandle buffer_handle, void* data, size_t size) { auto* delegate_data = reinterpret_cast<DelegateData*>(delegate->data_); - absl::string_view values = delegate_data->GetBufferMap(context) - ->GetTensor(buffer_handle) - .tensor_data(); + tensorflow::StringPiece values = delegate_data->GetBufferMap(context) + ->GetTensor(buffer_handle) + .tensor_data(); memcpy(data, values.data(), values.size()); return kTfLiteOk; }; diff --git a/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc b/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc index 82320a54024..06ff86e6d85 100644 --- a/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc +++ b/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/str_util.h" #if GOOGLE_CUDA @@ -36,7 +35,7 @@ Status ReplaceReduce(Graph* graph, Node* node) { TF_RETURN_IF_ERROR(GetNodeAttr(node->attrs(), "T", &dtype)); int num_devices = node->num_inputs(); string shared_name = node->name(); - auto make_builder = [&](absl::string_view op_name, absl::string_view suffix) { + auto make_builder = [&](StringPiece op_name, StringPiece suffix) { return NodeBuilder(strings::StrCat(shared_name, suffix), op_name) .Attr("reduction", reduction) .Attr("num_devices", num_devices) @@ -160,7 +159,7 @@ Status ReplaceBroadcast(Graph* graph, Node* node) { } string shared_name = node->name(); - auto make_builder = [&](absl::string_view op_name, absl::string_view suffix) { + auto make_builder = [&](StringPiece op_name, StringPiece suffix) { return NodeBuilder(strings::StrCat(shared_name, suffix), op_name) .Attr("num_devices", num_devices) .Attr("shared_name", shared_name) @@ -256,7 +255,7 @@ class NcclReplacePass : public GraphOptimizationPass { } // Find reduction and broadcast ops and replace them with Send/Recv ops. for (Node* node : graph->op_nodes()) { - absl::string_view type = node->type_string(); + StringPiece type = node->type_string(); if (!str_util::StartsWith(type, "Nccl")) { continue; } diff --git a/tensorflow/contrib/saved_model/cc/saved_model/BUILD b/tensorflow/contrib/saved_model/cc/saved_model/BUILD index da27789272f..ea4d41d43b5 100644 --- a/tensorflow/contrib/saved_model/cc/saved_model/BUILD +++ b/tensorflow/contrib/saved_model/cc/saved_model/BUILD @@ -35,7 +35,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_proto_parsing", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.cc b/tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.cc index 79c0b1b0d54..e87e497e5ff 100644 --- a/tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.cc +++ b/tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.cc @@ -15,17 +15,17 @@ limitations under the License. #include "tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/protobuf.h" namespace tensorflow { namespace { template <class T> -Status FindInProtobufMap(absl::string_view description, +Status FindInProtobufMap(StringPiece description, const protobuf::Map<string, T>& map, const string& key, const T** value) { const auto it = map.find(key); diff --git a/tensorflow/contrib/session_bundle/BUILD b/tensorflow/contrib/session_bundle/BUILD index 9e0f4eb9743..9c088591807 100644 --- a/tensorflow/contrib/session_bundle/BUILD +++ b/tensorflow/contrib/session_bundle/BUILD @@ -190,7 +190,6 @@ cc_library( "//tensorflow/core:core_cpu", "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -207,7 +206,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":signature_lite", - "@com_google_absl//absl/strings", "//tensorflow/core:lib_internal", ] + if_not_mobile([ ":manifest_proto_cc", @@ -344,7 +342,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", - "@com_google_absl//absl/strings", ], ) @@ -373,7 +370,6 @@ cc_library( deps = [ ":session_bundle", ":signature", - "@com_google_absl//absl/strings", "//tensorflow/cc/saved_model:loader", "//tensorflow/cc/saved_model:signature_constants", ] + if_not_mobile([ diff --git a/tensorflow/contrib/session_bundle/bundle_shim.cc b/tensorflow/contrib/session_bundle/bundle_shim.cc index 5f2b1e2a67d..c669ced9977 100644 --- a/tensorflow/contrib/session_bundle/bundle_shim.cc +++ b/tensorflow/contrib/session_bundle/bundle_shim.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/contrib/session_bundle/bundle_shim.h" -#include "absl/strings/string_view.h" #include "tensorflow/cc/saved_model/loader.h" #include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h" @@ -24,6 +23,7 @@ limitations under the License. #include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/protobuf/meta_graph.pb.h" #include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session_options.h" @@ -129,7 +129,7 @@ Status MaybeBuildPredictSignatureDef( Status LoadSavedModelFromLegacySessionBundlePath( const SessionOptions& session_options, const RunOptions& run_options, - const absl::string_view session_bundle_export_dir, + const StringPiece session_bundle_export_dir, SavedModelBundle* saved_model_bundle) { if (session_bundle_export_dir.empty()) { return Status(error::Code::NOT_FOUND, "Export directory path is empty."); diff --git a/tensorflow/contrib/session_bundle/session_bundle.cc b/tensorflow/contrib/session_bundle/session_bundle.cc index 3f36704405b..a690d9b129a 100644 --- a/tensorflow/contrib/session_bundle/session_bundle.cc +++ b/tensorflow/contrib/session_bundle/session_bundle.cc @@ -20,7 +20,6 @@ limitations under the License. #include <vector> #include "google/protobuf/any.pb.h" -#include "absl/strings/string_view.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph_def_util.h" @@ -63,7 +62,7 @@ Status CreateSessionFromGraphDef(const SessionOptions& options, return (*session)->Create(graph); } -Status GetMetaGraphDefFromExport(const absl::string_view export_dir, +Status GetMetaGraphDefFromExport(const StringPiece export_dir, MetaGraphDef* meta_graph_def) { const string meta_graph_def_path = io::JoinPath(export_dir, kMetaGraphDefFilename); @@ -78,7 +77,7 @@ Tensor CreateStringTensor(const string& value) { } // Adds Assets related tensors (assets_dir and asset files) to the inputs. -void AddAssetsTensorsToInputs(const absl::string_view export_dir, +void AddAssetsTensorsToInputs(const StringPiece export_dir, const std::vector<AssetFile>& asset_files, std::vector<std::pair<string, Tensor>>* inputs) { if (asset_files.empty()) { @@ -109,7 +108,7 @@ void AddAssetsTensorsToInputs(const absl::string_view export_dir, // prefix.data-* are present in the filesystem. So if we see export.index // present in the export_dir, we know the export is in V2 format and we return // <export_dir>/export as this prefix. -string GetVariablesFilename(const absl::string_view export_dir) { +string GetVariablesFilename(const StringPiece export_dir) { const char kVariablesFilename[] = "export"; const string kVariablesIndexFilename = MetaFilename("export"); // V2 ckpts const char kVariablesFilenamePattern[] = "export-\?\?\?\?\?-of-\?\?\?\?\?"; @@ -129,11 +128,10 @@ string GetVariablesFilename(const absl::string_view export_dir) { } } -Status RunRestoreOp(const RunOptions& run_options, - const absl::string_view export_dir, +Status RunRestoreOp(const RunOptions& run_options, const StringPiece export_dir, const std::vector<AssetFile>& asset_files, - const absl::string_view restore_op_name, - const absl::string_view variables_filename_const_op_name, + const StringPiece restore_op_name, + const StringPiece variables_filename_const_op_name, Session* session) { LOG(INFO) << "Running restore op for SessionBundle: " << restore_op_name << ", " << variables_filename_const_op_name; @@ -147,10 +145,9 @@ Status RunRestoreOp(const RunOptions& run_options, nullptr /* outputs */, &run_metadata); } -Status RunInitOp(const RunOptions& run_options, - const absl::string_view export_dir, +Status RunInitOp(const RunOptions& run_options, const StringPiece export_dir, const std::vector<AssetFile>& asset_files, - const absl::string_view init_op_name, Session* session) { + const StringPiece init_op_name, Session* session) { LOG(INFO) << "Running init op for SessionBundle"; std::vector<std::pair<string, Tensor>> inputs; AddAssetsTensorsToInputs(export_dir, asset_files, &inputs); @@ -161,7 +158,7 @@ Status RunInitOp(const RunOptions& run_options, Status LoadSessionBundleFromPathUsingRunOptionsInternal( const SessionOptions& options, const RunOptions& run_options, - const absl::string_view export_dir, SessionBundle* const bundle) { + const StringPiece export_dir, SessionBundle* const bundle) { LOG(INFO) << "Attempting to load a SessionBundle from: " << export_dir; LOG(INFO) << "Using RunOptions: " << DebugStringIfAvailable(run_options); TF_RETURN_IF_ERROR( @@ -230,16 +227,17 @@ Status LoadSessionBundleFromPathUsingRunOptionsInternal( } // namespace Status LoadSessionBundleFromPath(const SessionOptions& options, - const absl::string_view export_dir, + const StringPiece export_dir, SessionBundle* const bundle) { TF_RETURN_IF_ERROR(LoadSessionBundleFromPathUsingRunOptions( options, RunOptions(), export_dir, bundle)); return Status::OK(); } -Status LoadSessionBundleFromPathUsingRunOptions( - const SessionOptions& options, const RunOptions& run_options, - const absl::string_view export_dir, SessionBundle* const bundle) { +Status LoadSessionBundleFromPathUsingRunOptions(const SessionOptions& options, + const RunOptions& run_options, + const StringPiece export_dir, + SessionBundle* const bundle) { const uint64 start_microseconds = Env::Default()->NowMicros(); const Status status = LoadSessionBundleFromPathUsingRunOptionsInternal( options, run_options, export_dir, bundle); @@ -265,7 +263,7 @@ Status LoadSessionBundleFromPathUsingRunOptions( return status; } -bool IsPossibleExportDirectory(const absl::string_view directory) { +bool IsPossibleExportDirectory(const StringPiece directory) { const string meta_graph_def_path = io::JoinPath(directory, kMetaGraphDefFilename); return Env::Default()->FileExists(meta_graph_def_path).ok(); diff --git a/tensorflow/contrib/session_bundle/session_bundle.h b/tensorflow/contrib/session_bundle/session_bundle.h index f25123c3884..b2be46efa6d 100644 --- a/tensorflow/contrib/session_bundle/session_bundle.h +++ b/tensorflow/contrib/session_bundle/session_bundle.h @@ -20,10 +20,10 @@ limitations under the License. #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/contrib/session_bundle/signature.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/protobuf/meta_graph.pb.h" #include "tensorflow/core/protobuf/saver.pb.h" #include "tensorflow/core/public/session.h" @@ -60,7 +60,7 @@ struct SessionBundle { // Loads a manifest and initialized session using the output of an Exporter. Status LoadSessionBundleFromPath(const SessionOptions& options, - const absl::string_view export_dir, + const StringPiece export_dir, SessionBundle* bundle); // Similar to the LoadSessionBundleFromPath(), but also allows the session run @@ -70,14 +70,14 @@ Status LoadSessionBundleFromPath(const SessionOptions& options, // This method is EXPERIMENTAL and may change or be removed. Status LoadSessionBundleFromPathUsingRunOptions( const SessionOptions& session_options, const RunOptions& run_options, - const absl::string_view export_dir, SessionBundle* bundle); + const StringPiece export_dir, SessionBundle* bundle); // Sanity checks whether the directory looks like an export directory. Note that // we don't try to load any data in this method. // // If the method returns false this is definitely not an export directory, if it // returns true, it is no guarantee that the model will load. -bool IsPossibleExportDirectory(const absl::string_view export_dir); +bool IsPossibleExportDirectory(const StringPiece export_dir); } // namespace serving } // namespace tensorflow diff --git a/tensorflow/contrib/session_bundle/signature_test.cc b/tensorflow/contrib/session_bundle/signature_test.cc index 65be9c9a8b6..b1ff55552e0 100644 --- a/tensorflow/contrib/session_bundle/signature_test.cc +++ b/tensorflow/contrib/session_bundle/signature_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include <memory> #include "google/protobuf/any.pb.h" -#include "absl/strings/string_view.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/tensor.h" @@ -26,6 +25,7 @@ limitations under the License. #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session.h" @@ -34,7 +34,7 @@ namespace tensorflow { namespace serving { namespace { -static bool HasSubstr(absl::string_view base, absl::string_view substr) { +static bool HasSubstr(StringPiece base, StringPiece substr) { bool ok = str_util::StrContains(base, substr); EXPECT_TRUE(ok) << base << ", expected substring " << substr; return ok; diff --git a/tensorflow/contrib/tensorboard/db/BUILD b/tensorflow/contrib/tensorboard/db/BUILD index 03f18183adf..6507546ee9f 100644 --- a/tensorflow/contrib/tensorboard/db/BUILD +++ b/tensorflow/contrib/tensorboard/db/BUILD @@ -47,7 +47,6 @@ cc_library( "//tensorflow/core:protos_all_cc", "//tensorflow/core/kernels:summary_interface", "//tensorflow/core/lib/db:sqlite", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/contrib/tensorboard/db/summary_db_writer.cc b/tensorflow/contrib/tensorboard/db/summary_db_writer.cc index c45be444e0b..cfdc884277a 100644 --- a/tensorflow/contrib/tensorboard/db/summary_db_writer.cc +++ b/tensorflow/contrib/tensorboard/db/summary_db_writer.cc @@ -16,12 +16,12 @@ limitations under the License. #include <deque> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/tensorboard/db/summary_converter.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/summary.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/db/sqlite.h" #include "tensorflow/core/lib/random/random.h" #include "tensorflow/core/util/event.pb.h" @@ -136,7 +136,7 @@ void PatchPluginName(SummaryMetadata* metadata, const char* name) { } } -Status SetDescription(Sqlite* db, int64 id, const absl::string_view& markdown) { +Status SetDescription(Sqlite* db, int64 id, const StringPiece& markdown) { const char* sql = R"sql( INSERT OR REPLACE INTO Descriptions (id, description) VALUES (?, ?) )sql"; @@ -260,12 +260,12 @@ class GraphWriter { for (int node_id = 0; node_id < graph_->node_size(); ++node_id) { const NodeDef& node = graph_->node(node_id); for (int idx = 0; idx < node.input_size(); ++idx) { - absl::string_view name = node.input(idx); + StringPiece name = node.input(idx); int64 input_node_id; int64 input_node_idx = 0; int64 is_control = 0; size_t i = name.rfind(':'); - if (i != absl::string_view::npos) { + if (i != StringPiece::npos) { if (!strings::safe_strto64(name.substr(i + 1, name.size() - i - 1), &input_node_idx)) { return errors::DataLoss("Bad NodeDef.input: ", name); @@ -369,8 +369,7 @@ class GraphWriter { const uint64 now_; const int64 graph_id_; std::vector<string> name_copies_; - std::unordered_map<absl::string_view, int64, StringPieceHasher> - name_to_node_id_; + std::unordered_map<StringPiece, int64, StringPieceHasher> name_to_node_id_; TF_DISALLOW_COPY_AND_ASSIGN(GraphWriter); }; @@ -681,7 +680,7 @@ class SeriesWriter { } else { SqliteTransaction txn(*db); TF_RETURN_IF_ERROR( - Update(db, step, computed_time, t, absl::string_view(), rowid)); + Update(db, step, computed_time, t, StringPiece(), rowid)); TF_RETURN_IF_ERROR(UpdateNdString(db, t, rowid)); return txn.Commit(); } @@ -691,7 +690,7 @@ class SeriesWriter { } Status Update(Sqlite* db, int64 step, double computed_time, const Tensor& t, - const absl::string_view& data, int64 rowid) { + const StringPiece& data, int64 rowid) { const char* sql = R"sql( UPDATE OR REPLACE Tensors diff --git a/tensorflow/contrib/tpu/profiler/BUILD b/tensorflow/contrib/tpu/profiler/BUILD index adaa7fbfbd4..38d1c3049ef 100644 --- a/tensorflow/contrib/tpu/profiler/BUILD +++ b/tensorflow/contrib/tpu/profiler/BUILD @@ -29,7 +29,6 @@ cc_library( "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/contrib/tpu/profiler/dump_tpu_profile.cc b/tensorflow/contrib/tpu/profiler/dump_tpu_profile.cc index 49baacceed3..b4b06a40a2c 100644 --- a/tensorflow/contrib/tpu/profiler/dump_tpu_profile.cc +++ b/tensorflow/contrib/tpu/profiler/dump_tpu_profile.cc @@ -19,7 +19,6 @@ limitations under the License. #include <ctime> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/contrib/tpu/profiler/op_profile.pb.h" #include "tensorflow/contrib/tpu/profiler/trace_events.pb.h" #include "tensorflow/contrib/tpu/profiler/trace_events_to_json.h" @@ -64,8 +63,7 @@ Status WriteGzippedDataToFile(const string& filename, const string& data) { return Status::OK(); } -Status DumpTraceToLogDirectory(absl::string_view run_dir, - const string& host_prefix, +Status DumpTraceToLogDirectory(StringPiece run_dir, const string& host_prefix, const string& encoded_trace, std::ostream* os) { string proto_path = JoinPath(run_dir, StrCat(host_prefix, kProtoTraceFileName)); @@ -88,7 +86,7 @@ Status DumpTraceToLogDirectory(absl::string_view run_dir, return Status::OK(); } -Status DumpOpProfileToLogDirectory(absl::string_view run_dir, +Status DumpOpProfileToLogDirectory(StringPiece run_dir, const string& host_prefix, const tpu::op_profile::Profile& profile, std::ostream* os) { @@ -109,7 +107,7 @@ Status DumpOpProfileToLogDirectory(absl::string_view run_dir, return Status::OK(); } -Status DumpToolDataToLogDirectory(absl::string_view run_dir, +Status DumpToolDataToLogDirectory(StringPiece run_dir, const string& host_prefix, const tensorflow::ProfileToolData& tool, std::ostream* os) { diff --git a/tensorflow/contrib/verbs/BUILD b/tensorflow/contrib/verbs/BUILD index 83aae915be8..19cb8983b68 100644 --- a/tensorflow/contrib/verbs/BUILD +++ b/tensorflow/contrib/verbs/BUILD @@ -42,7 +42,6 @@ cc_library( deps = [ "//tensorflow/core:framework", "//tensorflow/core:lib", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/contrib/verbs/verbs_util.cc b/tensorflow/contrib/verbs/verbs_util.cc index 36623472562..a6333d9f362 100644 --- a/tensorflow/contrib/verbs/verbs_util.cc +++ b/tensorflow/contrib/verbs/verbs_util.cc @@ -17,7 +17,7 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -32,7 +32,7 @@ string VerbsUtil::AppendStepidToKey(const string& key, int64 step_id) { // static void VerbsUtil::GetKeyAndStepId(const string& key_with_step_id, string& key, int64& step_id) { - absl::string_view s(key_with_step_id); + StringPiece s(key_with_step_id); // a key (with step_id) has exact 6 parts if split by ";" // part 1: src_device; // part 2: src_incarnation; diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 8cdc6296409..841291e6d85 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -485,7 +485,6 @@ cc_library( ":platform_port", ":platform_protobuf", "//tensorflow/core/platform/default/build_config:env", - "@com_google_absl//absl/strings", ], ) @@ -515,7 +514,6 @@ cc_library( ":lib", ":lib_platform", ":platform_env", - "@com_google_absl//absl/strings", ], ) @@ -594,7 +592,6 @@ cc_library( "//tensorflow/core/platform/default/build_config:other", "//tensorflow/core/platform/default/build_config:platformlib", "//tensorflow/core/platform/default/build_config:port", - "@com_google_absl//absl/strings", ], ) @@ -981,7 +978,6 @@ cc_library( ":lib", ":lib_internal", ":protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -1482,7 +1478,6 @@ cc_library( "//tensorflow/core/kernels:ops_testutil", "//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:random_ops", - "@com_google_absl//absl/strings", ], ) @@ -2198,7 +2193,6 @@ cc_library( ":lib_proto_parsing", ":abi", ":core_stringpiece", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core/platform/default/build_config:platformlib", "@snappy", @@ -2624,7 +2618,6 @@ tf_cuda_library( ":protos_all_cc", ":stats_calculator_portable", ":version_lib", - "@com_google_absl//absl/strings", "//tensorflow/core/platform/default/build_config:platformlib", "//tensorflow/core/kernels:bounds_check", "//third_party/eigen3", @@ -2755,7 +2748,6 @@ tf_cuda_library( ":proto_text", ":protos_all_cc", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -2800,7 +2792,6 @@ tf_cuda_library( ":function_ops_op_lib", ":functional_grad", ":functional_ops_op_lib", - "@com_google_absl//absl/strings", "//tensorflow/core/kernels:bounds_check", "//tensorflow/core/kernels:required", ":core_cpu_impl", @@ -2930,7 +2921,6 @@ tf_cuda_library( ":lib_internal", ":proto_text", ":protos_all_cc", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core/grappler:grappler_item", ] + mkl_deps(), @@ -3010,7 +3000,6 @@ tf_cuda_library( ":protos_all_cc", "//tensorflow/core/debug:debug_graph_utils", "//tensorflow/core/kernels:function_ops", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -3134,7 +3123,6 @@ tf_cuda_library( ":protos_all_cc", ":stream_executor", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -3264,7 +3252,6 @@ cc_library( ":lib", ":lib_internal", ":protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -3380,7 +3367,6 @@ tf_cc_tests( ":test", ":test_main", "//third_party/eigen3", - "@com_google_absl//absl/strings", "@zlib_archive//:zlib", ], ) @@ -3412,7 +3398,6 @@ tf_cc_test( ":test", ":test_main", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -3484,7 +3469,6 @@ tf_cc_test( ":protos_all_cc", ":test", ":test_main", - "@com_google_absl//absl/strings", ], ) @@ -3534,7 +3518,6 @@ tf_cc_test( ":lib_internal", ":test", ":test_main", - "@com_google_absl//absl/strings", ], ) @@ -3696,7 +3679,6 @@ tf_cc_tests( "//tensorflow/cc:while_loop", "//tensorflow/core/kernels:ops_util", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -3733,7 +3715,6 @@ tf_cc_tests( "//tensorflow/cc:sendrecv_ops", "//tensorflow/core/kernels:ops_util", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -3917,7 +3898,6 @@ tf_cc_tests_gpu( ":testlib", "//tensorflow/cc:cc_ops", "//tensorflow/core/kernels:ops_util", - "@com_google_absl//absl/strings", ], ) @@ -3966,7 +3946,6 @@ tf_cuda_cc_test( ":testlib", "//tensorflow/cc:cc_ops", "//tensorflow/core/kernels:ops_util", - "@com_google_absl//absl/strings", ], ) @@ -4083,7 +4062,6 @@ tf_cc_test( "//tensorflow/core/kernels:immutable_constant_op", "//tensorflow/core/kernels:matmul_op", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -4194,7 +4172,6 @@ tf_cuda_cc_test( ":test", ":test_main", ":testlib", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/cc:cc_ops", "//tensorflow/core/kernels:collective_ops", @@ -4235,7 +4212,6 @@ tf_cc_test( ":test", ":test_main", ":testlib", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/cc:cc_ops", # Link with support for TensorFlow Debugger (tfdbg). @@ -4376,7 +4352,6 @@ tf_cc_test( "//tensorflow/core/kernels:random_ops", "//tensorflow/core/kernels:shape_ops", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -4769,7 +4744,6 @@ tf_cc_tests( "//tensorflow/cc:client_session", "//tensorflow/cc:function_ops", "//tensorflow/cc:ops", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/common_runtime/constant_folding_test.cc b/tensorflow/core/common_runtime/constant_folding_test.cc index 2227705ab55..98aefcde27f 100644 --- a/tensorflow/core/common_runtime/constant_folding_test.cc +++ b/tensorflow/core/common_runtime/constant_folding_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/constant_folding.h" #include "tensorflow/cc/ops/array_ops_internal.h" @@ -641,7 +640,7 @@ class TestTFFileSystem : public ::tensorflow::NullFileSystem { return ::tensorflow::errors::Unimplemented( "NewReadOnlyMemoryRegionFromFile unimplemented"); } - const ::absl::string_view sp = data_tensor_.tensor_data(); + const ::tensorflow::StringPiece sp = data_tensor_.tensor_data(); *result = std::unique_ptr<::tensorflow::ReadOnlyMemoryRegion>( new TestReadOnlyMemoryRegion(sp.data(), sp.size())); return ::tensorflow::Status::OK(); diff --git a/tensorflow/core/common_runtime/copy_tensor.cc b/tensorflow/core/common_runtime/copy_tensor.cc index 56b80cccaa0..6e2eb66b946 100644 --- a/tensorflow/core/common_runtime/copy_tensor.cc +++ b/tensorflow/core/common_runtime/copy_tensor.cc @@ -18,7 +18,6 @@ limitations under the License. #include <atomic> #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/dma_helper.h" #include "tensorflow/core/framework/variant_op_registry.h" #include "tensorflow/core/lib/core/errors.h" @@ -49,7 +48,7 @@ std::vector<RegistrationInfo>* MutableRegistry() { } void CopyHostToDevice(const Tensor* input, Allocator* cpu_allocator, - Allocator* out_allocator, absl::string_view edge_name, + Allocator* out_allocator, StringPiece edge_name, Device* dst, Tensor* output, DeviceContext* recv_dev_context, StatusCallback done) { if (input->dtype() == DT_VARIANT) { @@ -114,7 +113,7 @@ void CopyHostToDevice(const Tensor* input, Allocator* cpu_allocator, } void CopyDeviceToHost(const Tensor* input, Allocator* cpu_allocator, - Allocator* out_allocator, absl::string_view edge_name, + Allocator* out_allocator, StringPiece edge_name, Device* src, Tensor* output, DeviceContext* send_dev_context, StatusCallback done) { if (input->dtype() == DT_VARIANT) { @@ -247,8 +246,7 @@ void CopyDeviceToDevice(CopyTensor::CopyFunction copy_function, } // namespace // static -void CopyTensor::ViaDMA(absl::string_view edge_name, - DeviceContext* send_dev_context, +void CopyTensor::ViaDMA(StringPiece edge_name, DeviceContext* send_dev_context, DeviceContext* recv_dev_context, Device* src, Device* dst, const AllocatorAttributes src_alloc_attr, const AllocatorAttributes dst_alloc_attr, diff --git a/tensorflow/core/common_runtime/copy_tensor.h b/tensorflow/core/common_runtime/copy_tensor.h index f7a416fffcf..9cd5ac2a37d 100644 --- a/tensorflow/core/common_runtime/copy_tensor.h +++ b/tensorflow/core/common_runtime/copy_tensor.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/device_base.h" @@ -41,8 +40,7 @@ class CopyTensor { // the type of devices and memory in use, the copy may be performed // synchronously or asynchronously. 'done' will be invoked only // after the copy is actually complete. - static void ViaDMA(absl::string_view edge_name, - DeviceContext* send_dev_context, + static void ViaDMA(StringPiece edge_name, DeviceContext* send_dev_context, DeviceContext* recv_dev_context, Device* src, Device* dst, const AllocatorAttributes src_alloc_attr, const AllocatorAttributes dst_alloc_attr, diff --git a/tensorflow/core/common_runtime/device_mgr.cc b/tensorflow/core/common_runtime/device_mgr.cc index 068e944fec9..470abc14312 100644 --- a/tensorflow/core/common_runtime/device_mgr.cc +++ b/tensorflow/core/common_runtime/device_mgr.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/common_runtime/device_mgr.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/local_device.h" #include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/lib/core/errors.h" @@ -52,11 +51,11 @@ DeviceMgr::~DeviceMgr() { for (Device* p : devices_) delete p; } -absl::string_view DeviceMgr::CopyToBackingStore(absl::string_view s) { +StringPiece DeviceMgr::CopyToBackingStore(StringPiece s) { size_t n = s.size(); char* space = name_backing_store_.Alloc(n); memcpy(space, s.data(), n); - return absl::string_view(space, n); + return StringPiece(space, n); } void DeviceMgr::ListDeviceAttributes( @@ -90,11 +89,11 @@ string DeviceMgr::DeviceMappingString() const { return out; } -Status DeviceMgr::LookupDevice(absl::string_view name, Device** device) const { +Status DeviceMgr::LookupDevice(StringPiece name, Device** device) const { Status s; auto iter = device_map_.find(name); if (iter == device_map_.end()) { - std::vector<absl::string_view> device_names; + std::vector<StringPiece> device_names; for (auto&& itr : device_map_) { device_names.push_back(itr.first); } diff --git a/tensorflow/core/common_runtime/device_mgr.h b/tensorflow/core/common_runtime/device_mgr.h index 7a4235d3bcb..c1ff10d9b59 100644 --- a/tensorflow/core/common_runtime/device_mgr.h +++ b/tensorflow/core/common_runtime/device_mgr.h @@ -21,10 +21,10 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/lib/core/arena.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/platform/macros.h" @@ -53,7 +53,7 @@ class DeviceMgr { // Assigns *device with pointer to Device of the given name. // Accepts either a full device name, or just the replica-local suffix. - Status LookupDevice(absl::string_view name, Device** device) const; + Status LookupDevice(StringPiece name, Device** device) const; // Clears given containers of all devices if 'container' is // non-empty. Otherwise, clears default containers of all devices. @@ -66,9 +66,9 @@ class DeviceMgr { typedef gtl::InlinedVector<Device*, 8> DeviceVec; DeviceVec devices_; - absl::string_view CopyToBackingStore(absl::string_view s); + StringPiece CopyToBackingStore(StringPiece s); - std::unordered_map<absl::string_view, Device*, StringPieceHasher> device_map_; + std::unordered_map<StringPiece, Device*, StringPieceHasher> device_map_; core::Arena name_backing_store_; // Storage for keys in device_map_ std::unordered_map<string, int> device_type_counts_; diff --git a/tensorflow/core/common_runtime/device_set.cc b/tensorflow/core/common_runtime/device_set.cc index a1e162ed4b8..f6b4115cbf0 100644 --- a/tensorflow/core/common_runtime/device_set.cc +++ b/tensorflow/core/common_runtime/device_set.cc @@ -19,9 +19,9 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_factory.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/map_util.h" namespace tensorflow { @@ -68,7 +68,7 @@ static bool DeviceTypeComparator(const DeviceType& a, const DeviceType& b) { return a_priority > b_priority; } - return absl::string_view(a.type()) < absl::string_view(b.type()); + return StringPiece(a.type()) < StringPiece(b.type()); } std::vector<DeviceType> DeviceSet::PrioritizedDeviceTypeList() const { diff --git a/tensorflow/core/common_runtime/direct_session.cc b/tensorflow/core/common_runtime/direct_session.cc index 139fed6e6be..52c1cd26918 100644 --- a/tensorflow/core/common_runtime/direct_session.cc +++ b/tensorflow/core/common_runtime/direct_session.cc @@ -19,7 +19,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/collective_executor_mgr.h" #include "tensorflow/core/common_runtime/collective_param_resolver_local.h" #include "tensorflow/core/common_runtime/constant_folding.h" @@ -1193,7 +1192,7 @@ Status DirectSession::CreateExecutors( if (run_state_args->is_partial_run) { ek->graph = std::move(run_state_args->graph); - std::unordered_set<absl::string_view, StringPieceHasher> names; + std::unordered_set<StringPiece, StringPieceHasher> names; for (const string& input : callable_options.feed()) { TensorId id(ParseTensorName(input)); names.emplace(id.first); diff --git a/tensorflow/core/common_runtime/direct_session.h b/tensorflow/core/common_runtime/direct_session.h index 5e64f9cee6e..3a168bbe3fc 100644 --- a/tensorflow/core/common_runtime/direct_session.h +++ b/tensorflow/core/common_runtime/direct_session.h @@ -23,7 +23,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/costmodel_manager.h" #include "tensorflow/core/common_runtime/debugger_state_interface.h" #include "tensorflow/core/common_runtime/device_mgr.h" @@ -66,8 +65,7 @@ class DirectSession : public Session { ~DirectSession() override; typedef std::vector<std::pair<string, Tensor>> NamedTensorList; - typedef std::unordered_map<absl::string_view, Node*, StringPieceHasher> - NameNodeMap; + typedef std::unordered_map<StringPiece, Node*, StringPieceHasher> NameNodeMap; ::tensorflow::Status Create(const GraphDef& graph) override; ::tensorflow::Status Extend(const GraphDef& graph) override; diff --git a/tensorflow/core/common_runtime/direct_session_test.cc b/tensorflow/core/common_runtime/direct_session_test.cc index e33b1cb74eb..a6440c55ad4 100644 --- a/tensorflow/core/common_runtime/direct_session_test.cc +++ b/tensorflow/core/common_runtime/direct_session_test.cc @@ -22,7 +22,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/function_testlib.h" @@ -2041,8 +2040,8 @@ void TestFeedAndFetchTensorsInDeviceMemory( << DataType_Name(dtype); TF_ASSERT_OK(session->ReleaseCallable(handle)) << DataType_Name(dtype); ASSERT_EQ(1, outputs.size()); - const absl::string_view actual_data = outputs[0].tensor_data(); - const absl::string_view expected_data = host_tensor.tensor_data(); + const StringPiece actual_data = outputs[0].tensor_data(); + const StringPiece expected_data = host_tensor.tensor_data(); EXPECT_EQ(expected_data.size(), actual_data.size()) << DataType_Name(dtype); EXPECT_EQ(0, memcmp(expected_data.data(), actual_data.data(), std::min(expected_data.size(), actual_data.size()))) diff --git a/tensorflow/core/common_runtime/eager/BUILD b/tensorflow/core/common_runtime/eager/BUILD index ebc9e28c3ac..7b74c67c858 100644 --- a/tensorflow/core/common_runtime/eager/BUILD +++ b/tensorflow/core/common_runtime/eager/BUILD @@ -49,7 +49,6 @@ tf_cuda_library( deps = [ ":eager_executor", ":kernel_and_device", - "@com_google_absl//absl/strings", ] + select({ "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", @@ -198,7 +197,6 @@ cc_library( ":eager_operation", ":kernel_and_device", ":tensor_handle", - "@com_google_absl//absl/strings", ] + select({ "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", @@ -223,7 +221,6 @@ tf_cuda_library( deps = [ ":kernel_and_device", "@farmhash_archive//:farmhash", - "@com_google_absl//absl/strings", # Only the TF_AttrType enum is required, so pull in just the C headers. # TODO(b/113535673): Break this dependency and avoid the C header completely. "//tensorflow/c:c_api_headers", diff --git a/tensorflow/core/common_runtime/eager/attr_builder.cc b/tensorflow/core/common_runtime/eager/attr_builder.cc index d77372684d6..5c8369de876 100644 --- a/tensorflow/core/common_runtime/eager/attr_builder.cc +++ b/tensorflow/core/common_runtime/eager/attr_builder.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/common_runtime/eager/attr_builder.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/common_runtime/eager/kernel_and_device.h" #include "tensorflow/core/common_runtime/rendezvous_mgr.h" @@ -97,12 +96,11 @@ Status AttrTypeMapForOp(const char* op_name, const AttrTypeMap** out) { return Status::OK(); } -#define DEFINE_SET_ATTR(value_type, value_field) \ - template <> \ - AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, \ - value_type&& value) { \ - value_field.push_back(std::make_pair(attr_name, value)); \ - return *this; \ +#define DEFINE_SET_ATTR(value_type, value_field) \ + template <> \ + AttrBuilder& AttrBuilder::Set(StringPiece attr_name, value_type&& value) { \ + value_field.push_back(std::make_pair(attr_name, value)); \ + return *this; \ } DEFINE_SET_ATTR(float, float_attrs_); @@ -196,13 +194,13 @@ void CombineUnordered(const tensorflow::Fprint128& a, b->high64 += a.high64; } -inline tensorflow::Fprint128 CacheKeyHelper(absl::string_view s, +inline tensorflow::Fprint128 CacheKeyHelper(StringPiece s, const tensorflow::Fprint128& b) { tensorflow::Fprint128 a = tensorflow::Fingerprint128(s); return FingerprintCat128(a, b); } -inline tensorflow::Fprint128 CacheKeyHelper(absl::string_view s, uint64 b) { +inline tensorflow::Fprint128 CacheKeyHelper(StringPiece s, uint64 b) { return CacheKeyHelper(s, {b, b}); } diff --git a/tensorflow/core/common_runtime/eager/attr_builder.h b/tensorflow/core/common_runtime/eager/attr_builder.h index 4dbf6da49b3..c114ea4ba02 100644 --- a/tensorflow/core/common_runtime/eager/attr_builder.h +++ b/tensorflow/core/common_runtime/eager/attr_builder.h @@ -21,7 +21,6 @@ limitations under the License. #include <memory> #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/c/c_api.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/eager/kernel_and_device.h" @@ -95,7 +94,7 @@ class AttrBuilder { AttrBuilder& NumInputs(int n); template <class T> - AttrBuilder& Set(absl::string_view attr_name, T&& value) { + AttrBuilder& Set(StringPiece attr_name, T&& value) { MayBeInitializeNodeDef(); SetInAttrValueMap(node_def_->mutable_attr(), attr_name, value); return *this; @@ -108,8 +107,7 @@ class AttrBuilder { private: template <class T> - using AttrVec = - tensorflow::gtl::InlinedVector<std::pair<absl::string_view, T>, 2>; + using AttrVec = tensorflow::gtl::InlinedVector<std::pair<StringPiece, T>, 2>; void MayBeInitializeNodeDef(); // Fill `m` with the attr-value pairs set via AttrBuilder::Set() so far, as @@ -121,7 +119,7 @@ class AttrBuilder { void FillAttrValueMap(AttrValueMap* m, bool include_those_in_node_def) const; template <class T> - void SetInAttrValueMap(AttrValueMap* m, absl::string_view attr_name, + void SetInAttrValueMap(AttrValueMap* m, StringPiece attr_name, T&& value) const { DCHECK(!node_def_finalized_) << "Calling SetInAttrValueMap after BuildNodeDef."; @@ -150,15 +148,16 @@ class AttrBuilder { }; // namespace tensorflow template <> -AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, int&& value); +AttrBuilder& AttrBuilder::Set(StringPiece attr_name, int&& value); template <> -AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, float&& value); +AttrBuilder& AttrBuilder::Set(StringPiece attr_name, float&& value); template <> -AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, bool&& value); +AttrBuilder& AttrBuilder::Set(StringPiece attr_name, bool&& value); template <> -AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, +AttrBuilder& AttrBuilder::Set(StringPiece attr_name, tensorflow::DataType&& value); + } // namespace tensorflow #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_ATTR_BUILDER_H_ diff --git a/tensorflow/core/common_runtime/eager/context.cc b/tensorflow/core/common_runtime/eager/context.cc index 9fc15e832d0..f23cefb33d7 100644 --- a/tensorflow/core/common_runtime/eager/context.cc +++ b/tensorflow/core/common_runtime/eager/context.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/common_runtime/eager/context.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device_set.h" #include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/framework/resource_mgr.h" @@ -25,7 +24,7 @@ limitations under the License. namespace tensorflow { namespace { -bool ReadBoolFromEnvVar(absl::string_view env_var_name, bool default_val) { +bool ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val) { bool val; if (tensorflow::ReadBoolFromEnvVar(env_var_name, default_val, &val).ok()) { return val; diff --git a/tensorflow/core/common_runtime/eager/execute.cc b/tensorflow/core/common_runtime/eager/execute.cc index bf42172ffe6..c29a767d237 100644 --- a/tensorflow/core/common_runtime/eager/execute.cc +++ b/tensorflow/core/common_runtime/eager/execute.cc @@ -17,7 +17,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_set.h" #include "tensorflow/core/common_runtime/eager/context.h" @@ -821,7 +820,7 @@ Status FindDeviceFromName(EagerContext* ctx, const char* device_name, } Status ExecuteSend(EagerContext* ctx, tensorflow::Device* device, - TensorHandle* h, absl::string_view wire_id, + TensorHandle* h, StringPiece wire_id, const string& recv_device) { const tensorflow::AttrTypeMap* types; TF_RETURN_IF_ERROR(tensorflow::AttrTypeMapForOp("_Send", &types)); @@ -848,7 +847,7 @@ Status ExecuteSend(EagerContext* ctx, tensorflow::Device* device, } Status ExecuteRecv(EagerContext* ctx, tensorflow::Device* device, - DataType dtype, absl::string_view wire_id, + DataType dtype, StringPiece wire_id, const string& send_device, int64 send_device_incarnation, TensorHandle** result) { const tensorflow::AttrTypeMap* types; diff --git a/tensorflow/core/common_runtime/function.cc b/tensorflow/core/common_runtime/function.cc index 327e22a2ea5..e0e5f4a2156 100644 --- a/tensorflow/core/common_runtime/function.cc +++ b/tensorflow/core/common_runtime/function.cc @@ -18,7 +18,6 @@ limitations under the License. #include <deque> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/executor.h" #include "tensorflow/core/common_runtime/executor_factory.h" @@ -584,7 +583,7 @@ Status FunctionLibraryRuntimeImpl::ReleaseHandle(Handle handle) { return Status::OK(); } -void DumpGraph(absl::string_view label, const Graph* g) { +void DumpGraph(StringPiece label, const Graph* g) { // TODO(zhifengc): Change Graph to record #nodes. VLOG(1) << "Graph " << label << " #nodes " << g->num_nodes() << " #edges " << g->num_edges(); diff --git a/tensorflow/core/common_runtime/function.h b/tensorflow/core/common_runtime/function.h index 877fb08306a..eeca66f5d0b 100644 --- a/tensorflow/core/common_runtime/function.h +++ b/tensorflow/core/common_runtime/function.h @@ -19,7 +19,6 @@ limitations under the License. #include <functional> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/process_function_library_runtime.h" @@ -125,7 +124,7 @@ bool ExpandInlineFunctions(FunctionLibraryRuntime* lib, Graph* graph); // Dump the contents of the "graph" to log files if the logging level is // sufficiently high. -void DumpGraph(absl::string_view label, const Graph* g); +void DumpGraph(StringPiece label, const Graph* g); // Applies graph rewrite optimization such as inlining, dead code // removal, etc. diff --git a/tensorflow/core/common_runtime/function_test.cc b/tensorflow/core/common_runtime/function_test.cc index 7182b1bb7bd..716167132b3 100644 --- a/tensorflow/core/common_runtime/function_test.cc +++ b/tensorflow/core/common_runtime/function_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include <atomic> #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/array_ops_internal.h" #include "tensorflow/cc/ops/function_ops.h" #include "tensorflow/cc/ops/functional_ops.h" @@ -56,7 +55,7 @@ Status GetOpSig(const string& op, const OpDef** sig) { return OpRegistry::Global()->LookUpOpDef(op, sig); } -void HasError(const Status& s, absl::string_view substr) { +void HasError(const Status& s, StringPiece substr) { EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << s << ", expected substring " << substr; } diff --git a/tensorflow/core/common_runtime/gpu/gpu_device_test.cc b/tensorflow/core/common_runtime/gpu/gpu_device_test.cc index 281f6216c4e..36294094e9a 100644 --- a/tensorflow/core/common_runtime/gpu/gpu_device_test.cc +++ b/tensorflow/core/common_runtime/gpu/gpu_device_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #if GOOGLE_CUDA #include "tensorflow/core/common_runtime/gpu/gpu_device.h" @@ -54,7 +53,7 @@ Status GetComputeCapability(PlatformGpuId gpu_id, int* cc_major, return Status::OK(); } -void ExpectErrorMessageSubstr(const Status& s, absl::string_view substr) { +void ExpectErrorMessageSubstr(const Status& s, StringPiece substr) { EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << s << ", expected substring " << substr; } diff --git a/tensorflow/core/common_runtime/gpu/gpu_util_platform_specific.cc b/tensorflow/core/common_runtime/gpu/gpu_util_platform_specific.cc index 6061fd50c65..4bc88ffc8c3 100644 --- a/tensorflow/core/common_runtime/gpu/gpu_util_platform_specific.cc +++ b/tensorflow/core/common_runtime/gpu/gpu_util_platform_specific.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h" #include "tensorflow/core/common_runtime/gpu/gpu_util.h" @@ -32,7 +31,7 @@ void GPUDeviceContext::CopyCPUTensorToDevice(const Tensor* cpu_tensor, } void GPUDeviceContext::CopyDeviceTensorToCPU(const Tensor* device_tensor, - absl::string_view tensor_name, + StringPiece tensor_name, Device* device, Tensor* cpu_tensor, StatusCallback done) { GPUUtil::CopyGPUTensorToCPU(device, this, device_tensor, cpu_tensor, done); diff --git a/tensorflow/core/common_runtime/gpu_device_context.h b/tensorflow/core/common_runtime/gpu_device_context.h index 5cd5b61be0d..36038081527 100644 --- a/tensorflow/core/common_runtime/gpu_device_context.h +++ b/tensorflow/core/common_runtime/gpu_device_context.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" @@ -54,9 +53,9 @@ class GPUDeviceContext : public DeviceContext { Tensor* device_tensor, StatusCallback done) const override; - void CopyDeviceTensorToCPU(const Tensor* device_tensor, - absl::string_view edge_name, Device* device, - Tensor* cpu_tensor, StatusCallback done) override; + void CopyDeviceTensorToCPU(const Tensor* device_tensor, StringPiece edge_name, + Device* device, Tensor* cpu_tensor, + StatusCallback done) override; void MaintainLifetimeOnStream(const Tensor* t, se::Stream* stream) const override {} diff --git a/tensorflow/core/common_runtime/lower_if_while_test.cc b/tensorflow/core/common_runtime/lower_if_while_test.cc index f9f68056605..07bcecf1688 100644 --- a/tensorflow/core/common_runtime/lower_if_while_test.cc +++ b/tensorflow/core/common_runtime/lower_if_while_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/common_runtime/lower_if_while.h" -#include "absl/strings/string_view.h" #include "tensorflow/cc/client/client_session.h" #include "tensorflow/cc/framework/ops.h" #include "tensorflow/cc/ops/array_ops.h" @@ -39,7 +38,7 @@ namespace { typedef FunctionDefHelper FDH; -static void AssertHasSubstr(absl::string_view s, absl::string_view expected) { +static void AssertHasSubstr(StringPiece s, StringPiece expected) { ASSERT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/core/common_runtime/placer.cc b/tensorflow/core/common_runtime/placer.cc index d0583284a26..5e1ed130808 100644 --- a/tensorflow/core/common_runtime/placer.cc +++ b/tensorflow/core/common_runtime/placer.cc @@ -20,7 +20,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/graph.pb.h" @@ -29,6 +28,7 @@ limitations under the License. #include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -37,9 +37,8 @@ namespace { // We hoist the conversion from C-style string literal to StringPiece here, // so that we can avoid the many repeated calls to strlen(). -const absl::string_view kColocationAttrNameStringPiece(kColocationAttrName); -const absl::string_view kColocationGroupPrefixStringPiece( - kColocationGroupPrefix); +const StringPiece kColocationAttrNameStringPiece(kColocationAttrName); +const StringPiece kColocationGroupPrefixStringPiece(kColocationGroupPrefix); // Returns a list of devices having type in supported_device_types. The // returned list is sorted by preferred type (higher numeric type is preferred). @@ -69,7 +68,7 @@ std::vector<Device*> FilterSupportedDevices( if (a_priority != b_priority) { return a_priority > b_priority; } - return absl::string_view(a->name()) < absl::string_view(b->name()); + return StringPiece(a->name()) < StringPiece(b->name()); }; std::vector<Device*>::iterator sort_start; if (filtered_default_device != nullptr) { @@ -145,7 +144,7 @@ class ColocationGraph { // 'string' values stored in NodeDef attribute lists, as well as StringPiece // values that refer to 'string' values from NodeDef::name(), without // performing any string allocations. - std::unordered_map<absl::string_view, const Node*, StringPieceHasher> + std::unordered_map<StringPiece, const Node*, StringPieceHasher> colocation_group_root; for (Node* node : graph_->op_nodes()) { @@ -162,7 +161,7 @@ class ColocationGraph { node->attrs().Find(kColocationAttrNameStringPiece); if (attr_value != nullptr && attr_value->has_list()) { for (const string& class_spec : attr_value->list().s()) { - absl::string_view spec(class_spec); + StringPiece spec(class_spec); if (str_util::ConsumePrefix(&spec, kColocationGroupPrefixStringPiece)) { found_spec = true; @@ -184,9 +183,9 @@ class ColocationGraph { } Status ColocateNodeToGroup( - std::unordered_map<absl::string_view, const Node*, StringPieceHasher>* + std::unordered_map<StringPiece, const Node*, StringPieceHasher>* colocation_group_root, - Node* node, absl::string_view colocation_group) { + Node* node, StringPiece colocation_group) { const Node*& root_node = (*colocation_group_root)[colocation_group]; if (root_node == nullptr) { // This is the first node of the colocation group, so diff --git a/tensorflow/core/common_runtime/profile_handler.h b/tensorflow/core/common_runtime/profile_handler.h index cfdf8caf5c4..391dc8c1987 100644 --- a/tensorflow/core/common_runtime/profile_handler.h +++ b/tensorflow/core/common_runtime/profile_handler.h @@ -16,10 +16,10 @@ limitations under the License. #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/step_stats.pb.h" #include "tensorflow/core/graph/types.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { @@ -41,9 +41,8 @@ class ProfileHandler { // - op_type: String name of the Op. // - details: Main content for timeline click text. virtual void RecordOneOp(const string& device, const NodeExecStats& stats, - bool is_copy, absl::string_view label, - absl::string_view op_type, - absl::string_view details) = 0; + bool is_copy, StringPiece label, StringPiece op_type, + StringPiece details) = 0; // Records that the current step finished. // diff --git a/tensorflow/core/common_runtime/shape_refiner.cc b/tensorflow/core/common_runtime/shape_refiner.cc index 6852e12609e..9488a447789 100644 --- a/tensorflow/core/common_runtime/shape_refiner.cc +++ b/tensorflow/core/common_runtime/shape_refiner.cc @@ -19,7 +19,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/eval_const_tensor.h" #include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/node_def.pb.h" @@ -69,7 +68,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner, TF_RETURN_IF_ERROR(refiner->AddNode(node)); InferenceContext* node_context = CHECK_NOTNULL(refiner->GetContext(node)); - if (absl::string_view(node->type_string()) == kArgOp) { + if (StringPiece(node->type_string()) == kArgOp) { // Handle special node: function input. // Shapes for these nodes are provided in the outer inference // context. @@ -89,7 +88,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner, if (resource) { node_context->set_output_handle_shapes_and_types(0, *resource); } - } else if (absl::string_view(node->type_string()) == kRetvalOp) { + } else if (StringPiece(node->type_string()) == kRetvalOp) { // Handle special node: function output. // Shapes inferred for these nodes go into the outer inference // context. diff --git a/tensorflow/core/common_runtime/step_stats_collector.cc b/tensorflow/core/common_runtime/step_stats_collector.cc index d82cb3d495a..a70ab93d4ad 100644 --- a/tensorflow/core/common_runtime/step_stats_collector.cc +++ b/tensorflow/core/common_runtime/step_stats_collector.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/common_runtime/step_stats_collector.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/costmodel_manager.h" #include "tensorflow/core/framework/allocation_description.pb.h" #include "tensorflow/core/framework/op_kernel.h" @@ -23,6 +22,7 @@ limitations under the License. #include "tensorflow/core/framework/tracking_allocator.h" #include "tensorflow/core/graph/costmodel.h" #include "tensorflow/core/graph/graph.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/stringprintf.h" @@ -212,7 +212,7 @@ static int ExtractGpuWithStreamAll(string device_name) { scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture(); // Check that the digits are preceded by the 'device:GPU:' string scanner.OneLiteral(":UPG:ecived"); - absl::string_view capture; + StringPiece capture; bool matched = scanner.GetResult(nullptr, &capture); if (!matched) { @@ -241,7 +241,7 @@ static int ExtractGpuWithoutStream(string device_name) { scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture(); // Check that the digits are preceded by the 'device:GPU:' string scanner.OneLiteral(":UPG:ecived"); - absl::string_view capture; + StringPiece capture; bool matched = scanner.GetResult(nullptr, &capture); if (!matched) { @@ -276,7 +276,7 @@ void StepStatsCollector::BuildCostModel( const DeviceStepStats* hardware_stats; }; - std::unordered_map<absl::string_view, DeviceStats, StringPieceHasher> + std::unordered_map<StringPiece, DeviceStats, StringPieceHasher> per_device_stats; std::unordered_map<int, const DeviceStepStats*> gpu_hardware_stats; @@ -295,7 +295,7 @@ void StepStatsCollector::BuildCostModel( } for (auto& itr : per_device_stats) { - const absl::string_view device_name = itr.first; + const StringPiece device_name = itr.first; const int gpu_id = ExtractGpuWithoutStream(string(device_name)); if (gpu_id >= 0) { // Reference the gpu hardware stats in addition to the regular stats @@ -307,7 +307,7 @@ void StepStatsCollector::BuildCostModel( } for (auto itr : device_map) { - const absl::string_view device = itr.first; + const StringPiece device = itr.first; if (per_device_stats.find(device) == per_device_stats.end()) { continue; } @@ -316,8 +316,7 @@ void StepStatsCollector::BuildCostModel( CostModel* cm = cost_model_manager->FindOrCreateCostModel(graph); cm->IncrementUpdateTimes(); - std::unordered_map<absl::string_view, Node*, StringPieceHasher> - name_to_node; + std::unordered_map<StringPiece, Node*, StringPieceHasher> name_to_node; for (Node* n : graph->nodes()) { name_to_node.emplace(n->name(), n); } diff --git a/tensorflow/core/debug/BUILD b/tensorflow/core/debug/BUILD index 60f57e3fd31..591c22b8f62 100644 --- a/tensorflow/core/debug/BUILD +++ b/tensorflow/core/debug/BUILD @@ -109,7 +109,6 @@ tf_cuda_library( "//tensorflow/core:lib_internal", "//tensorflow/core:proto_text", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -133,7 +132,6 @@ tf_cuda_library( "//tensorflow/core:lib_internal", "//tensorflow/core:proto_text", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) diff --git a/tensorflow/core/debug/debug_graph_utils.cc b/tensorflow/core/debug/debug_graph_utils.cc index f35035ce929..5fc95a8f20d 100644 --- a/tensorflow/core/debug/debug_graph_utils.cc +++ b/tensorflow/core/debug/debug_graph_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/debug/debug_graph_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/memory_types.h" #include "tensorflow/core/framework/kernel_def.pb.h" #include "tensorflow/core/framework/node_def_builder.h" @@ -345,7 +344,7 @@ Status DebugNodeInserter::ParseDebugOpName( std::vector<string> attribute_segs = str_util::Split(arguments, ";"); for (const string& attribute_seg : attribute_segs) { - absl::string_view seg(attribute_seg); + StringPiece seg(attribute_seg); str_util::RemoveWhitespaceContext(&seg); if (seg.empty()) { continue; diff --git a/tensorflow/core/debug/debug_io_utils.cc b/tensorflow/core/debug/debug_io_utils.cc index 4b5a545f5c3..6994dec3b59 100644 --- a/tensorflow/core/debug/debug_io_utils.cc +++ b/tensorflow/core/debug/debug_io_utils.cc @@ -23,7 +23,6 @@ limitations under the License. #include <limits> #include <utility> #include <vector> -#include "absl/strings/string_view.h" #ifndef PLATFORM_WINDOWS #include "grpcpp/create_channel.h" @@ -309,7 +308,7 @@ Status ReadEventFromFile(const string& dump_file_path, Event* event) { return s; } - absl::string_view result; + StringPiece result; s = file->Read(0, file_size, &result, &(content)[0]); if (!s.ok()) { return s; diff --git a/tensorflow/core/distributed_runtime/BUILD b/tensorflow/core/distributed_runtime/BUILD index d2c63d0a3bc..37029f3f1a7 100644 --- a/tensorflow/core/distributed_runtime/BUILD +++ b/tensorflow/core/distributed_runtime/BUILD @@ -172,7 +172,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", "//tensorflow/core:worker_proto_cc", - "@com_google_absl//absl/strings", ], ) @@ -289,7 +288,6 @@ cc_library( "//tensorflow/core:core_cpu_internal", "//tensorflow/core:lib", "//tensorflow/core:worker_proto_cc", - "@com_google_absl//absl/strings", ], ) @@ -346,7 +344,6 @@ cc_library( "//tensorflow/core:master_proto_cc", "//tensorflow/core:protos_all_cc", "//tensorflow/core/debug:debug_graph_utils", - "@com_google_absl//absl/strings", ], ) @@ -400,7 +397,6 @@ cc_library( "//tensorflow/core:framework_internal", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc b/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc index 97e1639a42e..de6e4b4a7c5 100644 --- a/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc +++ b/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc @@ -18,7 +18,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/copy_tensor.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_mgr.h" @@ -145,8 +144,8 @@ BaseRemoteRendezvous::~BaseRemoteRendezvous() { // Returns true if "device_name" is a valid full name of local device // of the "worker". This helper is purely based on the worker name // and device name and does no lookups in the worker->device_mgr. -static bool IsLocalDevice(const absl::string_view worker_name, - const absl::string_view device_name) { +static bool IsLocalDevice(const StringPiece worker_name, + const StringPiece device_name) { return str_util::StartsWith(device_name, worker_name); } diff --git a/tensorflow/core/distributed_runtime/master_session.cc b/tensorflow/core/distributed_runtime/master_session.cc index 6c9bda15d1c..8e9eec1ed92 100644 --- a/tensorflow/core/distributed_runtime/master_session.cc +++ b/tensorflow/core/distributed_runtime/master_session.cc @@ -19,7 +19,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/common_runtime/profile_handler.h" #include "tensorflow/core/common_runtime/stats_publisher_interface.h" @@ -236,7 +235,7 @@ class MasterSession::ReffedClientGraph : public core::RefCounted { const bool is_partial_; const CallableOptions callable_opts_; WorkerCacheInterface* const worker_cache_; // Not owned. - std::unordered_map<absl::string_view, Node*, StringPieceHasher> name_to_node_; + std::unordered_map<StringPiece, Node*, StringPieceHasher> name_to_node_; const bool should_deregister_; std::atomic<int64> execution_count_ = {0}; @@ -297,14 +296,12 @@ class MasterSession::ReffedClientGraph : public core::RefCounted { // This is a generic method that handles Run, PartialRun, and RunCallable. template <class FetchListType, class ClientRequestType, class ClientResponseType> - Status RunPartitionsHelper(const std::unordered_map<absl::string_view, size_t, - StringPieceHasher>& feeds, - const FetchListType& fetches, const MasterEnv* env, - int64 step_id, int64 execution_count, - PerStepState* pss, CallOptions* call_opts, - const ClientRequestType& req, - ClientResponseType* resp, CancellationManager* cm, - bool is_last_partial_run); + Status RunPartitionsHelper( + const std::unordered_map<StringPiece, size_t, StringPieceHasher>& feeds, + const FetchListType& fetches, const MasterEnv* env, int64 step_id, + int64 execution_count, PerStepState* pss, CallOptions* call_opts, + const ClientRequestType& req, ClientResponseType* resp, + CancellationManager* cm, bool is_last_partial_run); // Deregisters the partitions on the workers. Called in the // destructor and does not wait for the rpc completion. @@ -732,7 +729,7 @@ Status MasterSession::ReffedClientGraph::RunPartitions( VLOG(2) << "RunPartitions step_id " << step_id << " execution_count " << execution_count; // Maps the names of fed tensors to their index in `req`. - std::unordered_map<absl::string_view, size_t, StringPieceHasher> feeds(3); + std::unordered_map<StringPiece, size_t, StringPieceHasher> feeds(3); for (size_t i = 0; i < req.num_feeds(); ++i) { if (!feeds.insert({req.feed_name(i), i}).second) { return errors::InvalidArgument("Duplicated feeds: ", req.feed_name(i)); @@ -756,7 +753,7 @@ Status MasterSession::ReffedClientGraph::RunPartitions( VLOG(2) << "RunPartitions step_id " << step_id << " execution_count " << execution_count; // Maps the names of fed tensors to their index in `req`. - std::unordered_map<absl::string_view, size_t, StringPieceHasher> feeds(3); + std::unordered_map<StringPiece, size_t, StringPieceHasher> feeds(3); for (size_t i = 0; i < callable_opts_.feed_size(); ++i) { if (!feeds.insert({callable_opts_.feed(i), i}).second) { // MakeCallable will fail if there are two feeds with the same name. diff --git a/tensorflow/core/distributed_runtime/remote_device.cc b/tensorflow/core/distributed_runtime/remote_device.cc index 26c145a5bab..a043c5dee6b 100644 --- a/tensorflow/core/distributed_runtime/remote_device.cc +++ b/tensorflow/core/distributed_runtime/remote_device.cc @@ -17,7 +17,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/distributed_runtime/worker_cache.h" @@ -34,9 +33,9 @@ namespace tensorflow { // parsing into one place. // // Parses and returns the local device part (e.g., cpu:0, gpu:4). -string GetLocalDeviceName(absl::string_view fullname) { +string GetLocalDeviceName(StringPiece fullname) { auto pos = fullname.rfind('/'); - CHECK_NE(pos, absl::string_view::npos); + CHECK_NE(pos, StringPiece::npos); fullname.remove_prefix(pos + 1); return string(fullname); } diff --git a/tensorflow/core/distributed_runtime/rpc/BUILD b/tensorflow/core/distributed_runtime/rpc/BUILD index 60e34c48f78..4a10d99a607 100644 --- a/tensorflow/core/distributed_runtime/rpc/BUILD +++ b/tensorflow/core/distributed_runtime/rpc/BUILD @@ -119,7 +119,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", "//tensorflow/core:worker_proto_cc", - "@com_google_absl//absl/strings", ], ) @@ -209,7 +208,6 @@ cc_library( "//tensorflow/core:master_proto_cc", "//tensorflow/core/distributed_runtime:call_options", "//tensorflow/core/distributed_runtime:master_interface", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -228,7 +226,6 @@ cc_library( "//tensorflow/core:lib_internal", "//tensorflow/core:master_proto_cc", "//tensorflow/core/distributed_runtime:master", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -257,7 +254,6 @@ cc_library( "//tensorflow/core/distributed_runtime:worker_cache", "//tensorflow/core/distributed_runtime:worker_env", "//tensorflow/core/distributed_runtime:worker_interface", - "@com_google_absl//absl/strings", ], ) @@ -320,7 +316,6 @@ tf_cc_binary( "//tensorflow/core:protos_all_cc", "//tensorflow/core/distributed_runtime:server_lib", "//tensorflow/core/kernels:data_flow", - "@com_google_absl//absl/strings", ], ) @@ -346,7 +341,6 @@ tf_cc_binary( "//tensorflow/core/kernels:matmul_op", "//tensorflow/core/kernels:reduction_ops", "//tensorflow/core/kernels:variable_ops", - "@com_google_absl//absl/strings", ], ) @@ -485,7 +479,6 @@ tf_cuda_cc_test( "//tensorflow/core/kernels:dense_update_ops", "//tensorflow/core/kernels:matmul_op", "//tensorflow/core/kernels:variable_ops", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_master_service.cc b/tensorflow/core/distributed_runtime/rpc/grpc_master_service.cc index 23cbba58c52..127dea2882a 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_master_service.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_master_service.cc @@ -33,7 +33,6 @@ limitations under the License. #include "grpcpp/alarm.h" #include "grpcpp/server_builder.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/distributed_runtime/master.h" #include "tensorflow/core/distributed_runtime/rpc/async_service_interface.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_call.h" @@ -287,12 +286,12 @@ class GrpcMasterService : public AsyncServiceInterface { // Start tracing, including the ID attached to the RPC. tracing::ScopedActivity* TraceRpc( - absl::string_view name, + StringPiece name, const std::multimap<::grpc::string_ref, ::grpc::string_ref>& metadata) { - absl::string_view id; + StringPiece id; auto it = metadata.find(GrpcIdKey()); if (it != metadata.end()) { - id = absl::string_view(it->second.data(), it->second.size()); + id = StringPiece(it->second.data(), it->second.size()); } return new tracing::ScopedActivity(name, id); } diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_remote_master.cc b/tensorflow/core/distributed_runtime/rpc/grpc_remote_master.cc index bc6a97af081..b832a2115cb 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_remote_master.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_remote_master.cc @@ -17,7 +17,6 @@ limitations under the License. #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/core/distributed_runtime/call_options.h" #include "tensorflow/core/distributed_runtime/master_interface.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_master_service_impl.h" @@ -120,7 +119,7 @@ class GrpcRemoteMaster : public MasterInterface { private: // Start tracing, attaching a unique ID to both the trace and the RPC. - tracing::ScopedActivity TraceRpc(absl::string_view name, + tracing::ScopedActivity TraceRpc(StringPiece name, ::grpc::ClientContext* ctx) { string trace_id = strings::StrCat(tracing::GetUniqueArg()); ctx->AddMetadata(GrpcIdKey(), trace_id); diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_session_test.cc b/tensorflow/core/distributed_runtime/rpc/grpc_session_test.cc index 358db1e2406..fc601991a24 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_session_test.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_session_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/distributed_runtime/rpc/grpc_session.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_testlib.h" #include "tensorflow/core/framework/graph.pb.h" @@ -668,7 +667,7 @@ TEST(GrpcSessionTest, LongErrorMessage) { auto a = test::graph::Constant(&g, Tensor()); a->set_assigned_device_name(dev_a); std::vector<char> long_string_buffer(1024 * 1024, 'x'); - absl::string_view long_string(long_string_buffer.data(), 1024 * 1024); + StringPiece long_string(long_string_buffer.data(), 1024 * 1024); string name = strings::StrCat(long_string, "fantasia!"); auto a_err = test::graph::Error(&g, a, name); a_err->set_assigned_device_name(dev_a); diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.cc b/tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.cc index 951f2d026cd..159435fd7db 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.h" #include "grpcpp/support/byte_buffer.h" #include "grpcpp/support/slice.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/dma_helper.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.pb.h" @@ -159,7 +158,7 @@ void EncodeTensorToByteBuffer(bool is_dead, const Tensor& val, io::ProtoEncodeHelper e_skeleton(skeleton.data(), skeleton.size()); EncodeSkeleton(val, &e_skeleton); - absl::string_view tdata = val.tensor_data(); + StringPiece tdata = val.tensor_data(); uint32 overall_tensor_proto_bytesize = (e_skeleton.size() + VarLengthEncodingSize(TensorProto::kTensorContentFieldNumber, @@ -198,7 +197,7 @@ void EncodeTensorToByteBuffer(bool is_dead, const Tensor& val, e.WriteVarlengthBeginning(RecvTensorResponse::kTensorFieldNumber, overall_tensor_proto_bytesize); // (C) - e.WriteRawBytes(absl::string_view(e_skeleton.data(), e_skeleton.size())); + e.WriteRawBytes(StringPiece(e_skeleton.data(), e_skeleton.size())); // (D1) & (D2) e.WriteVarlengthBeginning(TensorProto::kTensorContentFieldNumber, tdata.size()); diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server.cc b/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server.cc index a011cad596d..e52b2574117 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server.cc @@ -20,7 +20,6 @@ limitations under the License. #include "grpcpp/security/credentials.h" #include "grpcpp/server_builder.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/distributed_runtime/server_lib.h" #include "tensorflow/core/lib/core/errors.h" @@ -57,7 +56,7 @@ Status FillServerDef(const string& cluster_spec, const string& job_name, const string& job_name = job_pieces[0]; job_def->set_name(job_name); // Does a bit more validation of the tasks_per_replica. - const absl::string_view spec = job_pieces[1]; + const StringPiece spec = job_pieces[1]; // job_str is of form <job_name>|<host_ports>. const std::vector<string> host_ports = str_util::Split(spec, ';'); for (size_t i = 0; i < host_ports.size(); ++i) { diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_testlib_server.cc b/tensorflow/core/distributed_runtime/rpc/grpc_testlib_server.cc index 12688635627..33cbadda0a1 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_testlib_server.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_testlib_server.cc @@ -19,7 +19,6 @@ limitations under the License. #include "grpcpp/security/credentials.h" #include "grpcpp/server_builder.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/distributed_runtime/server_lib.h" #include "tensorflow/core/lib/core/errors.h" @@ -51,7 +50,7 @@ Status FillServerDef(const string& job_spec, const string& job_name, CHECK_EQ(2, job_pieces.size()) << job_str; job_def->set_name(job_pieces[0]); // Does a bit more validation of the tasks_per_replica. - const absl::string_view spec = job_pieces[1]; + const StringPiece spec = job_pieces[1]; // job_str is of form <job_name>|<host_ports>. const std::vector<string> host_ports = str_util::Split(spec, ';'); uint32 tasks_per_replica = host_ports.size(); diff --git a/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc b/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc index 0e7484ed03e..b8cb5385038 100644 --- a/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc +++ b/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc @@ -17,7 +17,6 @@ limitations under the License. #include <unordered_set> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/dma_helper.h" @@ -59,7 +58,7 @@ class RpcRecvTensorCall : public BaseRecvTensorCall { public: RpcRecvTensorCall() : wi_(nullptr), dst_device_(nullptr) {} - void Init(WorkerInterface* wi, int64 step_id, absl::string_view key, + void Init(WorkerInterface* wi, int64 step_id, StringPiece key, AllocatorAttributes alloc_attrs, Device* dst_device, const Rendezvous::Args& recv_args, Rendezvous::DoneCallback done) { wi_ = wi; diff --git a/tensorflow/core/distributed_runtime/tensor_coding.cc b/tensorflow/core/distributed_runtime/tensor_coding.cc index a61dca6f957..fe2d1a12934 100644 --- a/tensorflow/core/distributed_runtime/tensor_coding.cc +++ b/tensorflow/core/distributed_runtime/tensor_coding.cc @@ -17,7 +17,6 @@ limitations under the License. #include "google/protobuf/any.pb.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h" @@ -197,7 +196,7 @@ bool TensorResponse::ParseTensorSubmessage( seen_tensor_content = true; TensorShape shape(tensor_meta->tensor_shape()); Tensor t(allocator_, tensor_meta->dtype(), shape); - absl::string_view buf = t.tensor_data(); + StringPiece buf = t.tensor_data(); if (static_cast<size_t>(num_bytes) != buf.size()) return false; // TODO(jeff,sanjay): Figure out a way to avoid this copy if // the underlying ZeroCopyInputStream data is properly aligned diff --git a/tensorflow/core/example/feature_util.h b/tensorflow/core/example/feature_util.h index 49cd28a6ed3..016d1a92c18 100644 --- a/tensorflow/core/example/feature_util.h +++ b/tensorflow/core/example/feature_util.h @@ -104,9 +104,9 @@ limitations under the License. #include <type_traits> #include "absl/base/macros.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/example/example.pb.h" #include "tensorflow/core/example/feature.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/types.h" @@ -170,7 +170,7 @@ template <> struct is_string<string> : std::true_type {}; template <> -struct is_string<::absl::string_view> : std::true_type {}; +struct is_string<::tensorflow::StringPiece> : std::true_type {}; template <typename ValueType> struct FeatureTrait< diff --git a/tensorflow/core/framework/attr_value_util.cc b/tensorflow/core/framework/attr_value_util.cc index aa6e6f38a70..79966f06922 100644 --- a/tensorflow/core/framework/attr_value_util.cc +++ b/tensorflow/core/framework/attr_value_util.cc @@ -18,13 +18,13 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb_text.h" #include "tensorflow/core/framework/tensor.pb_text.h" #include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.pb_text.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/proto_serialization.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -187,8 +187,8 @@ string SummarizeString(const string& str) { // If the string is long, replace the middle with ellipses. constexpr int kMaxStringSummarySize = 80; if (escaped.size() >= kMaxStringSummarySize) { - absl::string_view prefix(escaped); - absl::string_view suffix = prefix; + StringPiece prefix(escaped); + StringPiece suffix = prefix; prefix.remove_suffix(escaped.size() - 10); suffix.remove_prefix(escaped.size() - 10); return strings::StrCat("\"", prefix, "...", suffix, "\""); @@ -288,7 +288,7 @@ string SummarizeAttrValue(const AttrValue& attr_value) { return "<Unknown AttrValue type>"; // Prevent missing return warning } -Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type) { +Status AttrValueHasType(const AttrValue& attr_value, StringPiece type) { int num_set = 0; #define VALIDATE_FIELD(name, type_string, oneof_case) \ @@ -386,8 +386,7 @@ Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type) { return Status::OK(); } -bool ParseAttrValue(absl::string_view type, absl::string_view text, - AttrValue* out) { +bool ParseAttrValue(StringPiece type, StringPiece text, AttrValue* out) { // Parse type. string field_name; bool is_list = str_util::ConsumePrefix(&type, "list("); @@ -421,7 +420,7 @@ bool ParseAttrValue(absl::string_view type, absl::string_view text, if (is_list) { // TextFormat parser considers "i: 7" to be the same as "i: [7]", // but we only want to allow list values with []. - absl::string_view cleaned = text; + StringPiece cleaned = text; str_util::RemoveLeadingWhitespace(&cleaned); str_util::RemoveTrailingWhitespace(&cleaned); if (cleaned.size() < 2 || cleaned[0] != '[' || @@ -474,12 +473,11 @@ DEFINE_SET_ATTR_VALUE_LIST(const std::vector<bool>&, b) DEFINE_SET_ATTR_VALUE_LIST(std::initializer_list<bool>, b) DEFINE_SET_ATTR_VALUE_BOTH(DataType, type) -void SetAttrValue(absl::string_view value, AttrValue* out) { +void SetAttrValue(StringPiece value, AttrValue* out) { out->set_s(value.data(), value.size()); } -void SetAttrValue(const gtl::ArraySlice<absl::string_view> value, - AttrValue* out) { +void SetAttrValue(const gtl::ArraySlice<StringPiece> value, AttrValue* out) { out->mutable_list()->Clear(); // Create list() even if value empty. for (const auto& v : value) { out->mutable_list()->add_s(v.data(), v.size()); diff --git a/tensorflow/core/framework/attr_value_util.h b/tensorflow/core/framework/attr_value_util.h index c9f2b334c82..9fce488793f 100644 --- a/tensorflow/core/framework/attr_value_util.h +++ b/tensorflow/core/framework/attr_value_util.h @@ -20,12 +20,12 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/partial_tensor_shape.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" namespace tensorflow { @@ -39,7 +39,7 @@ class NameAttrList; string SummarizeAttrValue(const AttrValue& attr_value); // Generates an error if attr_value doesn't have the indicated attr type. -Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type); +Status AttrValueHasType(const AttrValue& attr_value, StringPiece type); // Converts a text proto value from "text" into the field of *out // indicated by "type" (e.g. from the type field of an AttrDef). @@ -48,13 +48,12 @@ Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type); // * If type:"list(string)" and text:"['foo', 'bar']", // then *out is set to "list { s: ['foo', 'bar'] }" // Returns true on success. -bool ParseAttrValue(absl::string_view type, absl::string_view text, - AttrValue* out); +bool ParseAttrValue(StringPiece type, StringPiece text, AttrValue* out); // Sets *out based on the type of value. void SetAttrValue(const string& value, AttrValue* out); void SetAttrValue(const char* value, AttrValue* out); -void SetAttrValue(absl::string_view value, AttrValue* out); +void SetAttrValue(StringPiece value, AttrValue* out); void SetAttrValue(int64 value, AttrValue* out); void SetAttrValue(int32 value, AttrValue* out); void SetAttrValue(float value, AttrValue* out); @@ -70,7 +69,7 @@ void SetAttrValue(const NameAttrList& value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<string> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<const char*> value, AttrValue* out); -void SetAttrValue(gtl::ArraySlice<absl::string_view> value, AttrValue* out); +void SetAttrValue(gtl::ArraySlice<StringPiece> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<int64> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<int32> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<float> value, AttrValue* out); diff --git a/tensorflow/core/framework/dataset.cc b/tensorflow/core/framework/dataset.cc index d3dcc0377ab..284dafb886e 100644 --- a/tensorflow/core/framework/dataset.cc +++ b/tensorflow/core/framework/dataset.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/framework/dataset.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/graph/graph_def_builder.h" #include "tensorflow/core/graph/node_builder.h" @@ -78,7 +77,7 @@ Status GraphDefBuilderWrapper::AddDataset( const DatasetBase* dataset, const std::vector<std::pair<size_t, Node*>>& inputs, const std::vector<std::pair<size_t, gtl::ArraySlice<Node*>>>& list_inputs, - const std::vector<std::pair<absl::string_view, AttrValue>>& attrs, + const std::vector<std::pair<StringPiece, AttrValue>>& attrs, Node** output) { const string& name = dataset->name(); std::unique_ptr<const GraphDefBuilder::Options> opts( diff --git a/tensorflow/core/framework/dataset.h b/tensorflow/core/framework/dataset.h index 4bb0f326cb2..964a7d5f8c2 100644 --- a/tensorflow/core/framework/dataset.h +++ b/tensorflow/core/framework/dataset.h @@ -18,7 +18,6 @@ limitations under the License. #include <deque> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/dataset_stateful_op_whitelist.h" @@ -58,10 +57,10 @@ class SerializationContext; // Used for restoring iterator state. class IteratorStateReader { public: - virtual Status ReadScalar(absl::string_view key, int64* val) = 0; - virtual Status ReadScalar(absl::string_view key, string* val) = 0; - virtual Status ReadTensor(absl::string_view key, Tensor* val) = 0; - virtual bool Contains(absl::string_view key) = 0; + virtual Status ReadScalar(StringPiece key, int64* val) = 0; + virtual Status ReadScalar(StringPiece key, string* val) = 0; + virtual Status ReadTensor(StringPiece key, Tensor* val) = 0; + virtual bool Contains(StringPiece key) = 0; virtual ~IteratorStateReader() {} }; @@ -70,9 +69,9 @@ class IteratorStateReader { // Used for saving iterator state. class IteratorStateWriter { public: - virtual Status WriteScalar(absl::string_view key, const int64 val) = 0; - virtual Status WriteScalar(absl::string_view key, const string& val) = 0; - virtual Status WriteTensor(absl::string_view key, const Tensor& val) = 0; + virtual Status WriteScalar(StringPiece key, const int64 val) = 0; + virtual Status WriteScalar(StringPiece key, const string& val) = 0; + virtual Status WriteTensor(StringPiece key, const Tensor& val) = 0; virtual ~IteratorStateWriter() {} }; @@ -156,10 +155,10 @@ class GraphDefBuilderWrapper { // `*output` contains a pointer to the output `Node`. It is guaranteed to be // non-null if the method returns with an OK status. // The returned Node pointer is owned by the backing Graph of GraphDefBuilder. - Status AddDataset( - const DatasetBase* dataset, const std::vector<Node*>& inputs, - const std::vector<std::pair<absl::string_view, AttrValue>>& attrs, - Node** output) { + Status AddDataset(const DatasetBase* dataset, + const std::vector<Node*>& inputs, + const std::vector<std::pair<StringPiece, AttrValue>>& attrs, + Node** output) { std::vector<std::pair<size_t, Node*>> enumerated_inputs(inputs.size()); for (int i = 0; i < inputs.size(); i++) { enumerated_inputs[i] = std::make_pair(i, inputs[i]); @@ -171,7 +170,7 @@ class GraphDefBuilderWrapper { const DatasetBase* dataset, const std::vector<std::pair<size_t, Node*>>& inputs, const std::vector<std::pair<size_t, gtl::ArraySlice<Node*>>>& list_inputs, - const std::vector<std::pair<absl::string_view, AttrValue>>& attrs, + const std::vector<std::pair<StringPiece, AttrValue>>& attrs, Node** output); // Adds a user-defined function with name `function_name` to the graph and @@ -727,8 +726,7 @@ class DatasetOpKernel : public OpKernel { template <typename T> Status ParseScalarArgument(OpKernelContext* ctx, - const absl::string_view& argument_name, - T* output) { + const StringPiece& argument_name, T* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); if (!TensorShapeUtils::IsScalar(argument_t->shape())) { @@ -740,7 +738,7 @@ class DatasetOpKernel : public OpKernel { template <typename T> Status ParseVectorArgument(OpKernelContext* ctx, - const absl::string_view& argument_name, + const StringPiece& argument_name, std::vector<T>* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); diff --git a/tensorflow/core/framework/device_base.h b/tensorflow/core/framework/device_base.h index f6c4632efa7..446c31b17f2 100644 --- a/tensorflow/core/framework/device_base.h +++ b/tensorflow/core/framework/device_base.h @@ -21,11 +21,11 @@ limitations under the License. #include <vector> #include "absl/base/macros.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/refcount.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/logging.h" namespace Eigen { @@ -86,9 +86,8 @@ class DeviceContext : public core::RefCounted { // device_tensor into "cpu_tensor". "cpu_tensor" must be allocated // to be of the same size as "device_tensor". virtual void CopyDeviceTensorToCPU(const Tensor* device_tensor, - absl::string_view tensor_name, - Device* device, Tensor* cpu_tensor, - StatusCallback done) { + StringPiece tensor_name, Device* device, + Tensor* cpu_tensor, StatusCallback done) { done(errors::Internal("Unrecognized device type in device-to-CPU Copy")); } diff --git a/tensorflow/core/framework/function.cc b/tensorflow/core/framework/function.cc index df1c797a315..4ad6fd00dac 100644 --- a/tensorflow/core/framework/function.cc +++ b/tensorflow/core/framework/function.cc @@ -20,7 +20,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/function.pb_text.h" #include "tensorflow/core/framework/graph.pb.h" @@ -505,9 +504,9 @@ string Print(const NodeDef& n) { strings::StrAppend(&out, "[", str_util::Join(entries, ", "), "]"); } strings::StrAppend(&out, "("); - std::vector<absl::string_view> dat; + std::vector<StringPiece> dat; std::vector<string> dep; - for (absl::string_view s : n.input()) { + for (StringPiece s : n.input()) { if (str_util::ConsumePrefix(&s, "^")) { dep.emplace_back(s); } else { @@ -648,7 +647,7 @@ Status InstantiateFunction(const FunctionDef& fdef, AttrSlice attr_values, } } - auto substitute = [attr_values](absl::string_view name, AttrValue* val) { + auto substitute = [attr_values](StringPiece name, AttrValue* val) { if (const AttrValue* v = attr_values.Find(name)) { *val = *v; return true; @@ -1193,8 +1192,7 @@ Status FunctionLibraryDefinition::LookUp( return default_registry_->LookUp(op, op_reg_data); } -string FunctionLibraryDefinition::UniqueFunctionName( - absl::string_view prefix) const { +string FunctionLibraryDefinition::UniqueFunctionName(StringPiece prefix) const { tf_shared_lock l(mu_); int index = 0; string name = strings::StrCat(prefix, index); @@ -1272,8 +1270,7 @@ GET_ATTR(string) GET_ATTR(bool) #undef GET_ATTR -void FunctionDefHelper::AttrValueWrapper::InitFromString( - absl::string_view val) { +void FunctionDefHelper::AttrValueWrapper::InitFromString(StringPiece val) { if (val.size() >= 2 && val[0] == '$') { proto.set_placeholder(val.data() + 1, val.size() - 1); } else { diff --git a/tensorflow/core/framework/function.h b/tensorflow/core/framework/function.h index b2a44167745..fcc62037295 100644 --- a/tensorflow/core/framework/function.h +++ b/tensorflow/core/framework/function.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_CORE_FRAMEWORK_FUNCTION_H_ #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/function.pb.h" @@ -93,7 +92,7 @@ class FunctionDefHelper { } private: - void InitFromString(absl::string_view val); + void InitFromString(StringPiece val); }; // Constructs an AttrValue.func given the "name" and "attrs". @@ -182,8 +181,7 @@ inline FunctionDefHelper::AttrValueWrapper::AttrValueWrapper( } template <> -inline FunctionDefHelper::AttrValueWrapper::AttrValueWrapper( - absl::string_view val) { +inline FunctionDefHelper::AttrValueWrapper::AttrValueWrapper(StringPiece val) { InitFromString(val); } @@ -376,7 +374,7 @@ class FunctionLibraryDefinition : public OpRegistryInterface { // Generates new function name with the specified prefix that is unique // across this library. - string UniqueFunctionName(absl::string_view prefix) const LOCKS_EXCLUDED(mu_); + string UniqueFunctionName(StringPiece prefix) const LOCKS_EXCLUDED(mu_); // Ops created for function arguments bear the name given by `kArgOp`; those // created for return values bear the name given by `kRetOp`. diff --git a/tensorflow/core/framework/function_testlib.cc b/tensorflow/core/framework/function_testlib.cc index 2ea4dee9edc..0445c242e95 100644 --- a/tensorflow/core/framework/function_testlib.cc +++ b/tensorflow/core/framework/function_testlib.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/framework/function_testlib.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/tensor_testutil.h" @@ -46,8 +45,7 @@ GraphDef GDef(gtl::ArraySlice<NodeDef> nodes, } // Helper to construct a NodeDef. -NodeDef NDef(absl::string_view name, absl::string_view op, - gtl::ArraySlice<string> inputs, +NodeDef NDef(StringPiece name, StringPiece op, gtl::ArraySlice<string> inputs, gtl::ArraySlice<std::pair<string, FDH::AttrValueWrapper>> attrs, const string& device) { NodeDef n; diff --git a/tensorflow/core/framework/function_testlib.h b/tensorflow/core/framework/function_testlib.h index aacd555cb39..a01743423bb 100644 --- a/tensorflow/core/framework/function_testlib.h +++ b/tensorflow/core/framework/function_testlib.h @@ -18,7 +18,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/function.pb.h" @@ -49,8 +48,7 @@ class Attrs { // Helper to construct a NodeDef. NodeDef NDef( - absl::string_view name, absl::string_view op, - gtl::ArraySlice<string> inputs, + StringPiece name, StringPiece op, gtl::ArraySlice<string> inputs, gtl::ArraySlice<std::pair<string, FunctionDefHelper::AttrValueWrapper>> attrs = {}, const string& device = ""); diff --git a/tensorflow/core/framework/node_def_builder.cc b/tensorflow/core/framework/node_def_builder.cc index 898a7e716bb..348a825af91 100644 --- a/tensorflow/core/framework/node_def_builder.cc +++ b/tensorflow/core/framework/node_def_builder.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/framework/node_def_builder.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/op_def_util.h" #include "tensorflow/core/lib/core/errors.h" @@ -24,21 +23,20 @@ limitations under the License. namespace tensorflow { -NodeDefBuilder::NodeOut::NodeOut(absl::string_view n, int i, DataType dt) +NodeDefBuilder::NodeOut::NodeOut(StringPiece n, int i, DataType dt) : node(n), index(i), data_type(dt) {} NodeDefBuilder::NodeOut::NodeOut() { // uninitialized, call Reset() before use. } -void NodeDefBuilder::NodeOut::Reset(absl::string_view n, int i, DataType dt) { +void NodeDefBuilder::NodeOut::Reset(StringPiece n, int i, DataType dt) { node = string(n); index = i; data_type = dt; } -NodeDefBuilder::NodeDefBuilder(absl::string_view name, - absl::string_view op_name, +NodeDefBuilder::NodeDefBuilder(StringPiece name, StringPiece op_name, const OpRegistryInterface* op_registry) { node_def_.set_name(string(name)); const Status status = op_registry->LookUpOpDef(string(op_name), &op_def_); @@ -50,7 +48,7 @@ NodeDefBuilder::NodeDefBuilder(absl::string_view name, } } -NodeDefBuilder::NodeDefBuilder(absl::string_view name, const OpDef* op_def) +NodeDefBuilder::NodeDefBuilder(StringPiece name, const OpDef* op_def) : op_def_(op_def) { node_def_.set_name(string(name)); Initialize(); @@ -86,7 +84,7 @@ NodeDefBuilder& NodeDefBuilder::Input(FakeInputFunctor fake_input) { return *this; } -NodeDefBuilder& NodeDefBuilder::Input(absl::string_view src_node, int src_index, +NodeDefBuilder& NodeDefBuilder::Input(StringPiece src_node, int src_index, DataType dt) { const OpDef::ArgDef* arg = NextArgDef(); if (arg != nullptr) SingleInput(arg, src_node, src_index, dt); @@ -106,7 +104,7 @@ NodeDefBuilder& NodeDefBuilder::Input(gtl::ArraySlice<NodeOut> src_list) { } void NodeDefBuilder::SingleInput(const OpDef::ArgDef* input_arg, - absl::string_view src_node, int src_index, + StringPiece src_node, int src_index, DataType dt) { AddInput(src_node, src_index); @@ -163,7 +161,7 @@ void NodeDefBuilder::ListInput(const OpDef::ArgDef* input_arg, } } -void NodeDefBuilder::AddInput(absl::string_view src_node, int src_index) { +void NodeDefBuilder::AddInput(StringPiece src_node, int src_index) { if (src_node.empty()) { errors_.push_back("Empty input node name"); } else if (src_node[0] == '^') { @@ -194,12 +192,12 @@ void NodeDefBuilder::VerifyInputRef(const OpDef::ArgDef* input_arg, } } -NodeDefBuilder& NodeDefBuilder::ControlInput(absl::string_view src_node) { +NodeDefBuilder& NodeDefBuilder::ControlInput(StringPiece src_node) { control_inputs_.emplace_back(src_node); return *this; } -NodeDefBuilder& NodeDefBuilder::Device(absl::string_view device_spec) { +NodeDefBuilder& NodeDefBuilder::Device(StringPiece device_spec) { node_def_.set_device(string(device_spec)); return *this; } @@ -250,8 +248,7 @@ Status NodeDefBuilder::Finalize(NodeDef* node_def) const { } } -NodeDefBuilder& NodeDefBuilder::Attr(absl::string_view name, - const AttrValue& value) { +NodeDefBuilder& NodeDefBuilder::Attr(StringPiece name, const AttrValue& value) { if (const AttrValue* found = AttrSlice(node_def_).Find(name)) { if (!AreAttrValuesEqual(*found, value)) { errors_.push_back(strings::StrCat("Inconsistent values for attr '", name, @@ -264,13 +261,13 @@ NodeDefBuilder& NodeDefBuilder::Attr(absl::string_view name, return *this; } -#define ATTR(T) \ - NodeDefBuilder& NodeDefBuilder::Attr(absl::string_view name, T value) { \ - AttrValue attr_value; \ - SetAttrValue(value, &attr_value); \ - return Attr(name, attr_value); \ +#define ATTR(T) \ + NodeDefBuilder& NodeDefBuilder::Attr(StringPiece name, T value) { \ + AttrValue attr_value; \ + SetAttrValue(value, &attr_value); \ + return Attr(name, attr_value); \ } -ATTR(absl::string_view) +ATTR(StringPiece) ATTR(const char*) ATTR(int32) ATTR(int64) @@ -282,7 +279,7 @@ ATTR(const PartialTensorShape&) ATTR(const Tensor&) ATTR(const TensorProto&) ATTR(const NameAttrList&) -ATTR(gtl::ArraySlice<absl::string_view>) +ATTR(gtl::ArraySlice<StringPiece>) ATTR(gtl::ArraySlice<const char*>) ATTR(gtl::ArraySlice<string>) ATTR(gtl::ArraySlice<int32>) diff --git a/tensorflow/core/framework/node_def_builder.h b/tensorflow/core/framework/node_def_builder.h index f8af6c0710f..ad07ec54800 100644 --- a/tensorflow/core/framework/node_def_builder.h +++ b/tensorflow/core/framework/node_def_builder.h @@ -18,7 +18,6 @@ limitations under the License. #include <functional> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_util.h" @@ -51,9 +50,9 @@ class NodeDefBuilder { public: // To specify an output to be consumed by one of the Input() methods below. struct NodeOut { - NodeOut(absl::string_view n, int i, DataType dt); + NodeOut(StringPiece n, int i, DataType dt); NodeOut(); // uninitialized, call Reset() before use. - void Reset(absl::string_view n, int i, DataType dt); + void Reset(StringPiece n, int i, DataType dt); string node; int index; DataType data_type; @@ -63,16 +62,16 @@ class NodeDefBuilder { // the Op plus a registry) for the NodeDef. Other fields are // specified by calling the methods below. // REQUIRES: The OpDef must satisfy ValidateOpDef(). - NodeDefBuilder(absl::string_view name, absl::string_view op_name, + NodeDefBuilder(StringPiece name, StringPiece op_name, const OpRegistryInterface* op_registry = OpRegistry::Global()); // REQUIRES: in addition, *op_def must outlive *this. - NodeDefBuilder(absl::string_view name, const OpDef* op_def); + NodeDefBuilder(StringPiece name, const OpDef* op_def); // You must call one Input() function per input_arg in the Op, // *and in the same order as the input_args appear in the OpDef.* // For inputs that take a single tensor. - NodeDefBuilder& Input(absl::string_view src_node, int src_index, DataType dt); + NodeDefBuilder& Input(StringPiece src_node, int src_index, DataType dt); NodeDefBuilder& Input(const NodeOut& src); // For inputs that take a list of tensors. @@ -82,49 +81,45 @@ class NodeDefBuilder { NodeDefBuilder& Input(FakeInputFunctor fake_input); // Specify that this node must only run after src_node. - NodeDefBuilder& ControlInput(absl::string_view src_node); + NodeDefBuilder& ControlInput(StringPiece src_node); // Constrains what devices this node may be scheduled on. - NodeDefBuilder& Device(absl::string_view device_spec); + NodeDefBuilder& Device(StringPiece device_spec); // Sets the attr, if not already set. If already set with a different // value, an error will be returned from Finalize(). - NodeDefBuilder& Attr(absl::string_view name, const AttrValue& value); - NodeDefBuilder& Attr(absl::string_view name, absl::string_view value); - NodeDefBuilder& Attr(absl::string_view name, const char* value); - NodeDefBuilder& Attr(absl::string_view name, int32 value); - NodeDefBuilder& Attr(absl::string_view name, int64 value); - NodeDefBuilder& Attr(absl::string_view name, float value); - NodeDefBuilder& Attr(absl::string_view name, double value); - NodeDefBuilder& Attr(absl::string_view name, bool value); - NodeDefBuilder& Attr(absl::string_view name, DataType value); - NodeDefBuilder& Attr(absl::string_view name, const PartialTensorShape& value); - NodeDefBuilder& Attr(absl::string_view name, const Tensor& value); - NodeDefBuilder& Attr(absl::string_view name, const TensorProto& value); - NodeDefBuilder& Attr(absl::string_view name, const NameAttrList& value); - NodeDefBuilder& Attr(absl::string_view name, - gtl::ArraySlice<absl::string_view> value); - NodeDefBuilder& Attr(absl::string_view name, - gtl::ArraySlice<const char*> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<string> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<int32> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<int64> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<float> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<bool> value); - NodeDefBuilder& Attr(absl::string_view name, const std::vector<bool>& value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<DataType> value); - NodeDefBuilder& Attr(absl::string_view name, - gtl::ArraySlice<TensorShape> value); - NodeDefBuilder& Attr(absl::string_view name, + NodeDefBuilder& Attr(StringPiece name, const AttrValue& value); + NodeDefBuilder& Attr(StringPiece name, StringPiece value); + NodeDefBuilder& Attr(StringPiece name, const char* value); + NodeDefBuilder& Attr(StringPiece name, int32 value); + NodeDefBuilder& Attr(StringPiece name, int64 value); + NodeDefBuilder& Attr(StringPiece name, float value); + NodeDefBuilder& Attr(StringPiece name, double value); + NodeDefBuilder& Attr(StringPiece name, bool value); + NodeDefBuilder& Attr(StringPiece name, DataType value); + NodeDefBuilder& Attr(StringPiece name, const PartialTensorShape& value); + NodeDefBuilder& Attr(StringPiece name, const Tensor& value); + NodeDefBuilder& Attr(StringPiece name, const TensorProto& value); + NodeDefBuilder& Attr(StringPiece name, const NameAttrList& value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<StringPiece> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<const char*> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<string> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<int32> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<int64> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<float> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<bool> value); + NodeDefBuilder& Attr(StringPiece name, const std::vector<bool>& value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<DataType> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<TensorShape> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<PartialTensorShape> value); - NodeDefBuilder& Attr(absl::string_view name, + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<TensorShapeProto> value); - NodeDefBuilder& Attr(absl::string_view name, gtl::ArraySlice<Tensor> value); - NodeDefBuilder& Attr(absl::string_view name, - gtl::ArraySlice<NameAttrList> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<Tensor> value); + NodeDefBuilder& Attr(StringPiece name, gtl::ArraySlice<NameAttrList> value); template <class T> - NodeDefBuilder& Attr(absl::string_view name, std::initializer_list<T> value) { + NodeDefBuilder& Attr(StringPiece name, std::initializer_list<T> value) { return Attr(name, gtl::ArraySlice<T>(value)); } @@ -151,13 +146,13 @@ class NodeDefBuilder { bool NextArgAvailable(); // These do the main work of the Input() methods. - void SingleInput(const OpDef::ArgDef* input_arg, absl::string_view src_node, + void SingleInput(const OpDef::ArgDef* input_arg, StringPiece src_node, int src_index, DataType dt); void ListInput(const OpDef::ArgDef* input_arg, gtl::ArraySlice<NodeOut> src_list); // Add "src_node:src_index" to the list of inputs in the node_def_. - void AddInput(absl::string_view src_node, int src_index); + void AddInput(StringPiece src_node, int src_index); // Generate an error if you can't pass dt when expected is expected. void VerifyInputType(const OpDef::ArgDef* input_arg, DataType expected, diff --git a/tensorflow/core/framework/node_def_builder_test.cc b/tensorflow/core/framework/node_def_builder_test.cc index 45168e95808..cc583df348b 100644 --- a/tensorflow/core/framework/node_def_builder_test.cc +++ b/tensorflow/core/framework/node_def_builder_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <memory> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/fake_input.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/op_def_builder.h" @@ -51,8 +50,7 @@ class NodeDefBuilderTest : public ::testing::Test { // expectations. void ExpectSuccess(const NodeDefBuilder& builder, DataTypeSlice expected_in_types, - DataTypeSlice expected_out_types, - absl::string_view proto) { + DataTypeSlice expected_out_types, StringPiece proto) { NodeDef node_def; Status status = builder.Finalize(&node_def); TF_EXPECT_OK(status); diff --git a/tensorflow/core/framework/node_def_util.cc b/tensorflow/core/framework/node_def_util.cc index 497da45d3df..43ac1d0ada3 100644 --- a/tensorflow/core/framework/node_def_util.cc +++ b/tensorflow/core/framework/node_def_util.cc @@ -19,7 +19,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/graph.pb_text.h" #include "tensorflow/core/framework/node_def.pb.h" @@ -51,7 +50,7 @@ AttrSlice::AttrSlice(const NodeDef& node_def) AttrSlice::AttrSlice(const AttrValueMap* a) : ndef_(nullptr), attrs_(a) {} -static string SummarizeAttrsHelper(AttrSlice attrs, absl::string_view device) { +static string SummarizeAttrsHelper(AttrSlice attrs, StringPiece device) { string ret; // We sort the attrs so the output is deterministic. @@ -79,10 +78,9 @@ static string SummarizeAttrsHelper(AttrSlice attrs, absl::string_view device) { } string AttrSlice::SummarizeNode() const { - return ndef_ - ? SummarizeNodeDef(*ndef_) - : strings::StrCat( - "[", SummarizeAttrsHelper(*this, absl::string_view()), "]"); + return ndef_ ? SummarizeNodeDef(*ndef_) + : strings::StrCat( + "[", SummarizeAttrsHelper(*this, StringPiece()), "]"); } string SummarizeNode(const Node& node) { return SummarizeNodeDef(node.def()); } @@ -112,7 +110,7 @@ string FormatNodeDefForError(const NodeDef& node_def) { return errors::FormatNodeNameForError(node_def.name()); } -const AttrValue* AttrSlice::Find(absl::string_view attr_name) const { +const AttrValue* AttrSlice::Find(StringPiece attr_name) const { // Currently, the collection used for NodeDef::attr() (google::protobuf::Map) // requires that the keys used for lookups have type 'const string&'. Because // this method takes a StringPiece, it is necessary to allocate a temporary @@ -133,7 +131,7 @@ const AttrValue* AttrSlice::Find(absl::string_view attr_name) const { return nullptr; } -Status AttrSlice::Find(absl::string_view attr_name, +Status AttrSlice::Find(StringPiece attr_name, const AttrValue** attr_value) const { *attr_value = Find(attr_name); if (*attr_value != nullptr) { @@ -168,7 +166,7 @@ bool AttrSlice::EqualAttrs(AttrSlice other, Scratch* scratch) const { // The ... is to allow the caller to inject some value validation code. Use // just ; if no additional validation code is needed. #define DEFINE_GET_ATTR(TYPE, FIELD, ATTR_TYPE, APPEND_OP, CAST, ...) \ - Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, \ + Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, \ TYPE* value) { \ const AttrValue* attr_value; \ TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); \ @@ -178,7 +176,7 @@ bool AttrSlice::EqualAttrs(AttrSlice other, Scratch* scratch) const { *value = CAST; \ return Status::OK(); \ } \ - Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, \ + Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, \ std::vector<TYPE>* value) { \ const AttrValue* attr_value; \ TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); \ @@ -190,37 +188,37 @@ bool AttrSlice::EqualAttrs(AttrSlice other, Scratch* scratch) const { return Status::OK(); \ } -#define DEFINE_GET_ATTR_SIMPLE(TYPE, FIELD, ATTR_TYPE, APPEND_OP, CAST, ...) \ - bool GetNodeAttrSimple(const AttrSlice& attrs, absl::string_view attr_name, \ - TYPE* value) { \ - const AttrValue* attr_value = attrs.Find(attr_name); \ - if (attr_value == nullptr) { \ - return false; \ - } \ - Status s = AttrValueHasType(*attr_value, ATTR_TYPE); \ - if (!s.ok()) { \ - return false; \ - } \ - const auto& v = attr_value->FIELD(); \ - __VA_ARGS__; \ - *value = CAST; \ - return true; \ - } \ - bool GetNodeAttrSimple(const AttrSlice& attrs, absl::string_view attr_name, \ - std::vector<TYPE>* value) { \ - const AttrValue* attr_value = attrs.Find(attr_name); \ - if (attr_value == nullptr) { \ - return false; \ - } \ - Status s = AttrValueHasType(*attr_value, "list(" ATTR_TYPE ")"); \ - if (!s.ok()) { \ - return false; \ - } \ - for (const auto& v : attr_value->list().FIELD()) { \ - __VA_ARGS__; \ - value->APPEND_OP(CAST); \ - } \ - return true; \ +#define DEFINE_GET_ATTR_SIMPLE(TYPE, FIELD, ATTR_TYPE, APPEND_OP, CAST, ...) \ + bool GetNodeAttrSimple(const AttrSlice& attrs, StringPiece attr_name, \ + TYPE* value) { \ + const AttrValue* attr_value = attrs.Find(attr_name); \ + if (attr_value == nullptr) { \ + return false; \ + } \ + Status s = AttrValueHasType(*attr_value, ATTR_TYPE); \ + if (!s.ok()) { \ + return false; \ + } \ + const auto& v = attr_value->FIELD(); \ + __VA_ARGS__; \ + *value = CAST; \ + return true; \ + } \ + bool GetNodeAttrSimple(const AttrSlice& attrs, StringPiece attr_name, \ + std::vector<TYPE>* value) { \ + const AttrValue* attr_value = attrs.Find(attr_name); \ + if (attr_value == nullptr) { \ + return false; \ + } \ + Status s = AttrValueHasType(*attr_value, "list(" ATTR_TYPE ")"); \ + if (!s.ok()) { \ + return false; \ + } \ + for (const auto& v : attr_value->list().FIELD()) { \ + __VA_ARGS__; \ + value->APPEND_OP(CAST); \ + } \ + return true; \ } DEFINE_GET_ATTR(string, s, "string", emplace_back, v, ;) @@ -255,14 +253,13 @@ DEFINE_GET_ATTR(Tensor, tensor, "tensor", emplace_back, t, Tensor t; DEFINE_GET_ATTR(NameAttrList, func, "func", emplace_back, v, ;); #undef DEFINE_GET_ATTR -bool HasNodeAttr(const NodeDef& node_def, absl::string_view attr_name) { +bool HasNodeAttr(const NodeDef& node_def, StringPiece attr_name) { return node_def.attr().find(string(attr_name)) != node_def.attr().end(); } static const string& kEmptyString = *new string(); -const string& GetNodeAttrString(const AttrSlice& attrs, - absl::string_view attr_name) { +const string& GetNodeAttrString(const AttrSlice& attrs, StringPiece attr_name) { const AttrValue* attr_value = attrs.Find(attr_name); if (attr_value == nullptr) { return kEmptyString; @@ -274,7 +271,7 @@ const string& GetNodeAttrString(const AttrSlice& attrs, return attr_value->s(); } -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, DataTypeVector* value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); @@ -285,7 +282,7 @@ Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, return Status::OK(); } -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const TensorProto** value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); @@ -294,7 +291,7 @@ Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, return Status::OK(); } -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const NameAttrList** value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); @@ -577,7 +574,7 @@ namespace { using ::tensorflow::strings::Scanner; -bool IsValidOpName(absl::string_view sp) { +bool IsValidOpName(StringPiece sp) { return Scanner(sp) .One(Scanner::LETTER_DIGIT_DOT) .Any(Scanner::LETTER_DIGIT_DASH_DOT_SLASH_UNDERSCORE) @@ -585,7 +582,7 @@ bool IsValidOpName(absl::string_view sp) { .GetResult(); } -bool IsValidDataInputName(absl::string_view sp) { +bool IsValidDataInputName(StringPiece sp) { // Data inputs are op_name, op_name:0, or op_name:12345. Scanner scan(sp); scan.One(Scanner::LETTER_DIGIT_DOT) @@ -603,7 +600,7 @@ bool IsValidDataInputName(absl::string_view sp) { return scan.GetResult(); } -bool IsValidControlInputName(absl::string_view sp) { +bool IsValidControlInputName(StringPiece sp) { return Scanner(sp) .OneLiteral("^") .One(Scanner::LETTER_DIGIT_DOT) @@ -668,19 +665,18 @@ Status AttachDef(const Status& status, const Node& node) { return AttachDef(status, node.def()); } -void AddNodeAttr(absl::string_view name, const AttrValue& value, - NodeDef* node_def) { +void AddNodeAttr(StringPiece name, const AttrValue& value, NodeDef* node_def) { node_def->mutable_attr()->insert( AttrValueMap::value_type(string(name), value)); } -#define ADD_NODE_ATTR(T) \ - void AddNodeAttr(absl::string_view name, T value, NodeDef* node_def) { \ - AttrValue attr_value; \ - SetAttrValue(value, &attr_value); \ - AddNodeAttr(name, attr_value, node_def); \ +#define ADD_NODE_ATTR(T) \ + void AddNodeAttr(StringPiece name, T value, NodeDef* node_def) { \ + AttrValue attr_value; \ + SetAttrValue(value, &attr_value); \ + AddNodeAttr(name, attr_value, node_def); \ } -ADD_NODE_ATTR(absl::string_view) +ADD_NODE_ATTR(StringPiece) ADD_NODE_ATTR(const char*) ADD_NODE_ATTR(int32) ADD_NODE_ATTR(int64) @@ -692,7 +688,7 @@ ADD_NODE_ATTR(const PartialTensorShape&) ADD_NODE_ATTR(const Tensor&) ADD_NODE_ATTR(const TensorProto&) ADD_NODE_ATTR(const NameAttrList&) -ADD_NODE_ATTR(gtl::ArraySlice<absl::string_view>) +ADD_NODE_ATTR(gtl::ArraySlice<StringPiece>) ADD_NODE_ATTR(gtl::ArraySlice<const char*>) ADD_NODE_ATTR(gtl::ArraySlice<string>) ADD_NODE_ATTR(gtl::ArraySlice<int32>) @@ -708,22 +704,21 @@ ADD_NODE_ATTR(gtl::ArraySlice<Tensor>) ADD_NODE_ATTR(gtl::ArraySlice<NameAttrList>) #undef ADD_NODE_ATTR -void AddAttr(absl::string_view name, const AttrValue& value, - AttrValueMap* map) { +void AddAttr(StringPiece name, const AttrValue& value, AttrValueMap* map) { map->insert(AttrValueMap::value_type(string(name), value)); } -#define ADD_ATTR(T) \ - void AddAttr(absl::string_view name, T value, AttrValueMap* map) { \ - AttrValue attr_value; \ - SetAttrValue(value, &attr_value); \ - AddAttr(name, attr_value, map); \ +#define ADD_ATTR(T) \ + void AddAttr(StringPiece name, T value, AttrValueMap* map) { \ + AttrValue attr_value; \ + SetAttrValue(value, &attr_value); \ + AddAttr(name, attr_value, map); \ } ADD_ATTR(bool) #undef ADD_ATTR -Status AddPrefixAndSuffixToNode(absl::string_view prefix, - absl::string_view suffix, NodeDef* node_def) { +Status AddPrefixAndSuffixToNode(StringPiece prefix, StringPiece suffix, + NodeDef* node_def) { node_def->set_name(strings::StrCat(prefix, node_def->name(), suffix)); if (node_def->op() == "Enter" || node_def->op() == "RefEnter") { string frame_name; diff --git a/tensorflow/core/framework/node_def_util.h b/tensorflow/core/framework/node_def_util.h index 631f3587412..0ff67554eb3 100644 --- a/tensorflow/core/framework/node_def_util.h +++ b/tensorflow/core/framework/node_def_util.h @@ -19,9 +19,9 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/types.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/flatmap.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/platform/protobuf.h" @@ -59,65 +59,61 @@ typedef protobuf::Map<string, AttrValue> AttrValueMap; // Adds an attr with name <name> and value <value> to *node_def. // The type of the attr is based on the type of value. -void AddNodeAttr(absl::string_view name, const AttrValue& value, +void AddNodeAttr(StringPiece name, const AttrValue& value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, StringPiece value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, const char* value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, int32 value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, int64 value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, float value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, double value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, bool value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, DataType value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, const PartialTensorShape& value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, absl::string_view value, +void AddNodeAttr(StringPiece name, const Tensor& value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, const TensorProto& value, NodeDef* node_def); +void AddNodeAttr(StringPiece name, const NameAttrList& value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const char* value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, int32 value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, int64 value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, float value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, double value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, bool value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, DataType value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const PartialTensorShape& value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<StringPiece> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const Tensor& value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<const char*> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const TensorProto& value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<string> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const NameAttrList& value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<int32> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, - gtl::ArraySlice<absl::string_view> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<const char*> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<int64> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<string> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<float> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<int32> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<bool> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<int64> value, +void AddNodeAttr(StringPiece name, const std::vector<bool>& value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<float> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<DataType> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<bool> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<TensorShape> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, const std::vector<bool>& value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<PartialTensorShape> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<DataType> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<TensorShapeProto> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<TensorShape> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<Tensor> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, - gtl::ArraySlice<PartialTensorShape> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, - gtl::ArraySlice<TensorShapeProto> value, NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<Tensor> value, - NodeDef* node_def); -void AddNodeAttr(absl::string_view name, gtl::ArraySlice<NameAttrList> value, +void AddNodeAttr(StringPiece name, gtl::ArraySlice<NameAttrList> value, NodeDef* node_def); // Version to workaround C++'s "perfect" forwarding not being able to // forward {...} initialization. template <class T> -void AddNodeAttr(absl::string_view name, std::initializer_list<T> value, +void AddNodeAttr(StringPiece name, std::initializer_list<T> value, NodeDef* node_def) { AddNodeAttr(name, gtl::ArraySlice<T>(value), node_def); } // Adds an attr to an attr value map. -void AddAttr(absl::string_view name, const AttrValue& value, AttrValueMap* map); -void AddAttr(absl::string_view name, bool value, AttrValueMap* map); +void AddAttr(StringPiece name, const AttrValue& value, AttrValueMap* map); +void AddAttr(StringPiece name, bool value, AttrValueMap* map); class AttrSlice { public: @@ -130,11 +126,11 @@ class AttrSlice { // Returns the attr with attr_name if found. Otherwise, returns // nullptr. - const AttrValue* Find(absl::string_view attr_name) const; + const AttrValue* Find(StringPiece attr_name) const; // Returns the attr_value for attr_name if found. Otherwise, returns a // NotFound status. - Status Find(absl::string_view attr_name, const AttrValue** attr_value) const; + Status Find(StringPiece attr_name, const AttrValue** attr_value) const; // Helper class to avoid allocations in EqualAttrs. // TODO(irving): Will go away once NodeInfo is used. @@ -169,85 +165,84 @@ class AttrSlice { }; // Return true if the attr with the name attr_name is defined in node_def. -bool HasNodeAttr(const NodeDef& node_def, absl::string_view attr_name); +bool HasNodeAttr(const NodeDef& node_def, StringPiece attr_name); // Look up the attr with name attr_name and set *value to its value. If no // attr with attr_name is found in node_def, or the attr does not have // a matching type, a non-ok status will be returned. -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, string* value); // type: "string" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, int64* value); // type: "int" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, int32* value); // type: "int" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, float* value); // type: "float" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, bool* value); // type: "bool" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, DataType* value); // type: "type" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, TensorShapeProto* value); // type: "shape" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, TensorShape* value); // type: "shape" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, PartialTensorShape* value); // type: "shape" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, Tensor* value); // type: "tensor" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<string>* value); // type "list(string)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<int64>* value); // type "list(int)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<int32>* value); // type "list(int)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<float>* value); // type "list(float)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<bool>* value); // type "list(bool)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<DataType>* value); // type "list(type)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, DataTypeVector* value); // type "list(type)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<TensorShapeProto>* value); // type "list(shape)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<TensorShape>* value); // type "list(shape)" Status GetNodeAttr( - const AttrSlice& attrs, absl::string_view attr_name, + const AttrSlice& attrs, StringPiece attr_name, std::vector<PartialTensorShape>* value); // type "list(shape)" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<Tensor>* value); // type: "list(tensor)" // This version avoids copying the TensorProto. // REQUIRES: Must not use *value beyond the lifetime of node_def. -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const TensorProto** value); // type: "tensor" // This version avoids copying the NameAttrList. // REQUIRES: Must not use *value beyond the lifetime of node_def. -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const NameAttrList** value); // type: "func" // These versions copies the NameAttrList(s). -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, NameAttrList* value); // type: "func" -Status GetNodeAttr(const AttrSlice& attrs, absl::string_view attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, std::vector<NameAttrList>* value); // type: "list(func)" // Look up the attr with name attr_name and set *value to its value. If no // attr with attr_name is found in node_def, or the attr does not have // a matching type, false is returned. -bool GetNodeAttrSimple(const AttrSlice& attrs, absl::string_view attr_name, +bool GetNodeAttrSimple(const AttrSlice& attrs, StringPiece attr_name, string* value); // type: "string" -bool GetNodeAttrSimple(const AttrSlice& attrs, absl::string_view attr_name, +bool GetNodeAttrSimple(const AttrSlice& attrs, StringPiece attr_name, std::vector<string>* value); // type: "string" // Look up the attr with name attr_name and return a reference to its value. // If no attr with attr_name is found in node_def, or the attr does not have // a matching type, a reference to an empty string is returned. // REQUIRES: Must not use the returned value beyond the lifetime of node_def. -const string& GetNodeAttrString(const AttrSlice& attrs, - absl::string_view attr_name); +const string& GetNodeAttrString(const AttrSlice& attrs, StringPiece attr_name); // Computes the input type for a specific node input. // REQUIRES: ValidateOpDef(op_def).ok() @@ -289,8 +284,7 @@ Status ValidateNodeDef(const NodeDef& node_def, const OpDef& op_def); // space, the returned `NameRangeMap` objects borrow the input/output // argument names from `op_def`. The `op_def` must outlive the // returned `NameRangeMap` objects. -typedef gtl::FlatMap<absl::string_view, std::pair<int, int>, - hash<absl::string_view>> +typedef gtl::FlatMap<StringPiece, std::pair<int, int>, hash<StringPiece>> NameRangeMap; Status NameRangesForNode(const NodeDef& node_def, const OpDef& op_def, NameRangeMap* inputs, NameRangeMap* outputs); @@ -321,8 +315,8 @@ Status AttachDef(const Status& status, const Node& node); // Appends the given prefix and suffix to the original node name in order to // make the name unique. If it's an "Enter" node, use the same way to reset // attribute "frame_name". -Status AddPrefixAndSuffixToNode(absl::string_view prefix, - absl::string_view suffix, NodeDef* node_def); +Status AddPrefixAndSuffixToNode(StringPiece prefix, StringPiece suffix, + NodeDef* node_def); } // namespace tensorflow #endif // TENSORFLOW_CORE_FRAMEWORK_NODE_DEF_UTIL_H_ diff --git a/tensorflow/core/framework/node_def_util_test.cc b/tensorflow/core/framework/node_def_util_test.cc index 56fb66bd092..d9d437024ab 100644 --- a/tensorflow/core/framework/node_def_util_test.cc +++ b/tensorflow/core/framework/node_def_util_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/framework/node_def_util.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" // NOLINT #include "tensorflow/core/framework/fake_input.h" #include "tensorflow/core/framework/node_def_builder.h" @@ -271,8 +270,7 @@ void ExpectInvalidSyntax(const NodeDef& bad, const string& message) { EXPECT_TRUE(errors::IsInvalidArgument(status)) << status << "; NodeDef: " << SummarizeNodeDef(bad); - EXPECT_TRUE( - str_util::StrContains(absl::string_view(status.ToString()), message)) + EXPECT_TRUE(str_util::StrContains(StringPiece(status.ToString()), message)) << "NodeDef: " << SummarizeNodeDef(bad) << ", " << status << ", " << message; } diff --git a/tensorflow/core/framework/op.h b/tensorflow/core/framework/op.h index b3db2762782..81ed5f95f0b 100644 --- a/tensorflow/core/framework/op.h +++ b/tensorflow/core/framework/op.h @@ -20,7 +20,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_def_builder.h" #include "tensorflow/core/framework/op_def_util.h" #include "tensorflow/core/framework/selective_registration.h" @@ -262,17 +261,15 @@ template <> class OpDefBuilderWrapper<false> { public: constexpr OpDefBuilderWrapper(const char name[]) {} - OpDefBuilderWrapper<false>& Attr(absl::string_view spec) { return *this; } - OpDefBuilderWrapper<false>& Input(absl::string_view spec) { return *this; } - OpDefBuilderWrapper<false>& Output(absl::string_view spec) { return *this; } + OpDefBuilderWrapper<false>& Attr(StringPiece spec) { return *this; } + OpDefBuilderWrapper<false>& Input(StringPiece spec) { return *this; } + OpDefBuilderWrapper<false>& Output(StringPiece spec) { return *this; } OpDefBuilderWrapper<false>& SetIsCommutative() { return *this; } OpDefBuilderWrapper<false>& SetIsAggregate() { return *this; } OpDefBuilderWrapper<false>& SetIsStateful() { return *this; } OpDefBuilderWrapper<false>& SetAllowsUninitializedInput() { return *this; } - OpDefBuilderWrapper<false>& Deprecated(int, absl::string_view) { - return *this; - } - OpDefBuilderWrapper<false>& Doc(absl::string_view text) { return *this; } + OpDefBuilderWrapper<false>& Deprecated(int, StringPiece) { return *this; } + OpDefBuilderWrapper<false>& Doc(StringPiece text) { return *this; } OpDefBuilderWrapper<false>& SetShapeFn( Status (*fn)(shape_inference::InferenceContext*)) { return *this; diff --git a/tensorflow/core/framework/op_def_builder.cc b/tensorflow/core/framework/op_def_builder.cc index e46d91a6027..8a9bb631821 100644 --- a/tensorflow/core/framework/op_def_builder.cc +++ b/tensorflow/core/framework/op_def_builder.cc @@ -17,7 +17,6 @@ limitations under the License. #include <limits> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/op_def_util.h" @@ -34,11 +33,11 @@ namespace tensorflow { namespace { -string AttrError(absl::string_view orig, const string& op_name) { +string AttrError(StringPiece orig, const string& op_name) { return strings::StrCat(" from Attr(\"", orig, "\") for Op ", op_name); } -bool ConsumeAttrName(absl::string_view* sp, absl::string_view* out) { +bool ConsumeAttrName(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .One(Scanner::LETTER) .Any(Scanner::LETTER_DIGIT_UNDERSCORE) @@ -49,7 +48,7 @@ bool ConsumeAttrName(absl::string_view* sp, absl::string_view* out) { .GetResult(sp, out); } -bool ConsumeListPrefix(absl::string_view* sp) { +bool ConsumeListPrefix(StringPiece* sp) { return Scanner(*sp) .OneLiteral("list") .AnySpace() @@ -58,8 +57,7 @@ bool ConsumeListPrefix(absl::string_view* sp) { .GetResult(sp); } -bool ConsumeQuotedString(char quote_ch, absl::string_view* sp, - absl::string_view* out) { +bool ConsumeQuotedString(char quote_ch, StringPiece* sp, StringPiece* out) { const string quote_str(1, quote_ch); return Scanner(*sp) .OneLiteral(quote_str.c_str()) @@ -71,7 +69,7 @@ bool ConsumeQuotedString(char quote_ch, absl::string_view* sp, .GetResult(sp, out); } -bool ConsumeAttrType(absl::string_view* sp, absl::string_view* out) { +bool ConsumeAttrType(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .Many(Scanner::LOWERLETTER_DIGIT) .StopCapture() @@ -79,10 +77,10 @@ bool ConsumeAttrType(absl::string_view* sp, absl::string_view* out) { .GetResult(sp, out); } -bool ConsumeAttrNumber(absl::string_view* sp, int64* out) { +bool ConsumeAttrNumber(StringPiece* sp, int64* out) { Scanner scan(*sp); - absl::string_view match; - absl::string_view remaining; + StringPiece match; + StringPiece remaining; scan.AnySpace().RestartCapture(); if (scan.Peek() == '-') { @@ -112,21 +110,20 @@ bool ConsumeAttrNumber(absl::string_view* sp, int64* out) { } \ } while (false) -bool ConsumeCompoundAttrType(absl::string_view* sp, absl::string_view* out) { +bool ConsumeCompoundAttrType(StringPiece* sp, StringPiece* out) { auto capture_begin = sp->begin(); if (str_util::ConsumePrefix(sp, "numbertype") || str_util::ConsumePrefix(sp, "numerictype") || str_util::ConsumePrefix(sp, "quantizedtype") || str_util::ConsumePrefix(sp, "realnumbertype") || str_util::ConsumePrefix(sp, "realnumberictype")) { - *out = absl::string_view(capture_begin, sp->begin() - capture_begin); + *out = StringPiece(capture_begin, sp->begin() - capture_begin); return true; } return false; } -bool ProcessCompoundType(const absl::string_view type_string, - AttrValue* allowed) { +bool ProcessCompoundType(const StringPiece type_string, AttrValue* allowed) { if (type_string == "numbertype" || type_string == "numerictype") { for (DataType dt : NumberTypes()) { allowed->mutable_list()->add_type(dt); @@ -146,20 +143,20 @@ bool ProcessCompoundType(const absl::string_view type_string, return true; } -void FinalizeAttr(absl::string_view spec, OpDef* op_def, +void FinalizeAttr(StringPiece spec, OpDef* op_def, std::vector<string>* errors) { OpDef::AttrDef* attr = op_def->add_attr(); - absl::string_view orig(spec); + StringPiece orig(spec); // Parse "<name>:" at the beginning. - absl::string_view tmp_name; + StringPiece tmp_name; VERIFY(ConsumeAttrName(&spec, &tmp_name), "Trouble parsing '<name>:'"); attr->set_name(tmp_name.data(), tmp_name.size()); // Read "<type>" or "list(<type>)". bool is_list = ConsumeListPrefix(&spec); string type; - absl::string_view type_string; // Used if type == "type" + StringPiece type_string; // Used if type == "type" if (str_util::ConsumePrefix(&spec, "string")) { type = "string"; } else if (str_util::ConsumePrefix(&spec, "int")) { @@ -188,7 +185,7 @@ void FinalizeAttr(absl::string_view spec, OpDef* op_def, if (str_util::StartsWith(spec, "\"") || str_util::StartsWith(spec, "'")) { type = "string"; // "{ \"foo\", \"bar\" }" or "{ 'foo', 'bar' }" while (true) { - absl::string_view escaped_string; + StringPiece escaped_string; VERIFY(ConsumeQuotedString('"', &spec, &escaped_string) || ConsumeQuotedString('\'', &spec, &escaped_string), "Trouble parsing allowed string at '", spec, "'"); @@ -269,13 +266,12 @@ void FinalizeAttr(absl::string_view spec, OpDef* op_def, #undef VERIFY -string InOutError(bool is_output, absl::string_view orig, - const string& op_name) { +string InOutError(bool is_output, StringPiece orig, const string& op_name) { return strings::StrCat(" from ", is_output ? "Output" : "Input", "(\"", orig, "\") for Op ", op_name); } -bool ConsumeInOutName(absl::string_view* sp, absl::string_view* out) { +bool ConsumeInOutName(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .One(Scanner::LOWERLETTER) .Any(Scanner::LOWERLETTER_DIGIT_UNDERSCORE) @@ -286,7 +282,7 @@ bool ConsumeInOutName(absl::string_view* sp, absl::string_view* out) { .GetResult(sp, out); } -bool ConsumeInOutRefOpen(absl::string_view* sp) { +bool ConsumeInOutRefOpen(StringPiece* sp) { return Scanner(*sp) .OneLiteral("Ref") .AnySpace() @@ -295,11 +291,11 @@ bool ConsumeInOutRefOpen(absl::string_view* sp) { .GetResult(sp); } -bool ConsumeInOutRefClose(absl::string_view* sp) { +bool ConsumeInOutRefClose(StringPiece* sp) { return Scanner(*sp).OneLiteral(")").AnySpace().GetResult(sp); } -bool ConsumeInOutNameOrType(absl::string_view* sp, absl::string_view* out) { +bool ConsumeInOutNameOrType(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .One(Scanner::LETTER) .Any(Scanner::LETTER_DIGIT_UNDERSCORE) @@ -308,7 +304,7 @@ bool ConsumeInOutNameOrType(absl::string_view* sp, absl::string_view* out) { .GetResult(sp, out); } -bool ConsumeInOutTimesType(absl::string_view* sp, absl::string_view* out) { +bool ConsumeInOutTimesType(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .OneLiteral("*") .AnySpace() @@ -329,15 +325,15 @@ bool ConsumeInOutTimesType(absl::string_view* sp, absl::string_view* out) { } \ } while (false) -void FinalizeInputOrOutput(absl::string_view spec, bool is_output, - OpDef* op_def, std::vector<string>* errors) { +void FinalizeInputOrOutput(StringPiece spec, bool is_output, OpDef* op_def, + std::vector<string>* errors) { OpDef::ArgDef* arg = is_output ? op_def->add_output_arg() : op_def->add_input_arg(); - absl::string_view orig(spec); + StringPiece orig(spec); // Parse "<name>:" at the beginning. - absl::string_view tmp_name; + StringPiece tmp_name; VERIFY(ConsumeInOutName(&spec, &tmp_name), "Trouble parsing 'name:'"); arg->set_name(tmp_name.data(), tmp_name.size()); @@ -347,7 +343,7 @@ void FinalizeInputOrOutput(absl::string_view spec, bool is_output, } { // Parse "<name|type>" or "<name>*<name|type>". - absl::string_view first, second, type_or_attr; + StringPiece first, second, type_or_attr; VERIFY(ConsumeInOutNameOrType(&spec, &first), "Trouble parsing either a type or an attr name at '", spec, "'"); if (ConsumeInOutTimesType(&spec, &second)) { @@ -413,7 +409,7 @@ void FinalizeInputOrOutput(absl::string_view spec, bool is_output, #undef VERIFY -int num_leading_spaces(absl::string_view s) { +int num_leading_spaces(StringPiece s) { size_t i = 0; while (i < s.size() && s[i] == ' ') { ++i; @@ -421,7 +417,7 @@ int num_leading_spaces(absl::string_view s) { return i; } -bool ConsumeDocNameColon(absl::string_view* sp, absl::string_view* out) { +bool ConsumeDocNameColon(StringPiece* sp, StringPiece* out) { return Scanner(*sp) .One(Scanner::LETTER) .Any(Scanner::LETTER_DIGIT_UNDERSCORE) @@ -432,7 +428,7 @@ bool ConsumeDocNameColon(absl::string_view* sp, absl::string_view* out) { .GetResult(sp, out); } -bool IsDocNameColon(absl::string_view s) { +bool IsDocNameColon(StringPiece s) { return ConsumeDocNameColon(&s, nullptr /* out */); } @@ -469,8 +465,8 @@ void FinalizeDoc(const string& text, OpDef* op_def, // name: description // possibly continued on the next line // if so, we remove the minimum indent - absl::string_view name; - std::vector<absl::string_view> description; + StringPiece name; + std::vector<StringPiece> description; while (static_cast<size_t>(l) < lines.size()) { description.clear(); description.push_back(lines[l]); @@ -609,13 +605,13 @@ Status OpDefBuilder::Finalize(OpRegistrationData* op_reg_data) const { *op_reg_data = op_reg_data_; OpDef* op_def = &op_reg_data->op_def; - for (absl::string_view attr : attrs_) { + for (StringPiece attr : attrs_) { FinalizeAttr(attr, op_def, &errors); } - for (absl::string_view input : inputs_) { + for (StringPiece input : inputs_) { FinalizeInputOrOutput(input, false, op_def, &errors); } - for (absl::string_view output : outputs_) { + for (StringPiece output : outputs_) { FinalizeInputOrOutput(output, true, op_def, &errors); } FinalizeDoc(doc_, op_def, &errors); diff --git a/tensorflow/core/framework/op_def_builder_test.cc b/tensorflow/core/framework/op_def_builder_test.cc index 1e6a62e767a..9b24e3aa004 100644 --- a/tensorflow/core/framework/op_def_builder_test.cc +++ b/tensorflow/core/framework/op_def_builder_test.cc @@ -15,11 +15,11 @@ limitations under the License. #include "tensorflow/core/framework/op_def_builder.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/protobuf.h" @@ -40,7 +40,7 @@ class OpDefBuilderTest : public ::testing::Test { protected: OpDefBuilder b() { return OpDefBuilder("Test"); } - void ExpectSuccess(const OpDefBuilder& builder, absl::string_view proto, + void ExpectSuccess(const OpDefBuilder& builder, StringPiece proto, OpShapeInferenceFn* shape_fn_out = nullptr) { OpRegistrationData op_reg_data; Status status = builder.Finalize(&op_reg_data); @@ -61,7 +61,7 @@ class OpDefBuilderTest : public ::testing::Test { } } - void ExpectOrdered(const OpDefBuilder& builder, absl::string_view proto) { + void ExpectOrdered(const OpDefBuilder& builder, StringPiece proto) { OpRegistrationData op_reg_data; Status status = builder.Finalize(&op_reg_data); TF_EXPECT_OK(status); diff --git a/tensorflow/core/framework/op_def_util.cc b/tensorflow/core/framework/op_def_util.cc index aa37d408244..3597f43d519 100644 --- a/tensorflow/core/framework/op_def_util.cc +++ b/tensorflow/core/framework/op_def_util.cc @@ -18,12 +18,12 @@ limitations under the License. #include <set> #include <unordered_map> #include <unordered_set> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/op_def.pb_text.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/proto_serialization.h" @@ -145,7 +145,7 @@ Status ValidateAttrValue(const AttrValue& attr_value, return Status::OK(); } -const OpDef::AttrDef* FindAttr(absl::string_view name, const OpDef& op_def) { +const OpDef::AttrDef* FindAttr(StringPiece name, const OpDef& op_def) { for (int i = 0; i < op_def.attr_size(); ++i) { if (op_def.attr(i).name() == name) { return &op_def.attr(i); @@ -154,7 +154,7 @@ const OpDef::AttrDef* FindAttr(absl::string_view name, const OpDef& op_def) { return nullptr; } -OpDef::AttrDef* FindAttrMutable(absl::string_view name, OpDef* op_def) { +OpDef::AttrDef* FindAttrMutable(StringPiece name, OpDef* op_def) { for (int i = 0; i < op_def->attr_size(); ++i) { if (op_def->attr(i).name() == name) { return op_def->mutable_attr(i); @@ -163,7 +163,7 @@ OpDef::AttrDef* FindAttrMutable(absl::string_view name, OpDef* op_def) { return nullptr; } -const OpDef::ArgDef* FindInputArg(absl::string_view name, const OpDef& op_def) { +const OpDef::ArgDef* FindInputArg(StringPiece name, const OpDef& op_def) { for (int i = 0; i < op_def.input_arg_size(); ++i) { if (op_def.input_arg(i).name() == name) { return &op_def.input_arg(i); @@ -172,7 +172,7 @@ const OpDef::ArgDef* FindInputArg(absl::string_view name, const OpDef& op_def) { return nullptr; } -const ApiDef::Arg* FindInputArg(absl::string_view name, const ApiDef& api_def) { +const ApiDef::Arg* FindInputArg(StringPiece name, const ApiDef& api_def) { for (int i = 0; i < api_def.in_arg_size(); ++i) { if (api_def.in_arg(i).name() == name) { return &api_def.in_arg(i); @@ -268,11 +268,11 @@ Status ValidateOpDef(const OpDef& op_def) { attr.name(), " that matches a data type"); // Validate type - absl::string_view type(attr.type()); + StringPiece type(attr.type()); bool is_list = str_util::ConsumePrefix(&type, "list("); bool found = false; - for (absl::string_view valid : {"string", "int", "float", "bool", "type", - "shape", "tensor", "func"}) { + for (StringPiece valid : {"string", "int", "float", "bool", "type", "shape", + "tensor", "func"}) { if (str_util::ConsumePrefix(&type, valid)) { found = true; break; diff --git a/tensorflow/core/framework/op_def_util.h b/tensorflow/core/framework/op_def_util.h index a5f0608861c..85afe2bdea0 100644 --- a/tensorflow/core/framework/op_def_util.h +++ b/tensorflow/core/framework/op_def_util.h @@ -20,7 +20,6 @@ limitations under the License. #define TENSORFLOW_CORE_FRAMEWORK_OP_DEF_UTIL_H_ #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/lib/core/status.h" @@ -42,16 +41,16 @@ Status ValidateAttrValue(const AttrValue& attr_value, // The following search through op_def for an attr with the indicated name. // Returns nullptr if no such attr is found. -const OpDef::AttrDef* FindAttr(absl::string_view name, const OpDef& op_def); -OpDef::AttrDef* FindAttrMutable(absl::string_view name, OpDef* op_def); +const OpDef::AttrDef* FindAttr(StringPiece name, const OpDef& op_def); +OpDef::AttrDef* FindAttrMutable(StringPiece name, OpDef* op_def); // Searches op_def for input argument with the indicated name. // Returns nullptr if no such attr is found. -const OpDef::ArgDef* FindInputArg(absl::string_view name, const OpDef& op_def); +const OpDef::ArgDef* FindInputArg(StringPiece name, const OpDef& op_def); // Searches api_def for input argument with the indicated name. // Returns nullptr if no such attr is found. -const ApiDef::Arg* FindInputArg(absl::string_view name, const ApiDef& api_def); +const ApiDef::Arg* FindInputArg(StringPiece name, const ApiDef& api_def); // Produce a human-readable version of an op_def that is more concise // than a text-format proto. Excludes descriptions. diff --git a/tensorflow/core/framework/op_gen_lib.cc b/tensorflow/core/framework/op_gen_lib.cc index 81c67ed34c7..505ab547755 100644 --- a/tensorflow/core/framework/op_gen_lib.cc +++ b/tensorflow/core/framework/op_gen_lib.cc @@ -17,7 +17,6 @@ limitations under the License. #include <algorithm> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/gtl/map_util.h" @@ -27,7 +26,7 @@ limitations under the License. namespace tensorflow { -string WordWrap(absl::string_view prefix, absl::string_view str, int width) { +string WordWrap(StringPiece prefix, StringPiece str, int width) { const string indent_next_line = "\n" + Spaces(prefix.size()); width -= prefix.size(); string result; @@ -40,16 +39,16 @@ string WordWrap(absl::string_view prefix, absl::string_view str, int width) { break; } auto space = str.rfind(' ', width); - if (space == absl::string_view::npos) { + if (space == StringPiece::npos) { // Rather make a too-long line and break at a space. space = str.find(' '); - if (space == absl::string_view::npos) { + if (space == StringPiece::npos) { strings::StrAppend(&result, str); break; } } // Breaking at character at position <space>. - absl::string_view to_append = str.substr(0, space); + StringPiece to_append = str.substr(0, space); str.remove_prefix(space + 1); // Remove spaces at break. while (str_util::EndsWith(to_append, " ")) { @@ -66,7 +65,7 @@ string WordWrap(absl::string_view prefix, absl::string_view str, int width) { return result; } -bool ConsumeEquals(absl::string_view* description) { +bool ConsumeEquals(StringPiece* description) { if (str_util::ConsumePrefix(description, "=")) { while (str_util::ConsumePrefix(description, " ")) { // Also remove spaces after "=". @@ -81,12 +80,12 @@ bool ConsumeEquals(absl::string_view* description) { // contains the maximum prefix of the input `*orig` that doesn't // contain `split_ch`, and `*orig` contains everything after the // first `split_ch`. -static bool SplitAt(char split_ch, absl::string_view* orig, - absl::string_view* before_split) { +static bool SplitAt(char split_ch, StringPiece* orig, + StringPiece* before_split) { auto pos = orig->find(split_ch); - if (pos == absl::string_view::npos) { + if (pos == StringPiece::npos) { *before_split = *orig; - *orig = absl::string_view(); + *orig = StringPiece(); return false; } else { *before_split = orig->substr(0, pos); @@ -97,9 +96,9 @@ static bool SplitAt(char split_ch, absl::string_view* orig, // Does this line start with "<spaces><field>:" where "<field>" is // in multi_line_fields? Sets *colon_pos to the position of the colon. -static bool StartsWithFieldName(absl::string_view line, +static bool StartsWithFieldName(StringPiece line, const std::vector<string>& multi_line_fields) { - absl::string_view up_to_colon; + StringPiece up_to_colon; if (!SplitAt(':', &line, &up_to_colon)) return false; while (str_util::ConsumePrefix(&up_to_colon, " ")) ; // Remove leading spaces. @@ -111,7 +110,7 @@ static bool StartsWithFieldName(absl::string_view line, return false; } -static bool ConvertLine(absl::string_view line, +static bool ConvertLine(StringPiece line, const std::vector<string>& multi_line_fields, string* ml) { // Is this a field we should convert? @@ -119,8 +118,8 @@ static bool ConvertLine(absl::string_view line, return false; } // Has a matching field name, so look for "..." after the colon. - absl::string_view up_to_colon; - absl::string_view after_colon = line; + StringPiece up_to_colon; + StringPiece after_colon = line; SplitAt(':', &after_colon, &up_to_colon); while (str_util::ConsumePrefix(&after_colon, " ")) ; // Remove leading spaces. @@ -129,12 +128,12 @@ static bool ConvertLine(absl::string_view line, return false; } auto last_quote = after_colon.rfind('\"'); - if (last_quote == absl::string_view::npos) { + if (last_quote == StringPiece::npos) { // Error: we don't see the expected matching quote, abort the conversion. return false; } - absl::string_view escaped = after_colon.substr(0, last_quote); - absl::string_view suffix = after_colon.substr(last_quote + 1); + StringPiece escaped = after_colon.substr(0, last_quote); + StringPiece suffix = after_colon.substr(last_quote + 1); // We've now parsed line into '<up_to_colon>: "<escaped>"<suffix>' string unescaped; @@ -160,13 +159,13 @@ static bool ConvertLine(absl::string_view line, return true; } -string PBTxtToMultiline(absl::string_view pbtxt, +string PBTxtToMultiline(StringPiece pbtxt, const std::vector<string>& multi_line_fields) { string ml; // Probably big enough, since the input and output are about the // same size, but just a guess. ml.reserve(pbtxt.size() * (17. / 16)); - absl::string_view line; + StringPiece line; while (!pbtxt.empty()) { // Split pbtxt into its first line and everything after. SplitAt('\n', &pbtxt, &line); @@ -181,8 +180,8 @@ string PBTxtToMultiline(absl::string_view pbtxt, // Given a single line of text `line` with first : at `colon`, determine if // there is an "<<END" expression after the colon and if so return true and set // `*end` to everything after the "<<". -static bool FindMultiline(absl::string_view line, size_t colon, string* end) { - if (colon == absl::string_view::npos) return false; +static bool FindMultiline(StringPiece line, size_t colon, string* end) { + if (colon == StringPiece::npos) return false; line.remove_prefix(colon + 1); while (str_util::ConsumePrefix(&line, " ")) { } @@ -193,12 +192,12 @@ static bool FindMultiline(absl::string_view line, size_t colon, string* end) { return false; } -string PBTxtFromMultiline(absl::string_view multiline_pbtxt) { +string PBTxtFromMultiline(StringPiece multiline_pbtxt) { string pbtxt; // Probably big enough, since the input and output are about the // same size, but just a guess. pbtxt.reserve(multiline_pbtxt.size() * (33. / 32)); - absl::string_view line; + StringPiece line; while (!multiline_pbtxt.empty()) { // Split multiline_pbtxt into its first line and everything after. if (!SplitAt('\n', &multiline_pbtxt, &line)) { @@ -238,7 +237,7 @@ string PBTxtFromMultiline(absl::string_view multiline_pbtxt) { unescaped.push_back('\n'); } strings::StrAppend(&unescaped, line); - line = absl::string_view(); + line = StringPiece(); } // Escape what we extracted and then output it in quotes. diff --git a/tensorflow/core/framework/op_gen_lib.h b/tensorflow/core/framework/op_gen_lib.h index b7660207f8a..c269e2df049 100644 --- a/tensorflow/core/framework/op_gen_lib.h +++ b/tensorflow/core/framework/op_gen_lib.h @@ -18,10 +18,10 @@ limitations under the License. #include <string> #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/env.h" namespace tensorflow { @@ -35,17 +35,17 @@ inline string Spaces(int n) { return string(n, ' '); } // after the first by prefix.size() spaces. Intended use case is something // like prefix = " Foo(" and str is a list of arguments (terminated by a ")"). // TODO(josh11b): Option to wrap on ", " instead of " " when possible. -string WordWrap(absl::string_view prefix, absl::string_view str, int width); +string WordWrap(StringPiece prefix, StringPiece str, int width); // Looks for an "=" at the beginning of *description. If found, strips it off // (and any following spaces) from *description and return true. Otherwise // returns false. -bool ConsumeEquals(absl::string_view* description); +bool ConsumeEquals(StringPiece* description); // Convert text-serialized protobufs to/from multiline format. -string PBTxtToMultiline(absl::string_view pbtxt, +string PBTxtToMultiline(StringPiece pbtxt, const std::vector<string>& multi_line_fields); -string PBTxtFromMultiline(absl::string_view multiline_pbtxt); +string PBTxtFromMultiline(StringPiece multiline_pbtxt); // Takes a list of files with ApiDefs text protos, and allows you to // look up the specific ApiDef for any given op. diff --git a/tensorflow/core/framework/op_kernel.cc b/tensorflow/core/framework/op_kernel.cc index 65aa005bf6b..3e34bf04188 100644 --- a/tensorflow/core/framework/op_kernel.cc +++ b/tensorflow/core/framework/op_kernel.cc @@ -19,7 +19,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/graph.pb_text.h" @@ -34,6 +33,7 @@ limitations under the License. #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/notification.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -118,7 +118,7 @@ const string& OpKernel::type_string() const { return def_->op(); } const string& OpKernel::requested_device() const { return def_->device(); } const string& OpKernel::requested_input(int i) const { return def_->input(i); } -Status OpKernel::InputRange(absl::string_view input_name, int* start, +Status OpKernel::InputRange(StringPiece input_name, int* start, int* stop) const { const auto result = input_name_map_.find(input_name); if (result == input_name_map_.end()) { @@ -130,7 +130,7 @@ Status OpKernel::InputRange(absl::string_view input_name, int* start, } } -Status OpKernel::OutputRange(absl::string_view output_name, int* start, +Status OpKernel::OutputRange(StringPiece output_name, int* start, int* stop) const { const auto result = output_name_map_.find(output_name); if (result == output_name_map_.end()) { @@ -200,7 +200,7 @@ OpKernelConstruction::OpKernelConstruction( graph_def_version_(graph_def_version), status_(status) {} -bool OpKernelConstruction::HasAttr(absl::string_view attr_name) const { +bool OpKernelConstruction::HasAttr(StringPiece attr_name) const { return HasNodeAttr(def(), attr_name); } @@ -320,7 +320,7 @@ void OpKernelContext::really_record_tensor_reference(const Tensor& tensor) { referenced_tensors_->Add(tensor); } -Status OpKernelContext::input(absl::string_view name, const Tensor** tensor) { +Status OpKernelContext::input(StringPiece name, const Tensor** tensor) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); if (stop != start + 1) { @@ -338,8 +338,7 @@ Status OpKernelContext::input(absl::string_view name, const Tensor** tensor) { return Status::OK(); } -Status OpKernelContext::input_dtype(absl::string_view name, - DataType* dtype) const { +Status OpKernelContext::input_dtype(StringPiece name, DataType* dtype) const { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); if (stop != start + 1) { @@ -357,8 +356,7 @@ Status OpKernelContext::input_dtype(absl::string_view name, return Status::OK(); } -Status OpKernelContext::input_ref_mutex(absl::string_view name, - mutex** out_mutex) { +Status OpKernelContext::input_ref_mutex(StringPiece name, mutex** out_mutex) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); if (stop != start + 1) { @@ -440,7 +438,7 @@ bool OpKernelContext::forward_input_to_output_with_shape( } Status OpKernelContext::forward_input_to_output_with_shape( - absl::string_view input_name, absl::string_view output_name, + StringPiece input_name, StringPiece output_name, const TensorShape& output_shape, Tensor** output) { int input_index, output_index, stop; TF_RETURN_IF_ERROR( @@ -564,7 +562,7 @@ void OpKernelContext::delete_ref_input(int index, bool lock_held) { } } -Status OpKernelContext::mutable_input(absl::string_view name, Tensor* tensor, +Status OpKernelContext::mutable_input(StringPiece name, Tensor* tensor, bool lock_held) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); @@ -588,7 +586,7 @@ Status OpKernelContext::mutable_input(absl::string_view name, Tensor* tensor, return Status::OK(); } -Status OpKernelContext::replace_ref_input(absl::string_view name, +Status OpKernelContext::replace_ref_input(StringPiece name, const Tensor& tensor, bool lock_held) { int start, stop; @@ -606,14 +604,14 @@ Status OpKernelContext::replace_ref_input(absl::string_view name, return Status::OK(); } -Status OpKernelContext::input_list(absl::string_view name, OpInputList* list) { +Status OpKernelContext::input_list(StringPiece name, OpInputList* list) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); *list = OpInputList(this, start, stop); return Status::OK(); } -Status OpKernelContext::mutable_input_list(absl::string_view name, +Status OpKernelContext::mutable_input_list(StringPiece name, OpMutableInputList* list) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->InputRange(name, &start, &stop)); @@ -621,8 +619,7 @@ Status OpKernelContext::mutable_input_list(absl::string_view name, return Status::OK(); } -Status OpKernelContext::output_list(absl::string_view name, - OpOutputList* list) { +Status OpKernelContext::output_list(StringPiece name, OpOutputList* list) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->OutputRange(name, &start, &stop)); *list = OpOutputList(this, start, stop); @@ -645,7 +642,7 @@ Status OpKernelContext::allocate_output(int index, const TensorShape& shape, return allocate_output(index, shape, output, attr); } -Status OpKernelContext::allocate_output(absl::string_view name, +Status OpKernelContext::allocate_output(StringPiece name, const TensorShape& shape, Tensor** tensor) { int start, stop; @@ -659,7 +656,7 @@ Status OpKernelContext::allocate_output(absl::string_view name, return allocate_output(start, shape, tensor); } -Status OpKernelContext::allocate_output(absl::string_view name, +Status OpKernelContext::allocate_output(StringPiece name, const TensorShape& shape, Tensor** tensor, AllocatorAttributes attr) { @@ -755,8 +752,7 @@ Status OpKernelContext::allocate_persistent(DataType type, return s; } -Status OpKernelContext::set_output(absl::string_view name, - const Tensor& tensor) { +Status OpKernelContext::set_output(StringPiece name, const Tensor& tensor) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->OutputRange(name, &start, &stop)); if (stop != start + 1) { @@ -803,7 +799,7 @@ void OpKernelContext::set_output_ref(int index, mutex* mu, outputs_[index] = TensorValue(mu, tensor_for_ref); } -Status OpKernelContext::set_output_ref(absl::string_view name, mutex* mu, +Status OpKernelContext::set_output_ref(StringPiece name, mutex* mu, Tensor* tensor_for_ref) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->OutputRange(name, &start, &stop)); @@ -817,8 +813,7 @@ Status OpKernelContext::set_output_ref(absl::string_view name, mutex* mu, return Status::OK(); } -Status OpKernelContext::mutable_output(absl::string_view name, - Tensor** tensor) { +Status OpKernelContext::mutable_output(StringPiece name, Tensor** tensor) { int start, stop; TF_RETURN_IF_ERROR(params_->op_kernel->OutputRange(name, &start, &stop)); if (stop != start + 1) { @@ -916,7 +911,7 @@ void OpKernelContext::clear_recorded_memory() { // OpKernel registration ------------------------------------------------------ struct KernelRegistration { - KernelRegistration(const KernelDef& d, absl::string_view c, + KernelRegistration(const KernelDef& d, StringPiece c, kernel_factory::OpKernelRegistrar::Factory f) : def(d), kernel_class_name(c), factory(f) {} const KernelDef def; @@ -938,8 +933,8 @@ static KernelRegistry* GlobalKernelRegistryTyped() { return reinterpret_cast<KernelRegistry*>(GlobalKernelRegistry()); } -static string Key(absl::string_view op_type, const DeviceType& device_type, - absl::string_view label) { +static string Key(StringPiece op_type, const DeviceType& device_type, + StringPiece label) { return strings::StrCat(op_type, ":", DeviceTypeString(device_type), ":", label); } @@ -947,7 +942,7 @@ static string Key(absl::string_view op_type, const DeviceType& device_type, namespace kernel_factory { void OpKernelRegistrar::InitInternal(const KernelDef* kernel_def, - absl::string_view kernel_class_name, + StringPiece kernel_class_name, Factory factory) { // See comments in register_kernel::Name in header for info on _no_register. if (kernel_def->op() != "_no_register") { @@ -964,7 +959,7 @@ void OpKernelRegistrar::InitInternal(const KernelDef* kernel_def, namespace { -static const absl::string_view kKernelAttr("_kernel"); +static const StringPiece kKernelAttr("_kernel"); // TODO(irving): Replace with const Node& version below. Status FindKernelRegistration(const DeviceType& device_type, @@ -1077,12 +1072,12 @@ KernelList GetFilteredRegisteredKernels( return kernel_list; } -KernelList GetRegisteredKernelsForOp(absl::string_view op_name) { +KernelList GetRegisteredKernelsForOp(StringPiece op_name) { auto op_pred = [op_name](const KernelDef& k) { return k.op() == op_name; }; return GetFilteredRegisteredKernels(op_pred); } -string KernelsRegisteredForOp(absl::string_view op_name) { +string KernelsRegisteredForOp(StringPiece op_name) { KernelList kernel_list = GetRegisteredKernelsForOp(op_name); if (kernel_list.kernel_size() == 0) return " <no registered kernels>\n"; string ret; @@ -1180,7 +1175,7 @@ Status CreateOpKernel(DeviceType device_type, DeviceBase* device, namespace { -bool FindArgInOp(absl::string_view arg_name, +bool FindArgInOp(StringPiece arg_name, const protobuf::RepeatedPtrField<OpDef::ArgDef>& args) { for (const auto& arg : args) { if (arg_name == arg.name()) { diff --git a/tensorflow/core/framework/op_kernel.h b/tensorflow/core/framework/op_kernel.h index 7d48d35356f..3b1f57a4571 100644 --- a/tensorflow/core/framework/op_kernel.h +++ b/tensorflow/core/framework/op_kernel.h @@ -20,7 +20,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/cancellation.h" #include "tensorflow/core/framework/control_flow.h" @@ -143,9 +142,8 @@ class OpKernel { return output_memory_types_; } - Status InputRange(absl::string_view input_name, int* start, int* stop) const; - Status OutputRange(absl::string_view output_name, int* start, - int* stop) const; + Status InputRange(StringPiece input_name, int* start, int* stop) const; + Status OutputRange(StringPiece output_name, int* start, int* stop) const; // We allow legacy scalars within Google up until GraphDef version 6. // TODO(irving): Remove when we can drop support for GraphDef version 5. @@ -313,10 +311,10 @@ class OpKernelConstruction { // attr with attr_name is found in def(), or the attr does not have // a matching type, a non-ok status will be returned. template <class T> - Status GetAttr(absl::string_view attr_name, T* value) const; + Status GetAttr(StringPiece attr_name, T* value) const; // Return true if the attr_name is defined in def(). - bool HasAttr(absl::string_view attr_name) const; + bool HasAttr(StringPiece attr_name) const; // Return the device type. const DeviceType& device_type() const { return device_type_; } @@ -617,7 +615,7 @@ class OpKernelContext { int num_inputs() const { return params_->inputs->size(); } DataType input_dtype(int index) const; - Status input_dtype(absl::string_view name, DataType* dtype) const; + Status input_dtype(StringPiece name, DataType* dtype) const; MemoryType input_memory_type(int index) const; int num_outputs() const { return outputs_.size(); } @@ -637,14 +635,14 @@ class OpKernelContext { // use mutable_input below. // REQUIRES: !IsRefType(input_dtype(index)) // REQUIRES: the named input must not be a list. - Status input(absl::string_view name, const Tensor** tensor); + Status input(StringPiece name, const Tensor** tensor); // Returns the named list-valued immutable input in "list", as // defined in the OpDef. If the named output is not list-valued, // returns a one-element list. May only be used for non-Ref // inputs. For Ref inputs use mutable_input below. // REQUIRES: !IsRefType(input_dtype(index)) - Status input_list(absl::string_view name, OpInputList* list); + Status input_list(StringPiece name, OpInputList* list); // For mutable inputs, use the following together to make sure there // is no concurrent access to mutable_input(), e.g.: @@ -654,7 +652,7 @@ class OpKernelContext { // // modify the values in t // } // REQUIRES: IsRefType(input_dtype(index)) - Status input_ref_mutex(absl::string_view name, mutex** out_mutex); + Status input_ref_mutex(StringPiece name, mutex** out_mutex); // Returns a mutable input tensor. Must be used to access Ref // inputs. REQUIRES: IsRefType(input_dtype(index)). The caller may @@ -672,7 +670,7 @@ class OpKernelContext { // the input mutex will be acquired before returning the Tensor. // REQUIRES: the named input must not be a list. // REQUIRES: the named input must be a ref tensor. - Status mutable_input(absl::string_view name, Tensor* tensor, bool lock_held); + Status mutable_input(StringPiece name, Tensor* tensor, bool lock_held); // Returns the named list-valued mutable input in "list", as defined // in the OpDef. If the named input is not list-valued, returns a @@ -680,7 +678,7 @@ class OpKernelContext { // stored in the Tensor buffer may be modified, and modifications // will be visible to other Ops reading the same ref tensor. // REQUIRES: the named input must be a ref tensor. - Status mutable_input_list(absl::string_view name, OpMutableInputList* list); + Status mutable_input_list(StringPiece name, OpMutableInputList* list); // Replace the corresponding Ref Input to use the storage buffer // used by tensor. If !lock_held the input mutex will be acquired @@ -692,7 +690,7 @@ class OpKernelContext { // buffer used by tensor. If !lock_held the input mutex will be // acquired before returning the Tensor. // REQUIRES: IsRefType(input_dtype(index)). - Status replace_ref_input(absl::string_view name, const Tensor& tensor, + Status replace_ref_input(StringPiece name, const Tensor& tensor, bool lock_held); // Deletes the Tensor object used as the Ref Input at @@ -730,8 +728,8 @@ class OpKernelContext { bool forward_input_to_output_with_shape(int input_index, int output_index, const TensorShape& output_shape, Tensor** output) TF_MUST_USE_RESULT; - Status forward_input_to_output_with_shape(absl::string_view input_name, - absl::string_view output_name, + Status forward_input_to_output_with_shape(StringPiece input_name, + StringPiece output_name, const TensorShape& output_shape, Tensor** output) TF_MUST_USE_RESULT; @@ -775,8 +773,8 @@ class OpKernelContext { gtl::ArraySlice<int> candidate_input_indices, int output_index, const TensorShape& output_shape, Tensor** output) TF_MUST_USE_RESULT; Status forward_input_or_allocate_output( - gtl::ArraySlice<absl::string_view> candidate_input_names, - absl::string_view output_name, const TensorShape& output_shape, + gtl::ArraySlice<StringPiece> candidate_input_names, + StringPiece output_name, const TensorShape& output_shape, Tensor** output) TF_MUST_USE_RESULT; // Tries to reuse one of the inputs given in input_indices as a temporary. @@ -798,7 +796,7 @@ class OpKernelContext { // Returns the named list-valued output in "list", as defined in the OpDef. // If the named output is not list-valued, returns a one-element list. - Status output_list(absl::string_view name, OpOutputList* list); + Status output_list(StringPiece name, OpOutputList* list); // If output_required(index) returns true, the OpKernel's Compute() method // should call allocate_output(index, ...), set_output(index, ...), @@ -863,7 +861,7 @@ class OpKernelContext { // REQUIRES: !IsRefType(expected_output_dtype(index)) Status allocate_output(int index, const TensorShape& shape, Tensor** tensor) TF_MUST_USE_RESULT; - Status allocate_output(absl::string_view name, const TensorShape& shape, + Status allocate_output(StringPiece name, const TensorShape& shape, Tensor** tensor) TF_MUST_USE_RESULT; // The following methods use the supplied attributes instead of // those in output_attr_array. The caller is responsible for @@ -872,7 +870,7 @@ class OpKernelContext { // device. See comment above. Status allocate_output(int index, const TensorShape& shape, Tensor** tensor, AllocatorAttributes attr) TF_MUST_USE_RESULT; - Status allocate_output(absl::string_view name, const TensorShape& shape, + Status allocate_output(StringPiece name, const TensorShape& shape, Tensor** tensor, AllocatorAttributes attr) TF_MUST_USE_RESULT; @@ -915,16 +913,15 @@ class OpKernelContext { // index. REQUIRES: !IsRefType(expected_output_dtype(index)) // REQUIRES: 'tensor' must have the same MemoryType as // output_memory_types[index]. See comment above. - Status set_output(absl::string_view name, const Tensor& tensor); + Status set_output(StringPiece name, const Tensor& tensor); // To output a reference. Caller retains ownership of mu and tensor_for_ref, // and they must outlive all uses within the step. See comment above. // REQUIRES: IsRefType(expected_output_dtype(index)) - Status set_output_ref(absl::string_view name, mutex* mu, - Tensor* tensor_for_ref); + Status set_output_ref(StringPiece name, mutex* mu, Tensor* tensor_for_ref); // Returns nullptr if allocate_output() or set_output() have not been called. - Status mutable_output(absl::string_view name, Tensor** tensor); + Status mutable_output(StringPiece name, Tensor** tensor); // Records device specific state about how the input tensors were // computed. @@ -1227,7 +1224,7 @@ Status SupportedDeviceTypesForNode( // Returns a message with a description of the kernels registered for op // `op_name`. -string KernelsRegisteredForOp(absl::string_view op_name); +string KernelsRegisteredForOp(StringPiece op_name); // Call once after Op registration has completed. Status ValidateKernelRegistrations(const OpRegistryInterface& op_registry); @@ -1325,7 +1322,7 @@ KernelList GetFilteredRegisteredKernels( const std::function<bool(const KernelDef&)>& predicate); // Gets a list of all registered kernels for a given op -KernelList GetRegisteredKernelsForOp(absl::string_view op_name); +KernelList GetRegisteredKernelsForOp(StringPiece op_name); namespace kernel_factory { @@ -1333,8 +1330,8 @@ class OpKernelRegistrar { public: typedef OpKernel* (*Factory)(OpKernelConstruction*); - OpKernelRegistrar(const KernelDef* kernel_def, - absl::string_view kernel_class_name, Factory factory) { + OpKernelRegistrar(const KernelDef* kernel_def, StringPiece kernel_class_name, + Factory factory) { // Perform the check in the header to allow compile-time optimization // to a no-op, allowing the linker to remove the kernel symbols. if (kernel_def != nullptr) { @@ -1343,8 +1340,8 @@ class OpKernelRegistrar { } private: - void InitInternal(const KernelDef* kernel_def, - absl::string_view kernel_class_name, Factory factory); + void InitInternal(const KernelDef* kernel_def, StringPiece kernel_class_name, + Factory factory); }; } // namespace kernel_factory @@ -1353,8 +1350,7 @@ class OpKernelRegistrar { // Template and inline method implementations, please ignore template <class T> -Status OpKernelConstruction::GetAttr(absl::string_view attr_name, - T* value) const { +Status OpKernelConstruction::GetAttr(StringPiece attr_name, T* value) const { return GetNodeAttr(def(), attr_name, value); } @@ -1457,10 +1453,9 @@ inline Status OpKernelContext::forward_input_or_allocate_output( } inline Status OpKernelContext::forward_input_or_allocate_output( - gtl::ArraySlice<absl::string_view> candidate_input_names, - absl::string_view output_name, const TensorShape& output_shape, - Tensor** output) { - for (const absl::string_view& input_name : candidate_input_names) { + gtl::ArraySlice<StringPiece> candidate_input_names, StringPiece output_name, + const TensorShape& output_shape, Tensor** output) { + for (const StringPiece& input_name : candidate_input_names) { if (forward_input_to_output_with_shape(input_name, output_name, output_shape, output) .ok()) { diff --git a/tensorflow/core/framework/rendezvous.cc b/tensorflow/core/framework/rendezvous.cc index 3d14f221a3e..e84143f1b9a 100644 --- a/tensorflow/core/framework/rendezvous.cc +++ b/tensorflow/core/framework/rendezvous.cc @@ -20,7 +20,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/notification.h" #include "tensorflow/core/lib/gtl/flatmap.h" @@ -37,15 +36,15 @@ namespace tensorflow { Rendezvous::ParsedKey& Rendezvous::ParsedKey::operator=(const ParsedKey& b) { const char* b_base = b.buf_.data(); buf_ = b.buf_; - src_device = absl::string_view(buf_.data() + (b.src_device.data() - b_base), - b.src_device.size()); + src_device = StringPiece(buf_.data() + (b.src_device.data() - b_base), + b.src_device.size()); src = b.src; src_incarnation = b.src_incarnation; - dst_device = absl::string_view(buf_.data() + (b.dst_device.data() - b_base), - b.dst_device.size()); + dst_device = StringPiece(buf_.data() + (b.dst_device.data() - b_base), + b.dst_device.size()); dst = b.dst; - edge_name = absl::string_view(buf_.data() + (b.edge_name.data() - b_base), - b.edge_name.size()); + edge_name = StringPiece(buf_.data() + (b.edge_name.data() - b_base), + b.edge_name.size()); return *this; } @@ -69,22 +68,22 @@ string Rendezvous::CreateKey(const string& src_device, uint64 src_incarnation, // Return the prefix of "*s" up to the next occurrence of "delim", or // the whole remaining string if "delim" is not found. "*s" is advanced // past the string returned plus the delimiter (if found). -static absl::string_view ConsumeNextPart(absl::string_view* s, char delim) { +static StringPiece ConsumeNextPart(StringPiece* s, char delim) { for (size_t offset = 0; offset < s->size(); offset++) { if ((*s)[offset] == delim) { - absl::string_view result(s->data(), offset); + StringPiece result(s->data(), offset); s->remove_prefix(offset + 1); // +1: remove delim, as well return result; } } // No delimiter found: return rest of string - absl::string_view result(s->data(), s->size()); + StringPiece result(s->data(), s->size()); s->remove_prefix(s->size()); return result; } /* static */ -Status Rendezvous::ParseKey(absl::string_view key, ParsedKey* out) { +Status Rendezvous::ParseKey(StringPiece key, ParsedKey* out) { if (key.data() == out->buf_.data()) { // Caller used our buf_ string directly, so we don't need to copy. (The // SendOp and RecvOp implementations do this, for example). @@ -94,8 +93,8 @@ Status Rendezvous::ParseKey(absl::string_view key, ParsedKey* out) { // for the lifetime of the ParsedKey object. out->buf_.assign(key.data(), key.size()); } - absl::string_view s(out->buf_); - absl::string_view parts[5]; + StringPiece s(out->buf_); + StringPiece parts[5]; for (int i = 0; i < 5; i++) { parts[i] = ConsumeNextPart(&s, ';'); } @@ -105,9 +104,9 @@ Status Rendezvous::ParseKey(absl::string_view key, ParsedKey* out) { strings::HexStringToUint64(parts[1], &out->src_incarnation) && DeviceNameUtils::ParseFullName(parts[2], &out->dst) && !parts[3].empty()) { - out->src_device = absl::string_view(parts[0].data(), parts[0].size()); - out->dst_device = absl::string_view(parts[2].data(), parts[2].size()); - out->edge_name = absl::string_view(parts[3].data(), parts[3].size()); + out->src_device = StringPiece(parts[0].data(), parts[0].size()); + out->dst_device = StringPiece(parts[2].data(), parts[2].size()); + out->edge_name = StringPiece(parts[3].data(), parts[3].size()); return Status::OK(); } return errors::InvalidArgument("Invalid rendezvous key: ", key); @@ -278,7 +277,7 @@ class LocalRendezvousImpl : public Rendezvous { }; // We key the hash table by KeyHash of the Rendezvous::CreateKey string - static uint64 KeyHash(const absl::string_view& k) { + static uint64 KeyHash(const StringPiece& k) { return Hash64(k.data(), k.size()); } diff --git a/tensorflow/core/framework/rendezvous.h b/tensorflow/core/framework/rendezvous.h index 1e796a443d4..01e43e44e3f 100644 --- a/tensorflow/core/framework/rendezvous.h +++ b/tensorflow/core/framework/rendezvous.h @@ -18,7 +18,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/control_flow.h" #include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/framework/tensor.h" @@ -61,18 +60,18 @@ class Rendezvous : public core::RefCounted { // Parses the key constructed by CreateKey and parse src/dst device // names into structures respectively. struct ParsedKey { - absl::string_view src_device; + StringPiece src_device; DeviceNameUtils::ParsedName src; uint64 src_incarnation = 0; - absl::string_view dst_device; + StringPiece dst_device; DeviceNameUtils::ParsedName dst; - absl::string_view edge_name; + StringPiece edge_name; ParsedKey() {} ParsedKey(const ParsedKey& b) { *this = b; } ParsedKey& operator=(const ParsedKey& b); - absl::string_view FullKey() const { return buf_; } + StringPiece FullKey() const { return buf_; } private: friend class Rendezvous; @@ -80,7 +79,7 @@ class Rendezvous : public core::RefCounted { friend class RecvOp; string buf_; }; - static Status ParseKey(absl::string_view key, ParsedKey* out); + static Status ParseKey(StringPiece key, ParsedKey* out); // The caller is a tensor producer and it sends a message (a tensor // "val" and a bool "is_dead") under the given "key". diff --git a/tensorflow/core/framework/resource_mgr.cc b/tensorflow/core/framework/resource_mgr.cc index 31a5f8bd6d1..508a8d3149b 100644 --- a/tensorflow/core/framework/resource_mgr.cc +++ b/tensorflow/core/framework/resource_mgr.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/framework/resource_mgr.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_util.h" @@ -224,7 +223,7 @@ Status ResourceMgr::Cleanup(const string& container) { return Status::OK(); } -static bool IsValidContainerName(absl::string_view s) { +static bool IsValidContainerName(StringPiece s) { using ::tensorflow::strings::Scanner; return Scanner(s) .One(Scanner::LETTER_DIGIT_DOT) @@ -276,7 +275,7 @@ const ResourceHandle& HandleFromInput(OpKernelContext* ctx, int input) { return ctx->input(input).flat<ResourceHandle>()(0); } -Status HandleFromInput(OpKernelContext* ctx, absl::string_view input, +Status HandleFromInput(OpKernelContext* ctx, StringPiece input, ResourceHandle* handle) { const Tensor* tensor; TF_RETURN_IF_ERROR(ctx->input(input, &tensor)); diff --git a/tensorflow/core/framework/resource_mgr.h b/tensorflow/core/framework/resource_mgr.h index 703e2b6922f..4a531648d96 100644 --- a/tensorflow/core/framework/resource_mgr.h +++ b/tensorflow/core/framework/resource_mgr.h @@ -22,7 +22,6 @@ limitations under the License. #include <typeinfo> #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/resource_handle.h" @@ -245,7 +244,7 @@ ResourceHandle MakePerStepResourceHandle(OpKernelContext* ctx, // Returns a resource handle from a numbered op input. const ResourceHandle& HandleFromInput(OpKernelContext* ctx, int input); -Status HandleFromInput(OpKernelContext* ctx, absl::string_view input, +Status HandleFromInput(OpKernelContext* ctx, StringPiece input, ResourceHandle* handle); // Create a resource pointed by a given resource handle. diff --git a/tensorflow/core/framework/shape_inference.cc b/tensorflow/core/framework/shape_inference.cc index 174b2d6bdff..4dcc80680ff 100644 --- a/tensorflow/core/framework/shape_inference.cc +++ b/tensorflow/core/framework/shape_inference.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/framework/shape_inference.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb_text.h" #include "tensorflow/core/framework/partial_tensor_shape.h" #include "tensorflow/core/framework/tensor_shape.pb.h" @@ -173,7 +172,7 @@ Status InferenceContext::Run( return s; } -Status InferenceContext::set_output(absl::string_view output_name, +Status InferenceContext::set_output(StringPiece output_name, const std::vector<ShapeHandle>& shapes) { auto result = output_name_map_.find(output_name); if (result == output_name_map_.end()) { @@ -192,7 +191,7 @@ Status InferenceContext::set_output(absl::string_view output_name, return Status::OK(); } -Status InferenceContext::input(absl::string_view input_name, +Status InferenceContext::input(StringPiece input_name, std::vector<ShapeHandle>* output) const { const auto result = input_name_map_.find(input_name); if (result == input_name_map_.end()) { @@ -206,7 +205,7 @@ Status InferenceContext::input(absl::string_view input_name, return Status::OK(); } -Status InferenceContext::output(absl::string_view output_name, +Status InferenceContext::output(StringPiece output_name, std::vector<ShapeHandle>* output) const { const auto result = output_name_map_.find(output_name); if (result == output_name_map_.end()) { diff --git a/tensorflow/core/framework/shape_inference.h b/tensorflow/core/framework/shape_inference.h index 7fe27d1d9f4..e3885b7d9e8 100644 --- a/tensorflow/core/framework/shape_inference.h +++ b/tensorflow/core/framework/shape_inference.h @@ -17,7 +17,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/lib/core/errors.h" @@ -289,8 +288,7 @@ class InferenceContext { void SetInput(int idx, ShapeHandle shape) { inputs_[idx] = shape; } ShapeHandle input(int64 idx) const { return inputs_[idx]; } - Status input(absl::string_view input_name, - std::vector<ShapeHandle>* output) const; + Status input(StringPiece input_name, std::vector<ShapeHandle>* output) const; int num_inputs() const { return inputs_.size(); } // Returns the input tensor at index <idx>, or nullptr if the input tensor is @@ -327,12 +325,12 @@ class InferenceContext { ShapeHandle output(int64 idx) const { return outputs_.at(idx); } void set_output(int idx, ShapeHandle shape) { outputs_.at(idx) = shape; } - Status set_output(absl::string_view output_name, + Status set_output(StringPiece output_name, const std::vector<ShapeHandle>& shapes); int num_outputs() const { return outputs_.size(); } ShapeHandle output(int idx) const { return outputs_.at(idx); } - Status output(absl::string_view output_name, + Status output(StringPiece output_name, std::vector<ShapeHandle>* output) const; AttrSlice attrs() const { return AttrSlice(*node_def_); } @@ -527,7 +525,7 @@ class InferenceContext { // set *value to its value. If no attr with attr_name is found in def(), or // the attr does not have a matching type, a non-ok status will be returned. template <class T> - Status GetAttr(absl::string_view attr_name, T* value) const; + Status GetAttr(StringPiece attr_name, T* value) const; // Returns in <out> the result of dividing <dividend> by <divisor>. // Returns an error if <divisor> is not positive or if <evenly_divisible> @@ -818,7 +816,7 @@ inline DimensionOrConstant::DimensionOrConstant(int64 val) : val(val) { } template <class T> -Status InferenceContext::GetAttr(absl::string_view attr_name, T* value) const { +Status InferenceContext::GetAttr(StringPiece attr_name, T* value) const { return GetNodeAttr(*node_def_, attr_name, value); } diff --git a/tensorflow/core/framework/shape_inference_testutil.cc b/tensorflow/core/framework/shape_inference_testutil.cc index 214a4aee44f..b54dd220ab9 100644 --- a/tensorflow/core/framework/shape_inference_testutil.cc +++ b/tensorflow/core/framework/shape_inference_testutil.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/framework/shape_inference_testutil.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/lib/gtl/map_util.h" @@ -87,7 +86,7 @@ Status ShapeInferenceTestutil::InferShapes(ShapeInferenceTestOp op, " but should list ", num_outputs); } for (int i = 0; i < num_outputs; ++i) { - absl::string_view expected(expected_outs_v[i]); + StringPiece expected(expected_outs_v[i]); shape_inference::ShapeHandle out = c.output(i); string err_prefix = strings::StrCat("Output ", i); @@ -154,7 +153,7 @@ Status ShapeInferenceTestutil::InferShapes(ShapeInferenceTestOp op, } for (int j = 0; j < expected_dims.size(); ++j) { err_prefix = strings::StrCat("Output dim ", i, ",", j); - absl::string_view expected_dim(expected_dims[j]); + StringPiece expected_dim(expected_dims[j]); DimensionHandle out_dim = c.Dim(out, j); std::pair<int, int> in_dim_idx(-1, -1); @@ -246,7 +245,7 @@ Status ShapeInferenceTestutil::MakeShapeFromString( dims.push_back(manager->MakeDim(InferenceContext::kUnknownDim)); } else { scanner.RestartCapture().Many(strings::Scanner::DIGIT); - absl::string_view match; + StringPiece match; int64 dim_size = 0; if (!scanner.GetResult(nullptr, &match) || diff --git a/tensorflow/core/framework/shape_inference_testutil.h b/tensorflow/core/framework/shape_inference_testutil.h index deba5bb6f14..bb4dc25da4d 100644 --- a/tensorflow/core/framework/shape_inference_testutil.h +++ b/tensorflow/core/framework/shape_inference_testutil.h @@ -16,10 +16,10 @@ limitations under the License. #define TENSORFLOW_CORE_FRAMEWORK_SHAPE_INFERENCE_TESTUTIL_H_ #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/types.h" #include "tensorflow/core/public/version.h" @@ -32,7 +32,7 @@ class Tensor; struct ShapeInferenceTestOp { typedef std::pair<string, DataType> ShapeAndType; - explicit ShapeInferenceTestOp(absl::string_view name) : name(string(name)) {} + explicit ShapeInferenceTestOp(StringPiece name) : name(string(name)) {} string name; NodeDef node_def; std::vector<const Tensor*> input_tensors; diff --git a/tensorflow/core/framework/tensor.cc b/tensorflow/core/framework/tensor.cc index 50b39eb2ffe..1dea6da9113 100644 --- a/tensorflow/core/framework/tensor.cc +++ b/tensorflow/core/framework/tensor.cc @@ -29,7 +29,6 @@ limitations under the License. #include "tensorflow/core/framework/tensor.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/allocation_description.pb.h" #include "tensorflow/core/framework/log_memory.h" #include "tensorflow/core/framework/resource_handle.pb.h" @@ -134,8 +133,8 @@ struct Helper { template <typename Destination> static void Encode(TensorBuffer* in, int64 n, Destination* out) { DCHECK_EQ(in->size(), sizeof(T) * n); - port::AssignRefCounted( - absl::string_view(in->base<const char>(), in->size()), in, out); + port::AssignRefCounted(StringPiece(in->base<const char>(), in->size()), in, + out); } // Decoder of simple type T. Copy the bytes from "in" into the @@ -1149,10 +1148,9 @@ string Tensor::SummarizeValue(int64 max_entries, bool print_v2) const { } } -absl::string_view Tensor::tensor_data() const { - if (buf_ == nullptr) - return absl::string_view(); // Don't die for empty tensors - return absl::string_view(static_cast<char*>(buf_->data()), TotalBytes()); +StringPiece Tensor::tensor_data() const { + if (buf_ == nullptr) return StringPiece(); // Don't die for empty tensors + return StringPiece(static_cast<char*>(buf_->data()), TotalBytes()); } bool Tensor::SharesBufferWith(const Tensor& b) const { diff --git a/tensorflow/core/framework/tensor.h b/tensorflow/core/framework/tensor.h index c753b12698a..d0f9eb56e23 100644 --- a/tensorflow/core/framework/tensor.h +++ b/tensorflow/core/framework/tensor.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_FRAMEWORK_TENSOR_H_ #define TENSORFLOW_CORE_FRAMEWORK_TENSOR_H_ -#include "absl/strings/string_view.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -25,6 +24,7 @@ limitations under the License. #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/lib/core/refcount.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" @@ -469,7 +469,7 @@ class Tensor { /// not get destroyed while the `StringPiece` is still used. /// /// REQUIRES: `DataTypeCanUseMemcpy(dtype())`. - absl::string_view tensor_data() const; + StringPiece tensor_data() const; /// Copy the other tensor into this tensor and reshape it and reinterpret the /// buffer's datatype. diff --git a/tensorflow/core/framework/tensor_util.cc b/tensorflow/core/framework/tensor_util.cc index 37ab67fcbc1..65f6dc1c00b 100644 --- a/tensorflow/core/framework/tensor_util.cc +++ b/tensorflow/core/framework/tensor_util.cc @@ -16,9 +16,9 @@ limitations under the License. #include "tensorflow/core/framework/tensor_util.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/variant.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { namespace tensor { @@ -27,12 +27,12 @@ Tensor DeepCopy(const Tensor& other) { Tensor tmp = Tensor(other.dtype(), other.shape()); if (DataTypeCanUseMemcpy(other.dtype())) { if (other.NumElements() > 0) { - absl::string_view other_data = other.tensor_data(); + StringPiece other_data = other.tensor_data(); // We use StringPiece as a convenient map over the tensor buffer, // but we cast the type to get to the underlying buffer to do the // copy. - absl::string_view tmp_data = tmp.tensor_data(); + StringPiece tmp_data = tmp.tensor_data(); memcpy(const_cast<char*>(tmp_data.data()), other_data.data(), other_data.size()); } @@ -72,12 +72,12 @@ Status Concat(const gtl::ArraySlice<Tensor>& tensors, Tensor* result) { // We use StringPiece as a convenient map over the tensor buffer, // but we cast the type to get to the underlying buffer to do the // copy. - absl::string_view to_data = result->tensor_data(); + StringPiece to_data = result->tensor_data(); if (DataTypeCanUseMemcpy(dtype)) { int64 offset = 0; for (const Tensor& tensor : tensors) { - absl::string_view from_data = tensor.tensor_data(); + StringPiece from_data = tensor.tensor_data(); CHECK_LE(offset + from_data.size(), to_data.size()); memcpy(const_cast<char*>(to_data.data()) + offset, from_data.data(), from_data.size()); @@ -121,7 +121,7 @@ Status Split(const Tensor& tensor, const gtl::ArraySlice<int64>& sizes, "'tensor'"); } - absl::string_view from_data = tensor.tensor_data(); + StringPiece from_data = tensor.tensor_data(); if (DataTypeCanUseMemcpy(tensor.dtype())) { int64 offset = 0; @@ -134,7 +134,7 @@ Status Split(const Tensor& tensor, const gtl::ArraySlice<int64>& sizes, // We use StringPiece as a convenient map over the tensor buffer, // but we cast the type to get to the underlying buffer to do the // copy. - absl::string_view to_data = split->tensor_data(); + StringPiece to_data = split->tensor_data(); CHECK_LE(offset + to_data.size(), from_data.size()); memcpy(const_cast<char*>(to_data.data()), from_data.data() + offset, to_data.size()); diff --git a/tensorflow/core/framework/types.cc b/tensorflow/core/framework/types.cc index 944555f6832..2280114de51 100644 --- a/tensorflow/core/framework/types.cc +++ b/tensorflow/core/framework/types.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/framework/types.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -114,7 +113,7 @@ string DataTypeString(DataType dtype) { return DataTypeStringInternal(dtype); } -bool DataTypeFromString(absl::string_view sp, DataType* dt) { +bool DataTypeFromString(StringPiece sp, DataType* dt) { if (str_util::EndsWith(sp, "_ref")) { sp.remove_suffix(4); DataType non_ref; diff --git a/tensorflow/core/framework/types.h b/tensorflow/core/framework/types.h index e07877aa09c..2e96b057879 100644 --- a/tensorflow/core/framework/types.h +++ b/tensorflow/core/framework/types.h @@ -20,7 +20,6 @@ limitations under the License. #include <set> #include <string> -#include "absl/strings/string_view.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" // Disable clang-format to prevent 'FixedPoint' header from being included // before 'Tensor' header on which it depends. @@ -31,6 +30,7 @@ limitations under the License. #include "tensorflow/core/framework/numeric_types.h" #include "tensorflow/core/framework/resource_handle.h" #include "tensorflow/core/framework/types.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/platform/logging.h" @@ -56,8 +56,7 @@ class DeviceType { DeviceType(const char* type) // NOLINT(runtime/explicit) : type_(type) {} - explicit DeviceType(absl::string_view type) - : type_(type.data(), type.size()) {} + explicit DeviceType(StringPiece type) : type_(type.data(), type.size()) {} const char* type() const { return type_.c_str(); } const string& type_string() const { return type_; } @@ -229,7 +228,7 @@ class DataTypeSet { // If "sp" names a valid type, store it in "*dt" and return true. Otherwise, // return false. -bool DataTypeFromString(absl::string_view sp, DataType* dt); +bool DataTypeFromString(StringPiece sp, DataType* dt); constexpr inline DataTypeSet ToSet(DataType dt) { return DataTypeSet(1u << static_cast<uint32>(dt)); diff --git a/tensorflow/core/framework/variant_op_registry.cc b/tensorflow/core/framework/variant_op_registry.cc index f0891149190..ef5b240aeaa 100644 --- a/tensorflow/core/framework/variant_op_registry.cc +++ b/tensorflow/core/framework/variant_op_registry.cc @@ -15,7 +15,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/type_index.h" #include "tensorflow/core/framework/variant.h" @@ -90,7 +89,7 @@ REGISTER_VARIANT_SHAPE_TYPE(double); #undef REGISTER_VARIANT_SHAPE_TYPE UnaryVariantOpRegistry::VariantDecodeFn* UnaryVariantOpRegistry::GetDecodeFn( - absl::string_view type_name) { + StringPiece type_name) { auto found = decode_fns.find(type_name); if (found == decode_fns.end()) return nullptr; return &found->second; @@ -103,7 +102,7 @@ void UnaryVariantOpRegistry::RegisterDecodeFn( CHECK_EQ(existing, nullptr) << "Unary VariantDecodeFn for type_name: " << type_name << " already registered"; - decode_fns.insert(std::pair<absl::string_view, VariantDecodeFn>( + decode_fns.insert(std::pair<StringPiece, VariantDecodeFn>( GetPersistentStringPiece(type_name), decode_fn)); } @@ -180,7 +179,7 @@ Status VariantDeviceCopy( // Special casing UnaryOpFn per op and per device. UnaryVariantOpRegistry::VariantUnaryOpFn* UnaryVariantOpRegistry::GetUnaryOpFn( - VariantUnaryOp op, absl::string_view device, const TypeIndex& type_index) { + VariantUnaryOp op, StringPiece device, const TypeIndex& type_index) { auto found = unary_op_fns.find({op, device, type_index}); if (found == unary_op_fns.end()) return nullptr; return &found->second; @@ -222,8 +221,7 @@ REGISTER_VARIANT_ZEROS_LIKE_TYPE(bool); // Special casing BinaryOpFn per op and per device. UnaryVariantOpRegistry::VariantBinaryOpFn* -UnaryVariantOpRegistry::GetBinaryOpFn(VariantBinaryOp op, - absl::string_view device, +UnaryVariantOpRegistry::GetBinaryOpFn(VariantBinaryOp op, StringPiece device, const TypeIndex& type_index) { auto found = binary_op_fns.find({op, device, type_index}); if (found == binary_op_fns.end()) return nullptr; diff --git a/tensorflow/core/framework/variant_op_registry.h b/tensorflow/core/framework/variant_op_registry.h index dbbd6cebfc3..7eb37e859f5 100644 --- a/tensorflow/core/framework/variant_op_registry.h +++ b/tensorflow/core/framework/variant_op_registry.h @@ -19,7 +19,6 @@ limitations under the License. #include <string> #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #define EIGEN_USE_THREADS @@ -106,7 +105,7 @@ class UnaryVariantOpRegistry { const VariantDecodeFn& decode_fn); // Returns nullptr if no decode function was found for the given TypeName. - VariantDecodeFn* GetDecodeFn(absl::string_view type_name); + VariantDecodeFn* GetDecodeFn(StringPiece type_name); // Add a copy-to-GPU function to the registry. void RegisterDeviceCopyFn(const VariantDeviceCopyDirection direction, @@ -125,7 +124,7 @@ class UnaryVariantOpRegistry { // Returns nullptr if no unary op function was found for the given // op, device, and TypeName. - VariantUnaryOpFn* GetUnaryOpFn(VariantUnaryOp op, absl::string_view device, + VariantUnaryOpFn* GetUnaryOpFn(VariantUnaryOp op, StringPiece device, const TypeIndex& type_index); // Add a binary op function to the registry. @@ -135,7 +134,7 @@ class UnaryVariantOpRegistry { // Returns nullptr if no binary op function was found for the given // op, device and TypeName. - VariantBinaryOpFn* GetBinaryOpFn(VariantBinaryOp op, absl::string_view device, + VariantBinaryOpFn* GetBinaryOpFn(VariantBinaryOp op, StringPiece device, const TypeIndex& type_index); // Get a pointer to a global UnaryVariantOpRegistry object @@ -156,8 +155,7 @@ class UnaryVariantOpRegistry { }; gtl::FlatMap<TypeIndex, VariantShapeFn, TypeIndexHash> shape_fns; - gtl::FlatMap<absl::string_view, VariantDecodeFn, StringPieceHasher> - decode_fns; + gtl::FlatMap<StringPiece, VariantDecodeFn, StringPieceHasher> decode_fns; // Map std::pair<Direction, type_name> to function. struct PairHash { @@ -181,11 +179,10 @@ class UnaryVariantOpRegistry { // and references therein template <typename Op> struct FuncTuple { - FuncTuple(const Op& op, const absl::string_view& dev, - const TypeIndex& type_index) + FuncTuple(const Op& op, const StringPiece& dev, const TypeIndex& type_index) : op_type_(op), device_(dev), type_index_(type_index) {} Op op_type_; - absl::string_view device_; + StringPiece device_; TypeIndex type_index_; }; // friend declaration for operator== @@ -195,7 +192,7 @@ class UnaryVariantOpRegistry { struct TupleHash { template <typename Op> std::size_t operator()( - const std::tuple<Op, absl::string_view, TypeIndex>& x) const { + const std::tuple<Op, StringPiece, TypeIndex>& x) const { // The hash of an enum is just its value as a std::size_t. std::size_t ret = static_cast<std::size_t>(std::get<0>(x)); ret = Hash64Combine(ret, sp_hasher_(std::get<1>(x))); @@ -221,14 +218,14 @@ class UnaryVariantOpRegistry { // Find or insert a string into a persistent string storage // container; return the StringPiece pointing to the permanent string // location. - static absl::string_view GetPersistentStringPiece(const string& str) { + static StringPiece GetPersistentStringPiece(const string& str) { const auto string_storage = PersistentStringStorage(); auto found = string_storage->find(str); if (found == string_storage->end()) { auto inserted = string_storage->insert(str); - return absl::string_view(*inserted.first); + return StringPiece(*inserted.first); } else { - return absl::string_view(*found); + return StringPiece(*found); } } }; diff --git a/tensorflow/core/graph/costmodel.h b/tensorflow/core/graph/costmodel.h index 102cbb18b23..2d94dd5cdc8 100644 --- a/tensorflow/core/graph/costmodel.h +++ b/tensorflow/core/graph/costmodel.h @@ -19,18 +19,18 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/cost_graph.pb.h" #include "tensorflow/core/framework/step_stats.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/types.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/protobuf.h" namespace tensorflow { -typedef std::unordered_map<absl::string_view, int32, StringPieceHasher> +typedef std::unordered_map<StringPiece, int32, StringPieceHasher> NodeNameToCostIdMap; class StepStats; diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc index 91b0cdab8ef..bc0a6ae3465 100644 --- a/tensorflow/core/graph/graph.cc +++ b/tensorflow/core/graph/graph.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/graph/graph.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_util.h" @@ -550,7 +549,7 @@ Status Graph::AddFunctionLibrary(const FunctionDefLibrary& fdef_lib) { namespace { -void AddInput(NodeDef* dst, absl::string_view src_name, int src_slot) { +void AddInput(NodeDef* dst, StringPiece src_name, int src_slot) { if (src_slot == Graph::kControlSlot) { dst->add_input(strings::StrCat("^", src_name)); } else if (src_slot == 0) { @@ -636,7 +635,7 @@ void Graph::ToGraphDefSubRange(GraphDef* graph_def, int from_node_id) const { } } -string Graph::NewName(absl::string_view prefix) { +string Graph::NewName(StringPiece prefix) { return strings::StrCat(prefix, "/_", name_counter_++); } @@ -730,7 +729,7 @@ int Graph::InternDeviceName(const string& device_name) { return index; } -Status Graph::AddWhileContext(absl::string_view frame_name, +Status Graph::AddWhileContext(StringPiece frame_name, std::vector<Node*> enter_nodes, std::vector<Node*> exit_nodes, OutputTensor cond_output, diff --git a/tensorflow/core/graph/graph.h b/tensorflow/core/graph/graph.h index 1993d073dee..027ab522ed1 100644 --- a/tensorflow/core/graph/graph.h +++ b/tensorflow/core/graph/graph.h @@ -40,7 +40,6 @@ limitations under the License. #include <functional> #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/types.h" @@ -535,7 +534,7 @@ class Graph { // Generate new node name with the specified prefix that is unique // across this graph. - string NewName(absl::string_view prefix); + string NewName(StringPiece prefix); // Access to the list of all nodes. Example usage: // for (Node* node : graph.nodes()) { ... } @@ -608,8 +607,7 @@ class Graph { // Create and return a new WhileContext owned by this graph. This is called // when a new while loop is created. `frame_name` must be unique among // WhileContexts in this graph. - Status AddWhileContext(absl::string_view frame_name, - std::vector<Node*> enter_nodes, + Status AddWhileContext(StringPiece frame_name, std::vector<Node*> enter_nodes, std::vector<Node*> exit_nodes, OutputTensor cond_output, std::vector<OutputTensor> body_inputs, diff --git a/tensorflow/core/graph/graph_constructor.cc b/tensorflow/core/graph/graph_constructor.cc index d70fb6a1826..eeb5c14eaa5 100644 --- a/tensorflow/core/graph/graph_constructor.cc +++ b/tensorflow/core/graph/graph_constructor.cc @@ -21,7 +21,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/shape_refiner.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/function.pb.h" @@ -54,7 +53,7 @@ inline bool IsNextIteration(const NodeDef& node_def) { node_def.op() == "RefNextIteration"; } -bool IsValidNodeName(absl::string_view s, bool allow_internal_ops) { +bool IsValidNodeName(StringPiece s, bool allow_internal_ops) { using ::tensorflow::strings::Scanner; return Scanner(s) .One(allow_internal_ops ? Scanner::LETTER_DIGIT_DOT_UNDERSCORE @@ -218,15 +217,15 @@ class GraphConstructor { // Returns true if `name` already exists in `g_` (either as a node name or // prefix). - bool NameExistsInGraph(absl::string_view name); + bool NameExistsInGraph(StringPiece name); // Returns true if `name` already exists in the GraphDef being imported // (either as a node name or prefix). - bool NameExistsInGraphDef(absl::string_view name); + bool NameExistsInGraphDef(StringPiece name); // Returns a unique version of `original_name`, or `original_name` if it's // already unique in the graph. - string FindUniqueName(absl::string_view original_name); + string FindUniqueName(StringPiece original_name); // Decrement pending count for users of `processed` and add the ones that now // have all of their pending inputs satisfied to `ready_`. @@ -268,18 +267,16 @@ class GraphConstructor { }; // TODO(vrv): Profile this data structure to see if we should use an // alternative implementation of std::unordered_map. - std::unordered_map<absl::string_view, NodeInfo, StringPieceHasher> - gdef_nodes_; + std::unordered_map<StringPiece, NodeInfo, StringPieceHasher> gdef_nodes_; // Prefixes already used in the GraphDef being imported. - std::unordered_set<absl::string_view, StringPieceHasher> gdef_prefixes_; + std::unordered_set<StringPiece, StringPieceHasher> gdef_prefixes_; // Mapping from node name to the existing node in g_. - std::unordered_map<absl::string_view, Node*, StringPieceHasher> - existing_nodes_; + std::unordered_map<StringPiece, Node*, StringPieceHasher> existing_nodes_; // Prefixes already used in the graph. - std::unordered_set<absl::string_view, StringPieceHasher> existing_prefixes_; + std::unordered_set<StringPiece, StringPieceHasher> existing_prefixes_; // Imported node names that have been uniquified. The key is the original // name, the value is the new unique name. @@ -344,7 +341,7 @@ void GraphConstructor::UpdatePendingCountAndReady(int processed) { // This could be expensive but we don't expect to call it often, if at all (only // if there are multiple nodes in g_ with the same name) bool NodeNameInValues(const std::map<TensorId, TensorId>& input_map, - const absl::string_view& node_name) { + const StringPiece& node_name) { for (auto iter = input_map.begin(); iter != input_map.end(); ++iter) { if (iter->second.first == node_name) return true; } @@ -352,18 +349,17 @@ bool NodeNameInValues(const std::map<TensorId, TensorId>& input_map, } bool NodeNameInValues(const std::vector<string>& control_dependencies, - const absl::string_view& node_name) { + const StringPiece& node_name) { return std::find(control_dependencies.begin(), control_dependencies.end(), node_name) != control_dependencies.end(); } // Adds any prefixes of `node_name` (not including the full name itself) to // `prefixes`. -void AddPrefixes( - absl::string_view node_name, - std::unordered_set<absl::string_view, StringPieceHasher>* prefixes) { +void AddPrefixes(StringPiece node_name, + std::unordered_set<StringPiece, StringPieceHasher>* prefixes) { size_t idx = -1; - while ((idx = node_name.find('/', idx + 1)) != absl::string_view::npos) { + while ((idx = node_name.find('/', idx + 1)) != StringPiece::npos) { prefixes->insert(node_name.substr(0, idx)); } } @@ -397,7 +393,7 @@ Status GraphConstructor::EnsureNoNameCollisions() { } } } else if (!prefix_.empty()) { - absl::string_view prefix_no_slash(prefix_); + StringPiece prefix_no_slash(prefix_); prefix_no_slash.remove_suffix(1); if (!IsValidNodeName(prefix_no_slash, false)) { return errors::InvalidArgument("Imported node name prefix '", prefix_, @@ -447,8 +443,7 @@ Status GraphConstructor::BuildNodeIndex() { "': Node name contains invalid characters"); } if (!gdef_nodes_ - .insert(std::make_pair(absl::string_view(node_def.name()), - NodeInfo(n))) + .insert(std::make_pair(StringPiece(node_def.name()), NodeInfo(n))) .second) { return errors::InvalidArgument("Node '", node_def.name(), "' is not unique"); @@ -465,7 +460,7 @@ Status GraphConstructor::BuildNodeIndex() { // Validate control edges at end bool in_control_dependence = false; for (int i = 0; i < node_def.input_size(); ++i) { - absl::string_view input_name = node_def.input(i); + StringPiece input_name = node_def.input(i); if (!input_name.empty() && str_util::StartsWith(input_name, "^")) { in_control_dependence = true; } else if (in_control_dependence) { @@ -513,7 +508,7 @@ Status GraphConstructor::InitFromEdges() { int32 num_control_edges = 0; bool has_loop_back_edge = false; for (int i = 0; i < node_def.input_size(); ++i) { - absl::string_view input_name(node_def.input(i)); + StringPiece input_name(node_def.input(i)); if (str_util::StartsWith(input_name, "^")) { num_control_edges++; } else { @@ -529,7 +524,7 @@ Status GraphConstructor::InitFromEdges() { } } for (int i = 0; i < node_def.input_size(); ++i) { - absl::string_view input_name = node_def.input(i); + StringPiece input_name = node_def.input(i); TensorId id(ParseTensorName(input_name)); if (opts_.input_map.count(id) == 0) { // If an input is not mapped, then the input should appear in the graph @@ -563,7 +558,7 @@ Status GraphConstructor::ValidateColocationConstraints( const auto iter = node_def.attr().find(kColocationAttrName); if (iter == node_def.attr().end()) return Status::OK(); for (const string& c : iter->second.list().s()) { - absl::string_view s(c); + StringPiece s(c); if (str_util::ConsumePrefix(&s, kColocationGroupPrefix) && gdef_nodes_.find(s) == gdef_nodes_.end()) { return errors::InvalidArgument( @@ -802,7 +797,7 @@ void GraphConstructor::AddPrefixToNodeDef( // Skip remapped inputs (which already exist in g_ and are not being // imported). if (input_already_exists[i]) continue; - absl::string_view input(node_def->input(i)); + StringPiece input(node_def->input(i)); if (str_util::ConsumePrefix(&input, "^")) { node_def->set_input(i, strings::StrCat("^", prefix_, input)); } else { @@ -814,7 +809,7 @@ void GraphConstructor::AddPrefixToNodeDef( auto* list = node_def->mutable_attr()->at(kColocationAttrName).mutable_list(); for (int i = 0; i < list->s_size(); ++i) { - absl::string_view v(list->s(i)); + StringPiece v(list->s(i)); if (str_util::ConsumePrefix(&v, kColocationGroupPrefix)) { list->set_s(i, strings::StrCat(kColocationGroupPrefix, prefix_, v)); } @@ -857,7 +852,7 @@ void GraphConstructor::UpdateUniquifiedColocationNames() { if (!status.ok()) continue; bool updated = false; for (int i = 0; i < coloc_values.size(); ++i) { - absl::string_view val(coloc_values[i]); + StringPiece val(coloc_values[i]); if (str_util::ConsumePrefix(&val, kColocationGroupPrefix)) { const auto& name_pair = uniquified_names_.find(string(val)); if (name_pair == uniquified_names_.end()) continue; @@ -872,19 +867,19 @@ void GraphConstructor::UpdateUniquifiedColocationNames() { } } -bool GraphConstructor::NameExistsInGraph(absl::string_view name) { +bool GraphConstructor::NameExistsInGraph(StringPiece name) { if (existing_nodes_.find(name) != existing_nodes_.end()) return true; if (existing_prefixes_.find(name) != existing_prefixes_.end()) return true; return false; } -bool GraphConstructor::NameExistsInGraphDef(absl::string_view name) { +bool GraphConstructor::NameExistsInGraphDef(StringPiece name) { if (gdef_nodes_.find(name) != gdef_nodes_.end()) return true; if (gdef_prefixes_.find(name) != gdef_prefixes_.end()) return true; return false; } -string GraphConstructor::FindUniqueName(absl::string_view original_name) { +string GraphConstructor::FindUniqueName(StringPiece original_name) { string name(original_name); int count = 0; // Check that any generated names don't collide with imported NodeDefs (as @@ -1137,7 +1132,7 @@ Status GraphConstructor::PopulateReturnTensors() { Status GraphConstructor::PopulateReturnNodes() { if (opts_.return_nodes.empty()) return Status::OK(); - for (absl::string_view name : opts_.return_nodes) { + for (StringPiece name : opts_.return_nodes) { auto iter = gdef_nodes_.find(name); if (iter == gdef_nodes_.end()) { return errors::InvalidArgument("Requested return node '", name, diff --git a/tensorflow/core/graph/graph_constructor_test.cc b/tensorflow/core/graph/graph_constructor_test.cc index 395e88a59de..3eef6bd2bd2 100644 --- a/tensorflow/core/graph/graph_constructor_test.cc +++ b/tensorflow/core/graph/graph_constructor_test.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/graph/graph_constructor.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/shape_refiner.h" #include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/graph.pb.h" @@ -156,7 +155,7 @@ class GraphConstructorTest : public ::testing::Test { "value for the _class attribute. Update it and its callers"; return ""; } - absl::string_view loc(value[0]); + StringPiece loc(value[0]); return str_util::ConsumePrefix(&loc, kColocationGroupPrefix) ? string(loc) : ""; } diff --git a/tensorflow/core/graph/graph_def_builder.cc b/tensorflow/core/graph/graph_def_builder.cc index 02256ae6f9e..6d5df7efba7 100644 --- a/tensorflow/core/graph/graph_def_builder.cc +++ b/tensorflow/core/graph/graph_def_builder.cc @@ -17,7 +17,6 @@ limitations under the License. #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/lib/core/errors.h" @@ -28,11 +27,11 @@ GraphDefBuilder::Options::Options(Graph* graph, Status* status) GraphDefBuilder::Options::~Options() {} GraphDefBuilder::Options GraphDefBuilder::Options::WithName( - absl::string_view name) const { + StringPiece name) const { return Options(*this).WithNameImpl(name); } GraphDefBuilder::Options GraphDefBuilder::Options::WithDevice( - absl::string_view device) const { + StringPiece device) const { return Options(*this).WithDeviceImpl(device); } GraphDefBuilder::Options GraphDefBuilder::Options::WithControlInput( @@ -44,12 +43,12 @@ GraphDefBuilder::Options GraphDefBuilder::Options::WithControlInputs( return Options(*this).WithControlInputsImpl(control_inputs); } GraphDefBuilder::Options GraphDefBuilder::Options::WithNameImpl( - absl::string_view name) { + StringPiece name) { name_ = string(name); return *this; } GraphDefBuilder::Options GraphDefBuilder::Options::WithDeviceImpl( - absl::string_view device) { + StringPiece device) { device_ = string(device); return *this; } @@ -72,7 +71,7 @@ Status GraphDefBuilder::ToGraphDef(GraphDef* graph_def) const { return status_; } -string GraphDefBuilder::Options::GetNameForOp(absl::string_view op) const { +string GraphDefBuilder::Options::GetNameForOp(StringPiece op) const { if (name_.empty()) return graph_->NewName(op); return name_; } diff --git a/tensorflow/core/graph/graph_def_builder.h b/tensorflow/core/graph/graph_def_builder.h index e0528742d4d..400d8b6c84e 100644 --- a/tensorflow/core/graph/graph_def_builder.h +++ b/tensorflow/core/graph/graph_def_builder.h @@ -17,12 +17,12 @@ limitations under the License. #define TENSORFLOW_CORE_GRAPH_GRAPH_DEF_BUILDER_H_ #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" namespace tensorflow { @@ -76,19 +76,19 @@ class GraphDefBuilder { // Methods for setting options. These are const methods: they // return a copy of *this with the option set. - Options WithName(absl::string_view name) const; - Options WithDevice(absl::string_view device) const; + Options WithName(StringPiece name) const; + Options WithDevice(StringPiece device) const; Options WithControlInput(Node* control_input) const; Options WithControlInputs(gtl::ArraySlice<Node*> control_inputs) const; // Override the default value for an optional attr. template <class T> - Options WithAttr(absl::string_view attr_name, T&& value) const { + Options WithAttr(StringPiece attr_name, T&& value) const { return Options(*this).WithAttrImpl(attr_name, std::forward<T>(value)); } // Note: overload needed to allow {...} expressions for value. template <class T> - Options WithAttr(absl::string_view attr_name, + Options WithAttr(StringPiece attr_name, std::initializer_list<T> value) const { return WithAttr<std::initializer_list<T>>(attr_name, std::move(value)); } @@ -106,7 +106,7 @@ class GraphDefBuilder { // Given the Op type name, return a name for a node of that type. // Uses the value set in WithName() if that has been called. Otherwise, // returns a name built out of the Op type name. - string GetNameForOp(absl::string_view op) const; + string GetNameForOp(StringPiece op) const; // Sets the device, adds control inputs, adds attrs, and calls Finalize(). // If Finalize returns an error, it is saved and this function returns @@ -122,12 +122,12 @@ class GraphDefBuilder { } private: - Options WithNameImpl(absl::string_view name); - Options WithDeviceImpl(absl::string_view device); + Options WithNameImpl(StringPiece name); + Options WithDeviceImpl(StringPiece device); Options WithControlInputImpl(Node* control_input); Options WithControlInputsImpl(gtl::ArraySlice<Node*> control_inputs); template <class T> - Options WithAttrImpl(absl::string_view name, T&& value) { + Options WithAttrImpl(StringPiece name, T&& value) { attrs_.emplace_back(string(name), AttrValue()); SetAttrValue(std::forward<T>(value), &attrs_.back().second); return *this; diff --git a/tensorflow/core/graph/graph_partition.cc b/tensorflow/core/graph/graph_partition.cc index 9446e7cf6bc..1dbcebab598 100644 --- a/tensorflow/core/graph/graph_partition.cc +++ b/tensorflow/core/graph/graph_partition.cc @@ -22,7 +22,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/memory_types.h" #include "tensorflow/core/framework/node_def_builder.h" #include "tensorflow/core/framework/tensor.pb.h" @@ -156,7 +155,7 @@ bool IsDstInputOnHost(const Edge* edge, const GraphInfo& info) { // Add an input to dst that comes from the "src_slot" output of the // node named by "src_name". -void AddInput(NodeDef* dst, absl::string_view src_name, int src_slot) { +void AddInput(NodeDef* dst, StringPiece src_name, int src_slot) { if (src_slot == Graph::kControlSlot) { dst->add_input(strings::StrCat("^", src_name)); } else if (src_slot == 0) { @@ -912,7 +911,7 @@ Status AddControlEdges(const PartitionOptions& opts, // If 'ndef' is a Send or Recv, fills its attr send_device_incarnation // if possible. void SetIncarnation(const PartitionOptions& opts, NodeDef* ndef) { - absl::string_view op(ndef->op()); + StringPiece op(ndef->op()); if (op != "_Send" && op != "_Recv") { // Not related to send/recv. return; diff --git a/tensorflow/core/graph/node_builder.cc b/tensorflow/core/graph/node_builder.cc index 5f5587cef62..68a20fcc5f3 100644 --- a/tensorflow/core/graph/node_builder.cc +++ b/tensorflow/core/graph/node_builder.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/graph/node_builder.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/versions.pb.h" #include "tensorflow/core/lib/core/errors.h" @@ -30,17 +29,17 @@ NodeBuilder::NodeOut::NodeOut(Node* n, int32 i) // NOLINT(runtime/explicit) index(i), dt(SafeGetOutput(node, i, &error)) {} -NodeBuilder::NodeOut::NodeOut(absl::string_view n, int32 i, DataType t) +NodeBuilder::NodeOut::NodeOut(StringPiece n, int32 i, DataType t) : node(nullptr), error(false), name(n), index(i), dt(t) {} NodeBuilder::NodeOut::NodeOut() : node(nullptr), error(true), index(0), dt(DT_FLOAT) {} -NodeBuilder::NodeBuilder(absl::string_view name, absl::string_view op_name, +NodeBuilder::NodeBuilder(StringPiece name, StringPiece op_name, const OpRegistryInterface* op_registry) : def_builder_(name, op_name, op_registry) {} -NodeBuilder::NodeBuilder(absl::string_view name, const OpDef* op_def) +NodeBuilder::NodeBuilder(StringPiece name, const OpDef* op_def) : def_builder_(name, op_def) {} NodeBuilder::NodeBuilder(const NodeDefBuilder& def_builder) @@ -95,12 +94,12 @@ NodeBuilder& NodeBuilder::ControlInputs(gtl::ArraySlice<Node*> src_nodes) { return *this; } -NodeBuilder& NodeBuilder::Device(absl::string_view device_spec) { +NodeBuilder& NodeBuilder::Device(StringPiece device_spec) { def_builder_.Device(device_spec); return *this; } -NodeBuilder& NodeBuilder::AssignedDevice(absl::string_view device) { +NodeBuilder& NodeBuilder::AssignedDevice(StringPiece device) { assigned_device_ = string(device); return *this; } diff --git a/tensorflow/core/graph/node_builder.h b/tensorflow/core/graph/node_builder.h index f2baea606ad..d576985a232 100644 --- a/tensorflow/core/graph/node_builder.h +++ b/tensorflow/core/graph/node_builder.h @@ -17,12 +17,12 @@ limitations under the License. #define TENSORFLOW_CORE_GRAPH_NODE_BUILDER_H_ #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def_builder.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" namespace tensorflow { @@ -55,7 +55,7 @@ class NodeBuilder { // useful when preparing a graph for ExtendSession or creating a // back edge to a node that hasn't been added to the graph yet, // but will be. - NodeOut(absl::string_view name, int32 i, DataType t); + NodeOut(StringPiece name, int32 i, DataType t); // Default constructor for std::vector<NodeOut>. NodeOut(); @@ -75,9 +75,9 @@ class NodeBuilder { // the Op plus a registry) for the Node. Other fields are // specified by calling the methods below. // REQUIRES: The OpDef must satisfy ValidateOpDef(). - NodeBuilder(absl::string_view name, absl::string_view op_name, + NodeBuilder(StringPiece name, StringPiece op_name, const OpRegistryInterface* op_registry = OpRegistry::Global()); - NodeBuilder(absl::string_view name, const OpDef* op_def); + NodeBuilder(StringPiece name, const OpDef* op_def); // Create a NodeBuilder from an existing NodeDefBuilder. NodeBuilder(const NodeDefBuilder& def_builder); @@ -98,10 +98,10 @@ class NodeBuilder { // Sets the "requested device spec" in the NodeDef (not the // "assigned device" in the Node). - NodeBuilder& Device(absl::string_view device_spec); + NodeBuilder& Device(StringPiece device_spec); // Sets the device name in the "assigned device" field in tensorflow::Node. - NodeBuilder& AssignedDevice(absl::string_view device); + NodeBuilder& AssignedDevice(StringPiece device); // Set the value of an attr. attr_name must match the name of one of // attrs defined by the Op, and value must have the corresponding type @@ -109,10 +109,9 @@ class NodeBuilder { // types for value). Note that attrs will be set automatically if // they can be determined by the inputs. template <class T> - NodeBuilder& Attr(absl::string_view attr_name, T&& value); + NodeBuilder& Attr(StringPiece attr_name, T&& value); template <class T> - NodeBuilder& Attr(absl::string_view attr_name, - std::initializer_list<T> value); + NodeBuilder& Attr(StringPiece attr_name, std::initializer_list<T> value); // Validates the described node and adds it to *graph, adding edges // for all (non-back) inputs. If created_node is not nullptr, @@ -151,13 +150,13 @@ class NodeBuilder { // IMPLEMENTATION ------------------------------------------------------------- template <class T> -NodeBuilder& NodeBuilder::Attr(absl::string_view attr_name, T&& value) { +NodeBuilder& NodeBuilder::Attr(StringPiece attr_name, T&& value) { def_builder_.Attr(attr_name, std::forward<T>(value)); return *this; } template <class T> -NodeBuilder& NodeBuilder::Attr(absl::string_view attr_name, +NodeBuilder& NodeBuilder::Attr(StringPiece attr_name, std::initializer_list<T> value) { def_builder_.Attr(attr_name, value); return *this; diff --git a/tensorflow/core/graph/quantize_training.cc b/tensorflow/core/graph/quantize_training.cc index 91ed6d60826..3b6e8cc2339 100644 --- a/tensorflow/core/graph/quantize_training.cc +++ b/tensorflow/core/graph/quantize_training.cc @@ -19,7 +19,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/graph/quantize_training.h" #include "tensorflow/core/common_runtime/executor.h" @@ -154,7 +153,7 @@ Status FindSaveOp(const Graph* graph, Node** save_op, return Status::OK(); } -Node* FindRestoreAllOp(const Graph* graph, absl::string_view save_prefix) { +Node* FindRestoreAllOp(const Graph* graph, StringPiece save_prefix) { for (Node* node : graph->op_nodes()) { // The restore_all op should have the same prefix of the save_op. if (node->name() == strings::StrCat(save_prefix, "/restore_all")) { @@ -167,8 +166,8 @@ Node* FindRestoreAllOp(const Graph* graph, absl::string_view save_prefix) { // Strips the last "/suffix" from a name. // We use this to construct the name of restore ops in the same way they are // constructed by the Saver. -absl::string_view GetNodeNamePrefix(const Node* node) { - absl::string_view name = node->name(); +StringPiece GetNodeNamePrefix(const Node* node) { + StringPiece name = node->name(); return name.substr(0, name.rfind('/')); } @@ -252,7 +251,7 @@ Status AddRestoreVariableSubgraphs(Graph* graph, Node* save_op, const std::vector<const Edge*>& in_edges, const std::vector<Node*>& variables) { Node* prefix_op = in_edges[0]->src(); - absl::string_view name_prefix = GetNodeNamePrefix(save_op); + StringPiece name_prefix = GetNodeNamePrefix(save_op); Node* restore_all = FindRestoreAllOp(graph, name_prefix); if (restore_all == nullptr) { return errors::InvalidArgument("graph has SaveOp, but no restore_all NoOp"); diff --git a/tensorflow/core/graph/subgraph.cc b/tensorflow/core/graph/subgraph.cc index 96c5191a0a4..60337e30aa5 100644 --- a/tensorflow/core/graph/subgraph.cc +++ b/tensorflow/core/graph/subgraph.cc @@ -22,7 +22,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/types.h" @@ -45,8 +44,7 @@ namespace subgraph { namespace { -typedef std::unordered_map<absl::string_view, Node*, StringPieceHasher> - NameIndex; +typedef std::unordered_map<StringPiece, Node*, StringPieceHasher> NameIndex; // Rewrite graph by replacing the output tensors specified in // "fed_outputs" with special feed nodes for each specified output diff --git a/tensorflow/core/graph/subgraph_test.cc b/tensorflow/core/graph/subgraph_test.cc index cb3e7771aed..6c014a8d443 100644 --- a/tensorflow/core/graph/subgraph_test.cc +++ b/tensorflow/core/graph/subgraph_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/partial_tensor_shape.h" #include "tensorflow/core/graph/graph.h" @@ -313,7 +312,7 @@ TEST_F(SubgraphTest, ChainOfFools) { EXPECT_TRUE(HasEdge("e", 0, "_send_e_0", 0)); } -static bool HasSubstr(absl::string_view base, absl::string_view substr) { +static bool HasSubstr(StringPiece base, StringPiece substr) { bool ok = str_util::StrContains(base, substr); EXPECT_TRUE(ok) << base << ", expected substring " << substr; return ok; diff --git a/tensorflow/core/graph/tensor_id.cc b/tensorflow/core/graph/tensor_id.cc index 3a8317d757e..5a5b85e7273 100644 --- a/tensorflow/core/graph/tensor_id.cc +++ b/tensorflow/core/graph/tensor_id.cc @@ -17,7 +17,7 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -28,10 +28,10 @@ SafeTensorId::SafeTensorId(const TensorId& id) : SafeTensorId(string(id.first), id.second) {} TensorId ParseTensorName(const string& name) { - return ParseTensorName(absl::string_view(name.data(), name.size())); + return ParseTensorName(StringPiece(name.data(), name.size())); } -TensorId ParseTensorName(absl::string_view name) { +TensorId ParseTensorName(StringPiece name) { // Parse either a name, ^name, or name:digits. To do so, we go backwards from // the end of the string, skipping over a run of digits. If we hit a ':' // character, then we know we are in the 'name:digits' regime. Otherwise, we @@ -49,11 +49,11 @@ TensorId ParseTensorName(absl::string_view name) { } TensorId id; if (p > base && *p == ':' && mul > 1) { - id.first = absl::string_view(base, p - base); + id.first = StringPiece(base, p - base); id.second = index; } else if (str_util::StartsWith(name, "^")) { // Control edge - id.first = absl::string_view(base + 1); + id.first = StringPiece(base + 1); id.second = Graph::kControlSlot; } else { id.first = name; diff --git a/tensorflow/core/graph/tensor_id.h b/tensorflow/core/graph/tensor_id.h index fb1d7f50820..0ba39426184 100644 --- a/tensorflow/core/graph/tensor_id.h +++ b/tensorflow/core/graph/tensor_id.h @@ -18,8 +18,8 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/graph/graph.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -30,8 +30,8 @@ struct SafeTensorId; // Identifier for a tensor within a step. // first == operation_name, second == output_index // Note: does not own backing storage for name. -struct TensorId : public std::pair<absl::string_view, int> { - typedef std::pair<absl::string_view, int> Base; +struct TensorId : public std::pair<StringPiece, int> { + typedef std::pair<StringPiece, int> Base; // Inherit the set of constructors. using Base::pair; @@ -55,7 +55,7 @@ struct TensorId : public std::pair<absl::string_view, int> { }; TensorId ParseTensorName(const string& name); -TensorId ParseTensorName(absl::string_view name); +TensorId ParseTensorName(StringPiece name); // Same as TensorId, except owns the backing storage for the op name. This makes // the memory management simpler at the expense of a copy. diff --git a/tensorflow/core/graph/while_context.cc b/tensorflow/core/graph/while_context.cc index 31b3c56f9d1..8e89bc4c758 100644 --- a/tensorflow/core/graph/while_context.cc +++ b/tensorflow/core/graph/while_context.cc @@ -14,11 +14,10 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/graph/while_context.h" -#include "absl/strings/string_view.h" namespace tensorflow { -WhileContext::WhileContext(absl::string_view frame_name, +WhileContext::WhileContext(StringPiece frame_name, std::vector<Node*> enter_nodes, std::vector<Node*> exit_nodes, OutputTensor cond_output, diff --git a/tensorflow/core/graph/while_context.h b/tensorflow/core/graph/while_context.h index 310dcd712ed..5405e62be2f 100644 --- a/tensorflow/core/graph/while_context.h +++ b/tensorflow/core/graph/while_context.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_GRAPH_WHILE_CONTEXT_H_ #define TENSORFLOW_CORE_GRAPH_WHILE_CONTEXT_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/graph/graph.h" namespace tensorflow { @@ -35,7 +34,7 @@ namespace tensorflow { // differentiable. Figure out backwards compatibility story. class WhileContext { public: - WhileContext(absl::string_view frame_name, std::vector<Node*> enter_nodes, + WhileContext(StringPiece frame_name, std::vector<Node*> enter_nodes, std::vector<Node*> exit_nodes, OutputTensor cond_output, std::vector<OutputTensor> body_inputs, std::vector<OutputTensor> body_outputs); diff --git a/tensorflow/core/grappler/BUILD b/tensorflow/core/grappler/BUILD index bcb3bced950..7c6fe56e1f2 100644 --- a/tensorflow/core/grappler/BUILD +++ b/tensorflow/core/grappler/BUILD @@ -26,7 +26,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -42,7 +41,6 @@ tf_cc_test( "//tensorflow/core:protos_all_cc", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/grappler/optimizers/BUILD b/tensorflow/core/grappler/optimizers/BUILD index c014bcb489e..43a7d6a70b7 100644 --- a/tensorflow/core/grappler/optimizers/BUILD +++ b/tensorflow/core/grappler/optimizers/BUILD @@ -103,7 +103,6 @@ cc_library( "//tensorflow/core/grappler/clusters:cluster", "//tensorflow/core/grappler/costs:graph_properties", "//tensorflow/core/grappler/utils:symbolic_shapes", - "@com_google_absl//absl/strings", ], ) @@ -269,7 +268,6 @@ cc_library( "//tensorflow/core/grappler/costs:graph_properties", "//tensorflow/core/grappler/utils:symbolic_shapes", "//tensorflow/core/grappler/utils:topological_sort", - "@com_google_absl//absl/strings", ], ) @@ -317,7 +315,6 @@ cc_library( "//tensorflow/core/grappler:utils", "//tensorflow/core/grappler/costs:graph_properties", "//tensorflow/core/grappler/utils:topological_sort", - "@com_google_absl//absl/strings", ], ) @@ -772,7 +769,6 @@ cc_library( "//tensorflow/core/grappler:utils", "//tensorflow/core/grappler/costs:graph_properties", "//tensorflow/core/grappler/utils:frame", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc b/tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc index 069de8b93f9..9b94d2706a6 100644 --- a/tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc @@ -22,7 +22,6 @@ limitations under the License. #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/node_def.pb.h" @@ -40,6 +39,7 @@ limitations under the License. #include "tensorflow/core/grappler/utils/symbolic_shapes.h" #include "tensorflow/core/grappler/utils/topological_sort.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -285,7 +285,7 @@ class ArithmeticOptimizerStage : public GraphOptimizerStage<string> { for (const NodeDef* output : ctx().node_map->GetOutputs(node.name())) { for (int i = 0; i < output->input_size(); ++i) { auto input = output->input(i); - absl::string_view name = ParseNodeNameAsStringPiece(input, &position); + StringPiece name = ParseNodeNameAsStringPiece(input, &position); if (name == node.name() && /*control input*/ position < 0) { return true; } @@ -431,12 +431,12 @@ class ArithmeticNodesGroupOptimizerStage : public ArithmeticOptimizerStage { return signature; } - void MarkWithTag(const absl::string_view tag, NodeDef* node) { + void MarkWithTag(const StringPiece tag, NodeDef* node) { AddNodeAttr(tag, true, node); } void MarkAllMembersWithTag(const OptimizedNodesGroup& group, - const absl::string_view tag) const { + const StringPiece tag) const { AddNodeAttr(tag, true, group.root_node); for (NodeDef* optimized_node : group.optimized_nodes) { AddNodeAttr(tag, true, optimized_node); @@ -453,12 +453,12 @@ class ArithmeticNodesGroupOptimizerStage : public ArithmeticOptimizerStage { ctx().nodes_to_preserve->end(); } - bool IsMarkedWithTag(const NodeDef& node, const absl::string_view tag) const { + bool IsMarkedWithTag(const NodeDef& node, const StringPiece tag) const { return HasNodeAttr(node, tag); } - bool IsMarkedWithAnyTag(const NodeDef& node, const absl::string_view tag1, - const absl::string_view tag2) const { + bool IsMarkedWithAnyTag(const NodeDef& node, const StringPiece tag1, + const StringPiece tag2) const { return IsMarkedWithTag(node, tag1) || IsMarkedWithTag(node, tag2); } }; @@ -1577,7 +1577,7 @@ class HoistCWiseUnaryChainsStage : public ArithmeticOptimizerStage { for (NodeDef* output : outputs) { if (IsControlInput(output->input(0))) continue; int port; - const absl::string_view node_name = + const StringPiece node_name = ParseNodeNameAsStringPiece(output->input(0), &port); if (node_name == node.name()) { tails->insert(ChainLink(output, port)); @@ -1628,7 +1628,7 @@ class HoistCWiseUnaryChainsStage : public ArithmeticOptimizerStage { } else { for (NodeDef* new_tail : ctx().node_map->GetOutputs(tail->name())) { int port; - const absl::string_view node_name = + const StringPiece node_name = ParseNodeNameAsStringPiece(new_tail->input(0), &port); if (node_name != tail->name()) { return Status::OK(); @@ -3219,7 +3219,7 @@ uint64 UniqueNodes::ComputeSignature(const NodeDef& node) const { for (const auto& input : node.input()) { int pos; - const absl::string_view node_name = ParseNodeNameAsStringPiece(input, &pos); + const StringPiece node_name = ParseNodeNameAsStringPiece(input, &pos); h = Hash64CombineUnordered(Hash64(node_name.data(), node_name.size()), h); h = Hash64CombineUnordered(std::hash<int>()(pos), h); } diff --git a/tensorflow/core/grappler/optimizers/constant_folding.cc b/tensorflow/core/grappler/optimizers/constant_folding.cc index ff32bec5dea..11331c94061 100644 --- a/tensorflow/core/grappler/optimizers/constant_folding.cc +++ b/tensorflow/core/grappler/optimizers/constant_folding.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #define EIGEN_USE_THREADS #include "tensorflow/core/grappler/optimizers/constant_folding.h" @@ -35,6 +34,7 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/evaluation_utils.h" #include "tensorflow/core/grappler/utils.h" #include "tensorflow/core/grappler/utils/symbolic_shapes.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/cleanup.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/numbers.h" @@ -258,12 +258,12 @@ static Status ConvertShapeToConstant(const string& op, const DataType& type, // TODO(rmlarsen): Perhaps we should move this to the GraphOptimizer base class. bool ConstantFolding::OptimizedNodeExists(const NodeDef& node, - absl::string_view suffix) const { + StringPiece suffix) const { return node_map_->NodeExists(OptimizedNodeName(node, suffix)); } string ConstantFolding::OptimizedNodeName(const NodeDef& node, - absl::string_view suffix) const { + StringPiece suffix) const { return AddPrefixToNodeName(strings::StrCat(node.name(), suffix), kConstantFoldingConst); } diff --git a/tensorflow/core/grappler/optimizers/constant_folding.h b/tensorflow/core/grappler/optimizers/constant_folding.h index 7bf4b900122..8593b3e0b87 100644 --- a/tensorflow/core/grappler/optimizers/constant_folding.h +++ b/tensorflow/core/grappler/optimizers/constant_folding.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_CONSTANT_FOLDING_H_ #define TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_CONSTANT_FOLDING_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/resource_mgr.h" @@ -53,8 +52,8 @@ class ConstantFolding : public GraphOptimizer { const GraphDef& optimize_output, double result) override; private: - string OptimizedNodeName(const NodeDef& node, absl::string_view suffix) const; - bool OptimizedNodeExists(const NodeDef& node, absl::string_view suffix) const; + string OptimizedNodeName(const NodeDef& node, StringPiece suffix) const; + bool OptimizedNodeExists(const NodeDef& node, StringPiece suffix) const; bool IsReallyConstant(const NodeDef& node) const; diff --git a/tensorflow/core/grappler/optimizers/data/BUILD b/tensorflow/core/grappler/optimizers/data/BUILD index a4bd3566e59..1a648da5dae 100644 --- a/tensorflow/core/grappler/optimizers/data/BUILD +++ b/tensorflow/core/grappler/optimizers/data/BUILD @@ -52,7 +52,6 @@ cc_library( deps = [ ":graph_utils", ":function_utils", - "@com_google_absl//absl/strings", "//tensorflow/core/grappler:mutable_graph_view", "//tensorflow/core:framework", "//tensorflow/core:lib", @@ -91,7 +90,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":graph_utils", - "@com_google_absl//absl/strings", "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core/grappler:mutable_graph_view", @@ -126,7 +124,6 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ - "@com_google_absl//absl/strings", "//tensorflow/core:core_cpu", "//tensorflow/core:framework", "//tensorflow/core:lib", @@ -150,7 +147,6 @@ tf_cc_test( "//tensorflow/core/grappler:grappler_item", "//tensorflow/core/grappler/optimizers:custom_graph_optimizer", "//tensorflow/core/grappler/optimizers:custom_graph_optimizer_registry", - "@com_google_absl//absl/strings", ], ) @@ -163,7 +159,6 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ - "@com_google_absl//absl/strings", "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core/grappler:mutable_graph_view", @@ -220,7 +215,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":graph_utils", - "@com_google_absl//absl/strings", "//tensorflow/core/grappler:mutable_graph_view", "//tensorflow/core:lib", "//tensorflow/core/grappler:grappler_item", @@ -267,7 +261,6 @@ tf_cc_test( "//tensorflow/core:test_main", "//tensorflow/core:testlib", "//tensorflow/core/grappler:grappler_item", - "@com_google_absl//absl/strings", ], ) @@ -302,7 +295,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core/grappler:grappler_item", - "@com_google_absl//absl/strings", ], ) @@ -487,7 +479,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core/grappler:grappler_item", - "@com_google_absl//absl/strings", ], ) @@ -589,7 +580,6 @@ tf_cc_test( ":graph_utils", ":function_utils", ":vectorization_utils", - "@com_google_absl//absl/strings", "//tensorflow/core:framework", "//tensorflow/core:test", "//tensorflow/core:test_main", diff --git a/tensorflow/core/grappler/optimizers/data/function_utils.cc b/tensorflow/core/grappler/optimizers/data/function_utils.cc index ad2b8167cb1..311df15bc27 100644 --- a/tensorflow/core/grappler/optimizers/data/function_utils.cc +++ b/tensorflow/core/grappler/optimizers/data/function_utils.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/grappler/optimizers/data/function_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" #include "tensorflow/core/framework/device_base.h" @@ -35,8 +34,8 @@ FunctionDefTensorDesc::FunctionDefTensorDesc(const string& node_name, FunctionDefTensorDesc::FunctionDefTensorDesc(const string& input) { // Parses node_name:node_output:position string into its components. full_str = input; - absl::string_view capture; - absl::string_view remaining; + StringPiece capture; + StringPiece remaining; // Parse "node_name" if (strings::Scanner(input) @@ -87,8 +86,8 @@ void ReplaceReferences(const string& from, const string& to, } } -void AddFunctionOutputWithUniqueName(absl::string_view prefix, - absl::string_view output_tensor_name, +void AddFunctionOutputWithUniqueName(StringPiece prefix, + StringPiece output_tensor_name, FunctionDef* function, DataType dt) { string name = string(prefix); int id = function->signature().output_arg_size(); @@ -103,7 +102,7 @@ void AddFunctionOutputWithUniqueName(absl::string_view prefix, (*function->mutable_ret())[name] = string(output_tensor_name); } -NodeDef* AddNode(absl::string_view name, absl::string_view op, +NodeDef* AddNode(StringPiece name, StringPiece op, const std::vector<string>& inputs, const std::vector<std::pair<string, AttrValue>>& attributes, FunctionDef* fd) { @@ -123,49 +122,45 @@ NodeDef* AddNode(absl::string_view name, absl::string_view op, return node; } -bool ContainsFunctionNodeWithName(absl::string_view name, +bool ContainsFunctionNodeWithName(StringPiece name, const FunctionDef& function) { return FindFunctionNodeWithName(name, function) != -1; } -bool ContainsFunctionNodeWithOp(absl::string_view op, - const FunctionDef& function) { +bool ContainsFunctionNodeWithOp(StringPiece op, const FunctionDef& function) { return FindFunctionNodeWithOp(op, function) != -1; } -bool ContainsFunctionOutputWithName(absl::string_view name, +bool ContainsFunctionOutputWithName(StringPiece name, const FunctionDef& function) { return FindFunctionOutputWithName(name, function) != -1; } -int FindFunctionInputWithName(absl::string_view name, - const FunctionDef& function) { +int FindFunctionInputWithName(StringPiece name, const FunctionDef& function) { return graph_utils::GetFirstElementIndexWithPredicate( [&name](const OpDef_ArgDef& arg) { return arg.name() == name; }, function.signature().input_arg()); } -int FindFunctionOutputWithName(absl::string_view name, - const FunctionDef& function) { +int FindFunctionOutputWithName(StringPiece name, const FunctionDef& function) { return graph_utils::GetFirstElementIndexWithPredicate( [&name](const OpDef_ArgDef& arg) { return arg.name() == name; }, function.signature().output_arg()); } -int FindFunctionNodeWithName(absl::string_view name, - const FunctionDef& function) { +int FindFunctionNodeWithName(StringPiece name, const FunctionDef& function) { return graph_utils::GetFirstElementIndexWithPredicate( [&name](const NodeDef& node) { return node.name() == name; }, function.node_def()); } -int FindFunctionNodeWithOp(absl::string_view op, const FunctionDef& function) { +int FindFunctionNodeWithOp(StringPiece op, const FunctionDef& function) { return graph_utils::GetFirstElementIndexWithPredicate( [&op](const NodeDef& node) { return node.op() == op; }, function.node_def()); } -void SetUniqueFunctionNodeName(absl::string_view prefix, FunctionDef* function, +void SetUniqueFunctionNodeName(StringPiece prefix, FunctionDef* function, NodeDef* node) { string name = string(prefix); int id = function->node_def_size(); diff --git a/tensorflow/core/grappler/optimizers/data/function_utils.h b/tensorflow/core/grappler/optimizers/data/function_utils.h index 714f7d30d6b..d4ce824652b 100644 --- a/tensorflow/core/grappler/optimizers/data/function_utils.h +++ b/tensorflow/core/grappler/optimizers/data/function_utils.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_FUNCTION_UTILS_H_ #define TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_FUNCTION_UTILS_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/function.pb.h" #include "tensorflow/core/framework/graph.pb.h" @@ -60,50 +59,46 @@ void ReplaceReferences(const string& from, const string& to, FunctionDef* func); // Adds a function output to the function def, ensuring that the output key // is unique, and maps to output_tensor_name in the ret dict. -void AddFunctionOutputWithUniqueName(absl::string_view prefix, - absl::string_view output_tensor_name, +void AddFunctionOutputWithUniqueName(StringPiece prefix, + StringPiece output_tensor_name, FunctionDef* function, DataType dt); // Adds a node to a FunctionDef. -NodeDef* AddNode(absl::string_view name, absl::string_view op, +NodeDef* AddNode(StringPiece name, StringPiece op, const std::vector<string>& inputs, const std::vector<std::pair<string, AttrValue>>& attributes, FunctionDef* fd); // Checks whether the function contains a node with the given name. -bool ContainsFunctionNodeWithName(absl::string_view name, +bool ContainsFunctionNodeWithName(StringPiece name, const FunctionDef& function); // Checks whether the function contains a node with the given op. -bool ContainsFunctionNodeWithOp(absl::string_view op, - const FunctionDef& function); +bool ContainsFunctionNodeWithOp(StringPiece op, const FunctionDef& function); // Checks whether the function contains an output with the given name. -bool ContainsFunctionOutputWithName(absl::string_view name, +bool ContainsFunctionOutputWithName(StringPiece name, const FunctionDef& function); // Returns the index of the function input with the given name or -1 if the // function node does not exist. -int FindFunctionInputWithName(absl::string_view name, - const FunctionDef& function); +int FindFunctionInputWithName(StringPiece name, const FunctionDef& function); // Returns the index of the function output with the given name or -1 if the // function node does not exist. -int FindFunctionOutputWithName(absl::string_view name, - const FunctionDef& function); +int FindFunctionOutputWithName(StringPiece name, const FunctionDef& function); // Returns the index of the function node with the given name or -1 if the // function node does not exist. -int FindFunctionNodeWithName(absl::string_view name, - const FunctionDef& function); +int FindFunctionNodeWithName(StringPiece name, const FunctionDef& function); // Returns the index of the function node with the given op or -1 if the // function node does not exist. -int FindFunctionNodeWithOp(absl::string_view op, const FunctionDef& function); +int FindFunctionNodeWithOp(StringPiece op, const FunctionDef& function); // Sets the function node name using the `prefix` as a prefix while guaranteeing // the name is unique across the functions nodes. -void SetUniqueFunctionNodeName(absl::string_view prefix, FunctionDef* function, +void SetUniqueFunctionNodeName(StringPiece prefix, FunctionDef* function, NodeDef* node); } // end namespace function_utils diff --git a/tensorflow/core/grappler/optimizers/data/fusion_utils.cc b/tensorflow/core/grappler/optimizers/data/fusion_utils.cc index db6e4d8b512..b3bfee138ff 100644 --- a/tensorflow/core/grappler/optimizers/data/fusion_utils.cc +++ b/tensorflow/core/grappler/optimizers/data/fusion_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/fusion_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_builder.h" #include "tensorflow/core/framework/op_def.pb.h" @@ -424,14 +423,11 @@ void LazyConjunctionOutput(const protobuf::Map<string, string>& first_ret, *fused_ret = first_ret; } -FunctionDef* FuseFunctions(const FunctionDef& first_function, - const FunctionDef& second_function, - absl::string_view fused_name_prefix, - const SetFunctionSignatureFn& set_signature, - const SetInputFn& set_input, - const SetOutputFn& set_output, - const SetNodesFn& set_nodes, - FunctionDefLibrary* library) { +FunctionDef* FuseFunctions( + const FunctionDef& first_function, const FunctionDef& second_function, + StringPiece fused_name_prefix, const SetFunctionSignatureFn& set_signature, + const SetInputFn& set_input, const SetOutputFn& set_output, + const SetNodesFn& set_nodes, FunctionDefLibrary* library) { if (first_function.attr_size() != 0 || second_function.attr_size() != 0) return nullptr; // Functions with attributes are currently not supported diff --git a/tensorflow/core/grappler/optimizers/data/fusion_utils.h b/tensorflow/core/grappler/optimizers/data/fusion_utils.h index 0350a2c08ef..19b7002dcd8 100644 --- a/tensorflow/core/grappler/optimizers/data/fusion_utils.h +++ b/tensorflow/core/grappler/optimizers/data/fusion_utils.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_FUSION_UTILS_H_ #include <functional> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/grappler/op_types.h" @@ -123,14 +122,11 @@ void LazyConjunctionNodes(const FunctionDef& first_function, // that are not conflicting with first function. This means that copied nodes // from second function can end up having different names. For explanation of // set up functions see the documentation of the functions types. -FunctionDef* FuseFunctions(const FunctionDef& first_function, - const FunctionDef& second_function, - absl::string_view fused_name_prefix, - const SetFunctionSignatureFn& set_signature, - const SetInputFn& set_input, - const SetOutputFn& set_output, - const SetNodesFn& set_nodes, - FunctionDefLibrary* library); +FunctionDef* FuseFunctions( + const FunctionDef& first_function, const FunctionDef& second_function, + StringPiece fused_name_prefix, const SetFunctionSignatureFn& set_signature, + const SetInputFn& set_input, const SetOutputFn& set_output, + const SetNodesFn& set_nodes, FunctionDefLibrary* library); } // namespace fusion_utils } // namespace grappler diff --git a/tensorflow/core/grappler/optimizers/data/graph_test_utils.cc b/tensorflow/core/grappler/optimizers/data/graph_test_utils.cc index 034a4070d0c..1f03c6515c8 100644 --- a/tensorflow/core/grappler/optimizers/data/graph_test_utils.cc +++ b/tensorflow/core/grappler/optimizers/data/graph_test_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/graph_test_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function_testlib.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_testutil.h" @@ -26,8 +25,8 @@ namespace tensorflow { namespace grappler { namespace graph_tests_utils { -NodeDef MakeMapNode(absl::string_view name, absl::string_view input_node_name, - absl::string_view function_name) { +NodeDef MakeMapNode(StringPiece name, StringPiece input_node_name, + StringPiece function_name) { return test::function::NDef( name, "MapDataset", {string(input_node_name)}, {{"f", FunctionDefHelper::FunctionRef(string(function_name))}, @@ -36,9 +35,8 @@ NodeDef MakeMapNode(absl::string_view name, absl::string_view input_node_name, {"output_types", gtl::ArraySlice<DataType>{}}}); } -NodeDef MakeFilterNode(absl::string_view name, - absl::string_view input_node_name, - absl::string_view function_name) { +NodeDef MakeFilterNode(StringPiece name, StringPiece input_node_name, + StringPiece function_name) { return test::function::NDef( name, "FilterDataset", {string(input_node_name)}, {{"predicate", FunctionDefHelper::FunctionRef(string(function_name))}, @@ -47,12 +45,11 @@ NodeDef MakeFilterNode(absl::string_view name, {"output_types", gtl::ArraySlice<TensorShape>{}}}); } -NodeDef MakeMapAndBatchNode(absl::string_view name, - absl::string_view input_node_name, - absl::string_view batch_size_node_name, - absl::string_view num_parallel_calls_node_name, - absl::string_view drop_remainder_node_name, - absl::string_view function_name) { +NodeDef MakeMapAndBatchNode(StringPiece name, StringPiece input_node_name, + StringPiece batch_size_node_name, + StringPiece num_parallel_calls_node_name, + StringPiece drop_remainder_node_name, + StringPiece function_name) { return test::function::NDef( name, "MapAndBatchDatasetV2", {string(input_node_name), "", string(batch_size_node_name), diff --git a/tensorflow/core/grappler/optimizers/data/graph_test_utils.h b/tensorflow/core/grappler/optimizers/data/graph_test_utils.h index 8014a4f3053..f7891d5e1f2 100644 --- a/tensorflow/core/grappler/optimizers/data/graph_test_utils.h +++ b/tensorflow/core/grappler/optimizers/data/graph_test_utils.h @@ -16,26 +16,24 @@ limitations under the License. #ifndef TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_GRAPH_TEST_UTILS_H_ #define TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_GRAPH_TEST_UTILS_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { namespace grappler { namespace graph_tests_utils { -NodeDef MakeMapNode(absl::string_view name, absl::string_view input_node_name, - absl::string_view function_name = "XTimesTwo"); +NodeDef MakeMapNode(StringPiece name, StringPiece input_node_name, + StringPiece function_name = "XTimesTwo"); -NodeDef MakeFilterNode(absl::string_view name, - absl::string_view input_node_name, - absl::string_view function_name = "IsZero"); +NodeDef MakeFilterNode(StringPiece name, StringPiece input_node_name, + StringPiece function_name = "IsZero"); -NodeDef MakeMapAndBatchNode(absl::string_view name, - absl::string_view input_node_name, - absl::string_view batch_size_node_name, - absl::string_view num_parallel_calls_node_name, - absl::string_view drop_remainder_node_name, - absl::string_view function_name = "XTimesTwo"); +NodeDef MakeMapAndBatchNode(StringPiece name, StringPiece input_node_name, + StringPiece batch_size_node_name, + StringPiece num_parallel_calls_node_name, + StringPiece drop_remainder_node_name, + StringPiece function_name = "XTimesTwo"); } // end namespace graph_tests_utils } // end namespace grappler diff --git a/tensorflow/core/grappler/optimizers/data/graph_utils.cc b/tensorflow/core/grappler/optimizers/data/graph_utils.cc index 1cc6fca0372..b863a25dc5f 100644 --- a/tensorflow/core/grappler/optimizers/data/graph_utils.cc +++ b/tensorflow/core/grappler/optimizers/data/graph_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/lib/gtl/map_util.h" @@ -100,7 +99,7 @@ NodeDef* AddScalarPlaceholder(DataType dtype, MutableGraphView* graph) { return graph->AddNode(std::move(node)); } -NodeDef* AddNode(absl::string_view name, absl::string_view op, +NodeDef* AddNode(StringPiece name, StringPiece op, const std::vector<string>& inputs, const std::vector<std::pair<string, AttrValue>>& attributes, MutableGraphView* graph) { @@ -151,7 +150,7 @@ NodeDef* AddScalarConstNode(int64 v, MutableGraphView* graph) { } template <> -NodeDef* AddScalarConstNode(absl::string_view v, MutableGraphView* graph) { +NodeDef* AddScalarConstNode(StringPiece v, MutableGraphView* graph) { return AddScalarConstNodeHelper( DT_STRING, [v](TensorProto* proto) { proto->add_string_val(v.data(), v.size()); }, @@ -188,20 +187,20 @@ bool Compare(const GraphDef& g1, const GraphDef& g2) { return true; } -bool ContainsGraphFunctionWithName(absl::string_view name, +bool ContainsGraphFunctionWithName(StringPiece name, const FunctionDefLibrary& library) { return FindGraphFunctionWithName(name, library) != -1; } -bool ContainsGraphNodeWithName(absl::string_view name, const GraphDef& graph) { +bool ContainsGraphNodeWithName(StringPiece name, const GraphDef& graph) { return FindGraphNodeWithName(name, graph) != -1; } -bool ContainsNodeWithOp(absl::string_view op, const GraphDef& graph) { +bool ContainsNodeWithOp(StringPiece op, const GraphDef& graph) { return FindGraphNodeWithOp(op, graph) != -1; } -int FindGraphFunctionWithName(absl::string_view name, +int FindGraphFunctionWithName(StringPiece name, const FunctionDefLibrary& library) { return GetFirstElementIndexWithPredicate( [&name](const FunctionDef& function) { @@ -210,13 +209,13 @@ int FindGraphFunctionWithName(absl::string_view name, library.function()); } -int FindGraphNodeWithName(absl::string_view name, const GraphDef& graph) { +int FindGraphNodeWithName(StringPiece name, const GraphDef& graph) { return GetFirstElementIndexWithPredicate( [&name](const NodeDef& node) { return node.name() == name; }, graph.node()); } -int FindGraphNodeWithOp(absl::string_view op, const GraphDef& graph) { +int FindGraphNodeWithOp(StringPiece op, const GraphDef& graph) { return GetFirstElementIndexWithPredicate( [&op](const NodeDef& node) { return node.op() == op; }, graph.node()); } @@ -233,7 +232,7 @@ NodeDef* GetInputNode(const NodeDef& node, const MutableGraphView& graph) { return graph.GetRegularFanin(input_port).node; } -void SetUniqueGraphNodeName(absl::string_view prefix, GraphDef* graph, +void SetUniqueGraphNodeName(StringPiece prefix, GraphDef* graph, NodeDef* node) { string name = string(prefix); int id = graph->node_size(); @@ -249,8 +248,7 @@ void SetUniqueGraphNodeName(absl::string_view prefix, GraphDef* graph, node->set_name(std::move(name)); } -void SetUniqueGraphFunctionName(absl::string_view prefix, - FunctionDefLibrary* library, +void SetUniqueGraphFunctionName(StringPiece prefix, FunctionDefLibrary* library, FunctionDef* function) { string name = string(prefix); int id = library->function_size(); diff --git a/tensorflow/core/grappler/optimizers/data/graph_utils.h b/tensorflow/core/grappler/optimizers/data/graph_utils.h index 4397f77cbaf..d130fee2047 100644 --- a/tensorflow/core/grappler/optimizers/data/graph_utils.h +++ b/tensorflow/core/grappler/optimizers/data/graph_utils.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_GRAPH_UTILS_H_ #define TENSORFLOW_CORE_GRAPPLER_OPTIMIZERS_DATA_GRAPH_UTILS_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/function.pb.h" #include "tensorflow/core/framework/graph.pb.h" @@ -49,7 +48,7 @@ int GetFirstElementIndexWithPredicate(const Predicate& predicate, } // Adds a node to the graph. -NodeDef* AddNode(absl::string_view name, absl::string_view op, +NodeDef* AddNode(StringPiece name, StringPiece op, const std::vector<string>& inputs, const std::vector<std::pair<string, AttrValue>>& attributes, MutableGraphView* graph); @@ -78,33 +77,33 @@ NodeDef* AddScalarConstNode(int v, MutableGraphView* graph); template <> NodeDef* AddScalarConstNode(int64 v, MutableGraphView* graph); template <> -NodeDef* AddScalarConstNode(absl::string_view v, MutableGraphView* graph); +NodeDef* AddScalarConstNode(StringPiece v, MutableGraphView* graph); // Checks whether the two graphs are the same. bool Compare(const GraphDef& g1, const GraphDef& g2); // Checks whether the graph contains a node with the given name. -bool ContainsGraphNodeWithName(absl::string_view name, const GraphDef& graph); +bool ContainsGraphNodeWithName(StringPiece name, const GraphDef& graph); // Checks whether the library contains a function with the given name. -bool ContainsGraphFunctionWithName(absl::string_view name, +bool ContainsGraphFunctionWithName(StringPiece name, const FunctionDefLibrary& library); // Checks whether the graph contains a node with the given op. -bool ContainsNodeWithOp(absl::string_view op, const GraphDef& graph); +bool ContainsNodeWithOp(StringPiece op, const GraphDef& graph); // Returns the index of the node with the given name or -1 if the node does // not exist. -int FindGraphNodeWithName(absl::string_view name, const GraphDef& graph); +int FindGraphNodeWithName(StringPiece name, const GraphDef& graph); // Returns the index of the function with the given name or -1 if the function // does not exist. -int FindGraphFunctionWithName(absl::string_view name, +int FindGraphFunctionWithName(StringPiece name, const FunctionDefLibrary& library); // Returns the index of the first node with the given op or -1 if no such node // exists. -int FindGraphNodeWithOp(absl::string_view op, const GraphDef& graph); +int FindGraphNodeWithOp(StringPiece op, const GraphDef& graph); // Gets the 0th input to a node in the graph. NodeDef* GetInputNode(const NodeDef& node, const MutableGraphView& graph); @@ -116,13 +115,11 @@ std::vector<int> FindAllGraphNodesWithOp(const string& op, // Sets the node name using `prefix` as a prefix while guaranteeing the name // is unique across the graph. -void SetUniqueGraphNodeName(absl::string_view prefix, GraphDef* graph, - NodeDef* node); +void SetUniqueGraphNodeName(StringPiece prefix, GraphDef* graph, NodeDef* node); // Sets the function name using the `prefix` name as a prefix while guaranteeing // the name is unique across the function library. -void SetUniqueGraphFunctionName(absl::string_view prefix, - FunctionDefLibrary* library, +void SetUniqueGraphFunctionName(StringPiece prefix, FunctionDefLibrary* library, FunctionDef* function); // Copies attribute having name `attribute_name` from node `from` to node diff --git a/tensorflow/core/grappler/optimizers/data/graph_utils_test.cc b/tensorflow/core/grappler/optimizers/data/graph_utils_test.cc index c77fff1656f..4ab6d71532c 100644 --- a/tensorflow/core/grappler/optimizers/data/graph_utils_test.cc +++ b/tensorflow/core/grappler/optimizers/data/graph_utils_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function_testlib.h" #include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/lib/core/status_test_util.h" @@ -82,7 +81,7 @@ TEST(GraphUtilsTest, AddScalarConstNodeInt64) { TEST(GraphUtilsTest, AddScalarConstNodeString) { GraphDef graph_def; MutableGraphView graph(&graph_def); - NodeDef* string_node = AddScalarConstNode<absl::string_view>("hello", &graph); + NodeDef* string_node = AddScalarConstNode<StringPiece>("hello", &graph); EXPECT_TRUE( ContainsGraphNodeWithName(string_node->name(), *graph.GetGraph())); EXPECT_EQ(string_node->attr().at("value").tensor().string_val(0), "hello"); diff --git a/tensorflow/core/grappler/optimizers/data/latency_all_edges.cc b/tensorflow/core/grappler/optimizers/data/latency_all_edges.cc index 7954d124a2f..9e382aeef9c 100644 --- a/tensorflow/core/grappler/optimizers/data/latency_all_edges.cc +++ b/tensorflow/core/grappler/optimizers/data/latency_all_edges.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/latency_all_edges.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/grappler/clusters/cluster.h" @@ -43,8 +42,8 @@ NodeDef MakeLatencyNode(const NodeDef& node, MutableGraphView* graph) { // Set the input of LatencyDataset node as `node` new_node.add_input(node.name()); - NodeDef* tag = graph_utils::AddScalarConstNode<absl::string_view>( - absl::string_view("record_latency_" + node.name()), graph); + NodeDef* tag = graph_utils::AddScalarConstNode<StringPiece>( + StringPiece("record_latency_" + node.name()), graph); new_node.add_input(tag->name()); // Set `output_types` and `output_shapes` attributes. diff --git a/tensorflow/core/grappler/optimizers/data/map_and_batch_fusion_test.cc b/tensorflow/core/grappler/optimizers/data/map_and_batch_fusion_test.cc index 0db08d0181b..b676246b318 100644 --- a/tensorflow/core/grappler/optimizers/data/map_and_batch_fusion_test.cc +++ b/tensorflow/core/grappler/optimizers/data/map_and_batch_fusion_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/map_and_batch_fusion.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/grappler/grappler_item.h" #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" @@ -42,7 +41,7 @@ TEST(MapAndBatchFusionTest, FuseMapAndBatchNodesIntoOne) { NodeDef *range_node = graph_utils::AddNode("", "RangeDataset", range_inputs, range_attrs, &graph); NodeDef *captured_input_node = - graph_utils::AddScalarConstNode<absl::string_view>("hello", &graph); + graph_utils::AddScalarConstNode<StringPiece>("hello", &graph); NodeDef *map_node; { @@ -124,7 +123,7 @@ TEST(MapAndBatchFusionTest, FuseMapAndBatchV2NodesIntoOne) { NodeDef *range_node = graph_utils::AddNode("", "RangeDataset", range_inputs, range_attrs, &graph); NodeDef *captured_input_node = - graph_utils::AddScalarConstNode<absl::string_view>("hello", &graph); + graph_utils::AddScalarConstNode<StringPiece>("hello", &graph); NodeDef *map_node; { @@ -207,7 +206,7 @@ TEST(MapAndBatchFusionTest, FuseParallelMapAndBatchNodesIntoOne) { NodeDef *range_node = graph_utils::AddNode("", "RangeDataset", range_inputs, range_attrs, &graph); NodeDef *captured_input_node = - graph_utils::AddScalarConstNode<absl::string_view>("hello", &graph); + graph_utils::AddScalarConstNode<StringPiece>("hello", &graph); NodeDef *num_parallel_calls_node = graph_utils::AddScalarConstNode<int>(2, &graph); diff --git a/tensorflow/core/grappler/optimizers/data/map_vectorization_test.cc b/tensorflow/core/grappler/optimizers/data/map_vectorization_test.cc index c242a743593..f4faf415496 100644 --- a/tensorflow/core/grappler/optimizers/data/map_vectorization_test.cc +++ b/tensorflow/core/grappler/optimizers/data/map_vectorization_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/map_vectorization.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/function_testlib.h" #include "tensorflow/core/framework/tensor_testutil.h" @@ -31,10 +30,8 @@ namespace { using test::function::GDef; using test::function::NDef; -NodeDef MakeMapNodeHelper(absl::string_view name, - absl::string_view input_node_name, - absl::string_view function_name, - absl::string_view map_op_name, +NodeDef MakeMapNodeHelper(StringPiece name, StringPiece input_node_name, + StringPiece function_name, StringPiece map_op_name, gtl::ArraySlice<PartialTensorShape> output_shapes, gtl::ArraySlice<DataType> output_types) { return test::function::NDef( @@ -45,16 +42,16 @@ NodeDef MakeMapNodeHelper(absl::string_view name, {"output_types", output_types}}); } -NodeDef MakeMapNode(absl::string_view name, absl::string_view input_node_name, - absl::string_view function_name, +NodeDef MakeMapNode(StringPiece name, StringPiece input_node_name, + StringPiece function_name, gtl::ArraySlice<PartialTensorShape> output_shapes, gtl::ArraySlice<DataType> output_types) { return MakeMapNodeHelper(name, input_node_name, function_name, "MapDataset", output_shapes, output_types); } -NodeDef MakeBatchNode(absl::string_view name, absl::string_view input_node_name, - absl::string_view input_batch_size_name, +NodeDef MakeBatchNode(StringPiece name, StringPiece input_node_name, + StringPiece input_batch_size_name, gtl::ArraySlice<PartialTensorShape> output_shapes, gtl::ArraySlice<DataType> output_types) { return NDef( @@ -63,10 +60,9 @@ NodeDef MakeBatchNode(absl::string_view name, absl::string_view input_node_name, {{"output_types", output_types}, {"output_shapes", output_shapes}}); } -NodeDef MakeBatchV2Node(absl::string_view name, - absl::string_view input_node_name, - absl::string_view input_batch_size_name, - absl::string_view input_drop_remainder_name, +NodeDef MakeBatchV2Node(StringPiece name, StringPiece input_node_name, + StringPiece input_batch_size_name, + StringPiece input_drop_remainder_name, gtl::ArraySlice<PartialTensorShape> output_shapes, gtl::ArraySlice<DataType> output_types) { return NDef( @@ -76,7 +72,7 @@ NodeDef MakeBatchV2Node(absl::string_view name, {{"output_types", output_types}, {"output_shapes", output_shapes}}); } -NodeDef MakeRangeNode(absl::string_view name, gtl::ArraySlice<string> inputs) { +NodeDef MakeRangeNode(StringPiece name, gtl::ArraySlice<string> inputs) { return NDef(name, "RangeDataset", inputs, {{"output_shapes", gtl::ArraySlice<TensorShape>({{}})}, {"output_types", gtl::ArraySlice<DataType>({DT_INT64})}}); diff --git a/tensorflow/core/grappler/optimizers/data/noop_elimination_test.cc b/tensorflow/core/grappler/optimizers/data/noop_elimination_test.cc index 2f3da39845e..be1a66df75d 100644 --- a/tensorflow/core/grappler/optimizers/data/noop_elimination_test.cc +++ b/tensorflow/core/grappler/optimizers/data/noop_elimination_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/noop_elimination.h" #include <tuple> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/grappler/grappler_item.h" #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" @@ -36,15 +35,15 @@ std::vector<std::pair<string, AttrValue>> GetCommonAttributes() { return commonAttributes; } -NodeDef *MakeUnaryNode(absl::string_view node_type, int count, - string input_node, MutableGraphView *graph) { +NodeDef *MakeUnaryNode(StringPiece node_type, int count, string input_node, + MutableGraphView *graph) { NodeDef *node_count = graph_utils::AddScalarConstNode<int64>(count, graph); return graph_utils::AddNode("", node_type, {std::move(input_node), node_count->name()}, GetCommonAttributes(), graph); } -NodeDef *MakeUnaryNonConstNode(absl::string_view node_type, string input_node, +NodeDef *MakeUnaryNonConstNode(StringPiece node_type, string input_node, MutableGraphView *graph) { NodeDef *node_count = graph_utils::AddScalarPlaceholder(DT_INT32, graph); return graph_utils::AddNode("", node_type, @@ -54,7 +53,7 @@ NodeDef *MakeUnaryNonConstNode(absl::string_view node_type, string input_node, NodeDef *MakeCacheNode(string input_node, MutableGraphView *graph) { NodeDef *node_filename = - graph_utils::AddScalarConstNode<absl::string_view>("", graph); + graph_utils::AddScalarConstNode<StringPiece>("", graph); return graph_utils::AddNode("", "CacheDataset", {std::move(input_node), node_filename->name()}, GetCommonAttributes(), graph); diff --git a/tensorflow/core/grappler/optimizers/data/vectorization_utils.cc b/tensorflow/core/grappler/optimizers/data/vectorization_utils.cc index 799500350a9..8b93b1f2b83 100644 --- a/tensorflow/core/grappler/optimizers/data/vectorization_utils.cc +++ b/tensorflow/core/grappler/optimizers/data/vectorization_utils.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/grappler/optimizers/data/vectorization_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/grappler/optimizers/data/vectorization/vectorizer_registry.h" #include "absl/strings/str_join.h" @@ -415,7 +414,7 @@ Status Vectorization::StackTensor(WrappedTensor* unstacked, } Graph* g = outer_scope_.get(); - auto node_builder = [](absl::string_view op) { + auto node_builder = [](StringPiece op) { return NodeBuilder(strings::StrCat("vectorized/stack/", op), op); }; diff --git a/tensorflow/core/grappler/optimizers/data/vectorization_utils_test.cc b/tensorflow/core/grappler/optimizers/data/vectorization_utils_test.cc index 4d802e7a57f..e82bfb702a3 100644 --- a/tensorflow/core/grappler/optimizers/data/vectorization_utils_test.cc +++ b/tensorflow/core/grappler/optimizers/data/vectorization_utils_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/grappler/optimizers/data/vectorization_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/grappler/optimizers/data/function_utils.h" #include "tensorflow/core/grappler/optimizers/data/graph_utils.h" @@ -70,8 +69,7 @@ string GetRetval(const FunctionDef& function_def, int index) { // TODO(rachelim): Use FunctionDefHelper::Create instead FunctionDef CreateFunction( - absl::string_view name, - const std::vector<std::pair<string, DataType>>& inputs, + StringPiece name, const std::vector<std::pair<string, DataType>>& inputs, const std::vector<std::pair<string, DataType>>& outputs, const std::map<string, string>& rets) { FunctionDef func; @@ -93,6 +91,7 @@ FunctionDef CreateFunction( return func; } + ///==================================// // Tests for vectorization framework // ///==================================// diff --git a/tensorflow/core/grappler/optimizers/dependency_optimizer.cc b/tensorflow/core/grappler/optimizers/dependency_optimizer.cc index 75e32e0b7f0..6613768a354 100644 --- a/tensorflow/core/grappler/optimizers/dependency_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/dependency_optimizer.cc @@ -18,7 +18,6 @@ limitations under the License. #include <unordered_map> #include <unordered_set> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/grappler/costs/graph_properties.h" @@ -28,6 +27,7 @@ limitations under the License. #include "tensorflow/core/grappler/utils.h" #include "tensorflow/core/grappler/utils/topological_sort.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -204,7 +204,7 @@ void DependencyOptimizer::OptimizeNode(int node_idx, bool data_connection = false; for (int i = fanout->input_size() - 1; i >= 0; --i) { int pos; - absl::string_view input_name = + StringPiece input_name = ParseNodeNameAsStringPiece(fanout->input(i), &pos); if (input_name == node_name) { if (pos < 0) { @@ -352,7 +352,7 @@ void DependencyOptimizer::OptimizeNode(int node_idx, for (int j = 0; j < consumer->input_size(); ++j) { const string& old_input = consumer->input(j); int old_input_pos; - absl::string_view old_input_node_name = + StringPiece old_input_node_name = ParseNodeNameAsStringPiece(old_input, &old_input_pos); if (old_input_node_name == node_name) { if (old_input_pos >= 0) { diff --git a/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.cc b/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.cc index f41a2d7c15b..0d4aaf64621 100644 --- a/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/scoped_allocator.h" #include "tensorflow/core/common_runtime/scoped_allocator_mgr.h" #include "tensorflow/core/framework/graph.pb.h" @@ -199,7 +198,7 @@ Status RemoveEdge(const string& input_edge_name, const string& from_node_name, } } // namespace -void ScopedAllocatorOptimizer::ExtendNodeAttr(absl::string_view name, +void ScopedAllocatorOptimizer::ExtendNodeAttr(StringPiece name, const std::vector<int32>& values, NodeDef* node_def) { if (HasNodeAttr(*node_def, name)) { diff --git a/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.h b/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.h index e7a1ec154b7..13589f536ca 100644 --- a/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.h +++ b/tensorflow/core/grappler/optimizers/scoped_allocator_optimizer.h @@ -18,7 +18,6 @@ limitations under the License. #include <unordered_map> #include <unordered_set> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/grappler/optimizers/graph_optimizer.h" #include "tensorflow/core/protobuf/rewriter_config.pb.h" @@ -67,8 +66,7 @@ class ScopedAllocatorOptimizer : public GraphOptimizer { // Appends values to the attr value under name in node_def, if present. // If not present does an assignment. - static void ExtendNodeAttr(absl::string_view name, - const std::vector<int32>& values, + static void ExtendNodeAttr(StringPiece name, const std::vector<int32>& values, NodeDef* node_def); // Class that knows how to do graph rewriting for a particular kind of Op in diff --git a/tensorflow/core/grappler/utils.cc b/tensorflow/core/grappler/utils.cc index a890b56b4d2..5867d013242 100644 --- a/tensorflow/core/grappler/utils.cc +++ b/tensorflow/core/grappler/utils.cc @@ -20,12 +20,12 @@ limitations under the License. #include <queue> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/types.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -146,9 +146,9 @@ bool IsSameInput(const string& name1, const string& name2) { return true; } int position1; - absl::string_view node1 = ParseNodeNameAsStringPiece(name1, &position1); + StringPiece node1 = ParseNodeNameAsStringPiece(name1, &position1); int position2; - absl::string_view node2 = ParseNodeNameAsStringPiece(name2, &position2); + StringPiece node2 = ParseNodeNameAsStringPiece(name2, &position2); return (position1 == position2) && (node1 == node2); } @@ -251,7 +251,7 @@ int NumNonControlOutputs(const NodeDef& node, const NodeMap& node_map) { if (node_as_input == node.name()) { ++num_outputs; } else { - const absl::string_view name = + const StringPiece name = ParseNodeNameAsStringPiece(node_as_input, &pos); if (name == node.name()) { ++num_outputs; diff --git a/tensorflow/core/grappler/utils.h b/tensorflow/core/grappler/utils.h index c7a8a517bb8..0168ab1da3c 100644 --- a/tensorflow/core/grappler/utils.h +++ b/tensorflow/core/grappler/utils.h @@ -19,12 +19,12 @@ limitations under the License. #include <functional> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/threadpool.h" #include "tensorflow/core/lib/gtl/flatmap.h" #include "tensorflow/core/lib/gtl/flatset.h" @@ -125,8 +125,8 @@ inline int NodePositionIfSameNode(const string& input_name, if (input_it == input_name.end()) { return is_ctrl ? -1 : 0; } else if (*input_it++ == ':') { - absl::string_view remaining(&(*input_it), - std::distance(input_it, input_name.end())); + StringPiece remaining(&(*input_it), + std::distance(input_it, input_name.end())); int position; if (!strings::safe_strto32(remaining, &position)) { return -2; @@ -139,18 +139,18 @@ inline int NodePositionIfSameNode(const string& input_name, // Return the node name corresponding to 'name' if name is valid, or the empty // string otherwise. -inline absl::string_view NodeNameAsStringPiece(const string& name) { +inline StringPiece NodeNameAsStringPiece(const string& name) { static const string empty; - if (name.empty()) return absl::string_view(empty); + if (name.empty()) return StringPiece(empty); const auto begin_it = name[0] == '^' ? name.begin() + 1 : name.begin(); auto end_it = begin_it; while (end_it != name.end() && *end_it != ':') { ++end_it; } if (end_it != name.end() && *end_it != ':') { - return absl::string_view(empty); + return StringPiece(empty); } - return absl::string_view(&(*begin_it), std::distance(begin_it, end_it)); + return StringPiece(&(*begin_it), std::distance(begin_it, end_it)); } // Return the node name corresponding to 'name' if name is valid, or the empty @@ -160,12 +160,12 @@ inline string NodeName(const string& name) { } // Returns the node name and position in a single call. -inline absl::string_view ParseNodeNameAsStringPiece(const string& name, - int* position) { +inline StringPiece ParseNodeNameAsStringPiece(const string& name, + int* position) { static const string empty; if (name.empty()) { *position = 0; - return absl::string_view(empty); + return StringPiece(empty); } const bool is_ctrl = name[0] == '^'; const auto begin_it = is_ctrl ? name.begin() + 1 : name.begin(); @@ -174,17 +174,15 @@ inline absl::string_view ParseNodeNameAsStringPiece(const string& name, while (end_it != name.end() && *end_it != ':') { ++end_it; } - const absl::string_view node_name(&(*begin_it), - std::distance(begin_it, end_it)); + const StringPiece node_name(&(*begin_it), std::distance(begin_it, end_it)); if (end_it != name.end()) { if (*end_it != ':') { - return absl::string_view(empty); + return StringPiece(empty); } else if (!is_ctrl) { ++end_it; - absl::string_view remaining(&(*end_it), - std::distance(end_it, name.end())); + StringPiece remaining(&(*end_it), std::distance(end_it, name.end())); if (!strings::safe_strto32(remaining, position)) { - return absl::string_view(empty); + return StringPiece(empty); } } } diff --git a/tensorflow/core/grappler/utils/BUILD b/tensorflow/core/grappler/utils/BUILD index ae251577c7d..bdbb8836e17 100644 --- a/tensorflow/core/grappler/utils/BUILD +++ b/tensorflow/core/grappler/utils/BUILD @@ -170,7 +170,6 @@ cc_library( "//tensorflow/core/grappler:grappler_item", "//tensorflow/core/grappler:op_types", "//tensorflow/core/grappler:utils", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/grappler/utils/functions.cc b/tensorflow/core/grappler/utils/functions.cc index e3b2984d855..6861fb423c5 100644 --- a/tensorflow/core/grappler/utils/functions.cc +++ b/tensorflow/core/grappler/utils/functions.cc @@ -16,7 +16,6 @@ limitations under the License. #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/function.pb.h" @@ -109,8 +108,8 @@ Status GrapplerFunctionConnectivity::ExpandFunctionDefInput( string node_output; int position = -1; - absl::string_view capture; - absl::string_view remaining; + StringPiece capture; + StringPiece remaining; // Parse "node_name" if (Scanner(func_def_input) diff --git a/tensorflow/core/grappler/utils_test.cc b/tensorflow/core/grappler/utils_test.cc index a81d8e7bcdc..9b6c1f690b4 100644 --- a/tensorflow/core/grappler/utils_test.cc +++ b/tensorflow/core/grappler/utils_test.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/grappler/utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/standard_ops.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/grappler/grappler_item.h" @@ -372,17 +371,16 @@ BM_NodePositionIfSameNode("^foo/bar/baz", "foo/bar/baz", Match_Ctrl); BM_NodePositionIfSameNode("blah", "foo/bar/baz", NoMatch_0); BM_NodePositionIfSameNode("foo/bar/baz/gnu", "foo/bar/baz", NoMatch_end); -#define BM_ParseNodeNameAsStringPiece(I, NAME) \ - static void BM_ParseNodeNameAsStringPiece_##NAME(int iters) { \ - string input = I; \ - for (int i = 0; i < iters; ++i) { \ - int position; \ - const absl::string_view name = \ - ParseNodeNameAsStringPiece(input, &position); \ - CHECK_GE(position, -1); \ - CHECK(!name.empty()); \ - } \ - } \ +#define BM_ParseNodeNameAsStringPiece(I, NAME) \ + static void BM_ParseNodeNameAsStringPiece_##NAME(int iters) { \ + string input = I; \ + for (int i = 0; i < iters; ++i) { \ + int position; \ + const StringPiece name = ParseNodeNameAsStringPiece(input, &position); \ + CHECK_GE(position, -1); \ + CHECK(!name.empty()); \ + } \ + } \ BENCHMARK(BM_ParseNodeNameAsStringPiece_##NAME) BM_ParseNodeNameAsStringPiece("foo", foo); diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 5567288f1ef..1f401b257b9 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -578,7 +578,6 @@ ARRAY_DEPS = [ ":gather_functor", ":ops_util", ":transpose_functor", - "@com_google_absl//absl/strings", "//tensorflow/core:array_grad", "//tensorflow/core:array_ops_op_lib", "//tensorflow/core:core_cpu", @@ -1746,7 +1745,6 @@ DATA_FLOW_DEPS = [ ":tensor_array", ":typed_conditional_accumulator_base", ":typed_queue", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core:core_cpu", "//tensorflow/core:data_flow_ops_op_lib", @@ -2106,7 +2104,6 @@ tf_kernel_library( "//tensorflow/core:lib", "//tensorflow/core:list_ops_op_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) @@ -2190,7 +2187,6 @@ IMAGE_DEPS = [ ":bounds_check", ":eigen_helpers", ":image_resizer_state", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core:framework", "//tensorflow/core:gif_internal", @@ -2622,7 +2618,6 @@ tf_cc_tests( "//tensorflow/core:test_main", "//tensorflow/core:testlib", "//tensorflow/core/util/tensor_bundle", - "@com_google_absl//absl/strings", ], ) @@ -3175,7 +3170,6 @@ tf_cc_tests( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", - "@com_google_absl//absl/strings", ], ) @@ -3322,7 +3316,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", - "@com_google_absl//absl/strings", ], ) @@ -3344,7 +3337,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", - "@com_google_absl//absl/strings", ], ) @@ -3469,7 +3461,6 @@ tf_kernel_library( ":image_resizer_state", ":fill_functor", ":ops_util", - "@com_google_absl//absl/strings", "//tensorflow/core:core_cpu", "//tensorflow/core:framework", "//tensorflow/core:lib", @@ -3934,7 +3925,6 @@ cc_library( ) PARSING_DEPS = [ - "@com_google_absl//absl/strings", "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:parsing_ops_op_lib", @@ -4120,7 +4110,6 @@ cc_library( ) SPARSE_DEPS = [ - "@com_google_absl//absl/strings", "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:sparse_ops_op_lib", @@ -4539,7 +4528,6 @@ cc_library( STRING_DEPS = [ ":bounds_check", ":string_util", - "@com_google_absl//absl/strings", "//third_party/eigen3", "//tensorflow/core:framework", "//tensorflow/core:lib", @@ -4562,7 +4550,7 @@ tf_kernel_library( tf_kernel_library( name = "string_format_op", prefix = "string_format_op", - deps = STRING_DEPS, + deps = STRING_DEPS + ["@com_google_absl//absl/strings"], ) tf_cc_test( @@ -4815,7 +4803,6 @@ tf_kernel_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:word2vec_ops", - "@com_google_absl//absl/strings", ], ) @@ -4854,7 +4841,6 @@ cc_library( "//tensorflow/core:lib_internal", "//tensorflow/core:protos_all_cc", "//tensorflow/core:test", - "@com_google_absl//absl/strings", ], ) @@ -6338,7 +6324,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/kernels/conv_grad_ops.cc b/tensorflow/core/kernels/conv_grad_ops.cc index 00abebd8953..507720c998d 100644 --- a/tensorflow/core/kernels/conv_grad_ops.cc +++ b/tensorflow/core/kernels/conv_grad_ops.cc @@ -15,7 +15,6 @@ limitations under the License. // See docs in ../ops/nn_ops.cc. -#include "absl/strings/string_view.h" #define USE_EIGEN_TENSOR #define EIGEN_USE_THREADS @@ -57,7 +56,7 @@ int ConvBackpropDimensions::SpatialPadding(const Padding& padding, // while the original version only handles the cases where dilation_rates equal // to 1. Status ConvBackpropExtractAndVerifyDimensionV2( - absl::string_view label, const TensorShape& input_shape, + StringPiece label, const TensorShape& input_shape, const TensorShape& filter_shape, const TensorShape& output_shape, const gtl::ArraySlice<int32>& dilations, const std::vector<int32>& strides, Padding padding, int spatial_dim, int filter_spatial_dim, @@ -96,7 +95,7 @@ Status ConvBackpropExtractAndVerifyDimensionV2( } Status ConvBackpropExtractAndVerifyDimension( - absl::string_view label, const TensorShape& input_shape, + StringPiece label, const TensorShape& input_shape, const TensorShape& filter_shape, const TensorShape& output_shape, const std::vector<int32>& strides, Padding padding, int spatial_dim, int filter_spatial_dim, ConvBackpropSpatialDimension* dim) { @@ -107,9 +106,8 @@ Status ConvBackpropExtractAndVerifyDimension( } Status ConvBackpropComputeDimensionsV2( - absl::string_view label, int num_spatial_dims, - const TensorShape& input_shape, const TensorShape& filter_shape, - const TensorShape& out_backprop_shape, + StringPiece label, int num_spatial_dims, const TensorShape& input_shape, + const TensorShape& filter_shape, const TensorShape& out_backprop_shape, const gtl::ArraySlice<int32>& dilations, const std::vector<int32>& strides, Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims) { // The + 2 in the following line is for the batch and feature dimensions. @@ -161,11 +159,13 @@ Status ConvBackpropComputeDimensionsV2( return Status::OK(); } -Status ConvBackpropComputeDimensions( - absl::string_view label, int num_spatial_dims, - const TensorShape& input_shape, const TensorShape& filter_shape, - const TensorShape& out_backprop_shape, const std::vector<int32>& strides, - Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims) { +Status ConvBackpropComputeDimensions(StringPiece label, int num_spatial_dims, + const TensorShape& input_shape, + const TensorShape& filter_shape, + const TensorShape& out_backprop_shape, + const std::vector<int32>& strides, + Padding padding, TensorFormat data_format, + ConvBackpropDimensions* dims) { static constexpr std::array<int32, 5> one_dilations = {{1, 1, 1, 1, 1}}; return ConvBackpropComputeDimensionsV2( label, num_spatial_dims, input_shape, filter_shape, out_backprop_shape, diff --git a/tensorflow/core/kernels/conv_grad_ops.h b/tensorflow/core/kernels/conv_grad_ops.h index 24a4deb8d35..9551959463b 100644 --- a/tensorflow/core/kernels/conv_grad_ops.h +++ b/tensorflow/core/kernels/conv_grad_ops.h @@ -161,8 +161,8 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor_shape.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/util/padding.h" #include "tensorflow/core/util/tensor_format.h" @@ -249,18 +249,19 @@ struct ConvBackpropDimensions { // Common code between implementations of Conv?DBackpropInput and // Conv?DBackpropFilter. Verifies that the dimensions all match, and computes // sizes/padding for the spatial dimensions. -Status ConvBackpropComputeDimensions( - absl::string_view label, int num_spatial_dims, - const TensorShape& input_shape, const TensorShape& filter_shape, - const TensorShape& out_backprop_shape, const std::vector<int32>& strides, - Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims); +Status ConvBackpropComputeDimensions(StringPiece label, int num_spatial_dims, + const TensorShape& input_shape, + const TensorShape& filter_shape, + const TensorShape& out_backprop_shape, + const std::vector<int32>& strides, + Padding padding, TensorFormat data_format, + ConvBackpropDimensions* dims); // The V2 version computes the same outputs with arbitrary dilation rate. // TODO(b/67112639): Merge V2 versions and the original versions eventually. Status ConvBackpropComputeDimensionsV2( - absl::string_view label, int num_spatial_dims, - const TensorShape& input_shape, const TensorShape& filter_shape, - const TensorShape& out_backprop_shape, + StringPiece label, int num_spatial_dims, const TensorShape& input_shape, + const TensorShape& filter_shape, const TensorShape& out_backprop_shape, const gtl::ArraySlice<int32>& dilations, const std::vector<int32>& strides, Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims); } // namespace tensorflow diff --git a/tensorflow/core/kernels/data/BUILD b/tensorflow/core/kernels/data/BUILD index 6f6ba6943bd..37c1c547861 100644 --- a/tensorflow/core/kernels/data/BUILD +++ b/tensorflow/core/kernels/data/BUILD @@ -42,7 +42,6 @@ cc_library( "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) @@ -640,7 +639,6 @@ tf_kernel_library( "//tensorflow/core:protos_all_cc", "//tensorflow/core:session_options", "//tensorflow/core/kernels:ops_util", - "@com_google_absl//absl/strings", ], ) @@ -682,7 +680,6 @@ tf_kernel_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core/util/tensor_bundle", - "@com_google_absl//absl/strings", ], ) @@ -797,7 +794,6 @@ tf_kernel_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core/kernels:ops_util", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/kernels/data/cache_dataset_ops.cc b/tensorflow/core/kernels/data/cache_dataset_ops.cc index ced5fb1971b..f2419db3dc2 100644 --- a/tensorflow/core/kernels/data/cache_dataset_ops.cc +++ b/tensorflow/core/kernels/data/cache_dataset_ops.cc @@ -12,7 +12,6 @@ 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 "absl/strings/string_view.h" #include "tensorflow/core/framework/partial_tensor_shape.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/kernels/data/dataset.h" @@ -340,7 +339,7 @@ class CacheDatasetOp : public UnaryDatasetOpKernel { if (dataset()->env_->FileExists(lockfile_).ok()) { // Attempt to read the contents of the lockfile. char contents_scratch[151] = {0}; // Initialize all to 0. - absl::string_view contents; + StringPiece contents; std::unique_ptr<RandomAccessFile> file; if (dataset()->env_->NewRandomAccessFile(lockfile_, &file).ok()) { file->Read(0, 150, &contents, contents_scratch).IgnoreError(); @@ -459,7 +458,7 @@ class CacheDatasetOp : public UnaryDatasetOpKernel { *end_of_sequence = true; return Status::OK(); } - absl::string_view key = reader_.key(); + StringPiece key = reader_.key(); DCHECK_EQ(key, dataset()->FormatName(cur_index_, i)); TF_RETURN_IF_ERROR(reader_.ReadCurrent(&(*out_tensors)[i])); TF_RETURN_IF_ERROR(reader_.status()); diff --git a/tensorflow/core/kernels/data/dataset_utils.cc b/tensorflow/core/kernels/data/dataset_utils.cc index f6e45bf0f51..a40f7f2146d 100644 --- a/tensorflow/core/kernels/data/dataset_utils.cc +++ b/tensorflow/core/kernels/data/dataset_utils.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/kernels/data/dataset_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/function.h" #include "tensorflow/core/framework/op_kernel.h" @@ -69,8 +68,8 @@ std::vector<bool> ComputeMoveVector(const std::vector<int>& indices) { Status MakeIteratorFromInputElement( IteratorContext* ctx, const std::vector<Tensor>& input_element, - int64 thread_index, CapturedFunction* captured_func, - absl::string_view prefix, std::unique_ptr<IteratorBase>* out_iterator) { + int64 thread_index, CapturedFunction* captured_func, StringPiece prefix, + std::unique_ptr<IteratorBase>* out_iterator) { std::vector<Tensor> return_values; TF_RETURN_IF_ERROR( diff --git a/tensorflow/core/kernels/data/dataset_utils.h b/tensorflow/core/kernels/data/dataset_utils.h index fbc26872f3b..d7770622936 100644 --- a/tensorflow/core/kernels/data/dataset_utils.h +++ b/tensorflow/core/kernels/data/dataset_utils.h @@ -15,7 +15,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_KERNELS_DATA_DATASET_UTILS_H_ #define TENSORFLOW_CORE_KERNELS_DATA_DATASET_UTILS_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/kernels/data/captured_function.h" #include "tensorflow/core/kernels/data/dataset.h" @@ -45,8 +44,8 @@ std::vector<bool> ComputeMoveVector(const std::vector<int>& indices); Status MakeIteratorFromInputElement( IteratorContext* ctx, const std::vector<Tensor>& input_element, - int64 thread_index, CapturedFunction* captured_func, - absl::string_view prefix, std::unique_ptr<IteratorBase>* out_iterator); + int64 thread_index, CapturedFunction* captured_func, StringPiece prefix, + std::unique_ptr<IteratorBase>* out_iterator); // Returns Status::OK() if `expected` and `received` types match, // errors::InvalidArgument otherwise. diff --git a/tensorflow/core/kernels/data/experimental/BUILD b/tensorflow/core/kernels/data/experimental/BUILD index 07437e0c5fe..441bdc2898f 100644 --- a/tensorflow/core/kernels/data/experimental/BUILD +++ b/tensorflow/core/kernels/data/experimental/BUILD @@ -66,7 +66,6 @@ tf_kernel_library( "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/kernels/data/experimental/csv_dataset_op.cc b/tensorflow/core/kernels/data/experimental/csv_dataset_op.cc index 8114a5cf6ee..7451ca4cb16 100644 --- a/tensorflow/core/kernels/data/experimental/csv_dataset_op.cc +++ b/tensorflow/core/kernels/data/experimental/csv_dataset_op.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ // See docs in ../ops/parsing_ops.cc. -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/dataset.h" #include "tensorflow/core/framework/op.h" @@ -380,7 +379,7 @@ class CSVDatasetOp : public DatasetOpKernel { // Reached EOF, and last field is empty *end_of_record = true; if (include) { - return FieldToOutput(ctx, absl::string_view(), out_tensors); + return FieldToOutput(ctx, StringPiece(), out_tensors); } else { return Status::OK(); } @@ -461,9 +460,8 @@ class CSVDatasetOp : public DatasetOpKernel { if (errors::IsOutOfRange(s)) { // This was the last field. We are done *end_of_record = true; - parse_result.Update( - QuotedFieldToOutput(ctx, absl::string_view(), out_tensors, - earlier_pieces, include)); + parse_result.Update(QuotedFieldToOutput( + ctx, StringPiece(), out_tensors, earlier_pieces, include)); return parse_result; } else if (!s.ok()) { return s; @@ -474,14 +472,14 @@ class CSVDatasetOp : public DatasetOpKernel { pos_++; if (next == dataset()->delim_) { parse_result.Update(QuotedFieldToOutput( - ctx, absl::string_view(&buffer_[start], pos_ - 1 - start), + ctx, StringPiece(&buffer_[start], pos_ - 1 - start), out_tensors, earlier_pieces, include)); return parse_result; } else if (next == '\n' || next == '\r') { *end_of_record = true; parse_result.Update(QuotedFieldToOutput( - ctx, absl::string_view(&buffer_[start], pos_ - 1 - start), + ctx, StringPiece(&buffer_[start], pos_ - 1 - start), out_tensors, earlier_pieces, include)); if (next == '\r') SkipNewLineIfNecessary(); return parse_result; @@ -502,7 +500,7 @@ class CSVDatasetOp : public DatasetOpKernel { // Converts quoted field to an output tensor, removing the starting // and ending quotes from it and unescaping double quotations if // necessary. - Status QuotedFieldToOutput(IteratorContext* ctx, absl::string_view field, + Status QuotedFieldToOutput(IteratorContext* ctx, StringPiece field, std::vector<Tensor>* out_tensors, const std::vector<Piece>& earlier_pieces, bool include) EXCLUSIVE_LOCKS_REQUIRED(mu_) { @@ -531,17 +529,17 @@ class CSVDatasetOp : public DatasetOpKernel { // the opening quotation mark of the quoted field. bool skip_next_quote = true; for (const Piece& p : earlier_pieces) { - AppendUnescapedPiece(absl::string_view(&p.buffer[p.start], p.len), + AppendUnescapedPiece(StringPiece(&p.buffer[p.start], p.len), &field_complete, &skip_next_quote); } AppendUnescapedPiece(field, &field_complete, &skip_next_quote); - absl::string_view result = absl::string_view(field_complete); + StringPiece result = StringPiece(field_complete); result.remove_suffix(1); // Skip final quote return FieldToOutput(ctx, result, out_tensors); } - void AppendUnescapedPiece(absl::string_view piece, string* field_complete, + void AppendUnescapedPiece(StringPiece piece, string* field_complete, bool* skip_next_quote) { size_t from = 0; size_t found = piece.find('\"', from); @@ -580,8 +578,8 @@ class CSVDatasetOp : public DatasetOpKernel { // Whatever we have is the last field of the last record *end_of_record = true; parse_result.Update(UnquotedFieldToOutput( - ctx, absl::string_view(&buffer_[start], pos_ - start), - out_tensors, earlier_pieces, include)); + ctx, StringPiece(&buffer_[start], pos_ - start), out_tensors, + earlier_pieces, include)); return parse_result; } else if (!s.ok()) { return s; // Surface all other errors to caller @@ -592,8 +590,8 @@ class CSVDatasetOp : public DatasetOpKernel { if (ch == dataset()->delim_) { parse_result.Update(UnquotedFieldToOutput( - ctx, absl::string_view(&buffer_[start], pos_ - start), - out_tensors, earlier_pieces, include)); + ctx, StringPiece(&buffer_[start], pos_ - start), out_tensors, + earlier_pieces, include)); pos_++; return parse_result; } @@ -601,8 +599,8 @@ class CSVDatasetOp : public DatasetOpKernel { // need special case to skip over first \n of record if the line // breaks are \r\n parse_result.Update(UnquotedFieldToOutput( - ctx, absl::string_view(&buffer_[start], pos_ - start), - out_tensors, earlier_pieces, include)); + ctx, StringPiece(&buffer_[start], pos_ - start), out_tensors, + earlier_pieces, include)); *end_of_record = true; pos_++; if (ch == '\r') SkipNewLineIfNecessary(); @@ -632,7 +630,7 @@ class CSVDatasetOp : public DatasetOpKernel { } // Given a field, converts it to the right output tensor type - Status FieldToOutput(IteratorContext* ctx, absl::string_view field, + Status FieldToOutput(IteratorContext* ctx, StringPiece field, std::vector<Tensor>* out_tensors) { size_t output_idx = out_tensors->size(); if (output_idx >= dataset()->out_type_.size()) { @@ -751,8 +749,7 @@ class CSVDatasetOp : public DatasetOpKernel { // Given a string field, and its index in the output, // converts it to a Tensor of the right type and adds it to the // out_tensors vector. - Status UnquotedFieldToOutput(IteratorContext* ctx, - absl::string_view field, + Status UnquotedFieldToOutput(IteratorContext* ctx, StringPiece field, std::vector<Tensor>* out_tensors, const std::vector<Piece>& earlier_pieces, bool include) EXCLUSIVE_LOCKS_REQUIRED(mu_) { diff --git a/tensorflow/core/kernels/data/experimental/indexed_dataset.h b/tensorflow/core/kernels/data/experimental/indexed_dataset.h index 66bdbc55938..27a8360cbcf 100644 --- a/tensorflow/core/kernels/data/experimental/indexed_dataset.h +++ b/tensorflow/core/kernels/data/experimental/indexed_dataset.h @@ -15,7 +15,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_KERNELS_DATA_EXPERIMENTAL_INDEXED_DATASET_H_ #define TENSORFLOW_CORE_KERNELS_DATA_EXPERIMENTAL_INDEXED_DATASET_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/dataset.h" #include "tensorflow/core/framework/op_kernel.h" @@ -85,8 +84,7 @@ class IndexedDatasetOpKernel : public OpKernel { template <typename T> Status ParseScalarArgument(OpKernelContext* ctx, - const absl::string_view& argument_name, - T* output) { + const StringPiece& argument_name, T* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); if (!TensorShapeUtils::IsScalar(argument_t->shape())) { diff --git a/tensorflow/core/kernels/data/iterator_ops.cc b/tensorflow/core/kernels/data/iterator_ops.cc index fca61d4e8f4..7a833668aca 100644 --- a/tensorflow/core/kernels/data/iterator_ops.cc +++ b/tensorflow/core/kernels/data/iterator_ops.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/kernels/data/iterator_ops.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/graph_runner.h" #include "tensorflow/core/common_runtime/renamed_device.h" #include "tensorflow/core/common_runtime/threadpool_device.h" @@ -214,19 +213,19 @@ class VariantTensorDataReader : public IteratorStateReader { // pre-processing did not have errors. Status status() const { return status_; } - Status ReadScalar(absl::string_view key, int64* val) override { + Status ReadScalar(StringPiece key, int64* val) override { return ReadScalarInternal(key, val); } - Status ReadScalar(absl::string_view key, string* val) override { + Status ReadScalar(StringPiece key, string* val) override { return ReadScalarInternal(key, val); } - Status ReadTensor(absl::string_view key, Tensor* val) override { + Status ReadTensor(StringPiece key, Tensor* val) override { return ReadTensorInternal(key, val); } - bool Contains(absl::string_view key) override { + bool Contains(StringPiece key) override { return map_.find(string(key)) != map_.end(); } @@ -247,7 +246,7 @@ class VariantTensorDataReader : public IteratorStateReader { } template <typename T> - Status ReadScalarInternal(absl::string_view key, T* val) { + Status ReadScalarInternal(StringPiece key, T* val) { if (map_.find(string(key)) == map_.end()) { return errors::NotFound(key); } @@ -255,7 +254,7 @@ class VariantTensorDataReader : public IteratorStateReader { return Status::OK(); } - Status ReadTensorInternal(absl::string_view key, Tensor* val) { + Status ReadTensorInternal(StringPiece key, Tensor* val) { if (map_.find(string(key)) == map_.end()) { return errors::NotFound(key); } @@ -274,15 +273,15 @@ class VariantTensorDataWriter : public IteratorStateWriter { // Does not take ownership of data. explicit VariantTensorDataWriter(VariantTensorData* data) : data_(data) {} - Status WriteScalar(absl::string_view key, const int64 val) override { + Status WriteScalar(StringPiece key, const int64 val) override { return WriteScalarInternal(key, val); } - Status WriteScalar(absl::string_view key, const string& val) override { + Status WriteScalar(StringPiece key, const string& val) override { return WriteScalarInternal(key, val); } - Status WriteTensor(absl::string_view key, const Tensor& val) override { + Status WriteTensor(StringPiece key, const Tensor& val) override { return WriteTensorInternal(key, val); } @@ -298,13 +297,13 @@ class VariantTensorDataWriter : public IteratorStateWriter { private: template <typename T> - Status WriteScalarInternal(absl::string_view key, const T& val) { + Status WriteScalarInternal(StringPiece key, const T& val) { Tensor val_t = Tensor(DataTypeToEnum<T>::v(), TensorShape({})); val_t.scalar<T>()() = val; return WriteTensorInternal(key, val_t); } - Status WriteTensorInternal(absl::string_view key, const Tensor& val) { + Status WriteTensorInternal(StringPiece key, const Tensor& val) { // Write key to the metadata proto. This gets written to `data_` // when `Flush()` is called. We do this lazily to avoid multiple // serialization calls. diff --git a/tensorflow/core/kernels/data/writer_ops.cc b/tensorflow/core/kernels/data/writer_ops.cc index b3f7ab9fd74..3f76695bb1c 100644 --- a/tensorflow/core/kernels/data/writer_ops.cc +++ b/tensorflow/core/kernels/data/writer_ops.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/kernels/data/dataset.h" #include "tensorflow/core/kernels/data/dataset_utils.h" @@ -37,8 +36,7 @@ class ToTFRecordOp : public AsyncOpKernel { template <typename T> Status ParseScalarArgument(OpKernelContext* ctx, - const absl::string_view& argument_name, - T* output) { + const StringPiece& argument_name, T* output) { const Tensor* argument_t; TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); if (!TensorShapeUtils::IsScalar(argument_t->shape())) { diff --git a/tensorflow/core/kernels/decode_bmp_op.cc b/tensorflow/core/kernels/decode_bmp_op.cc index 94c21f4da3f..ae451be7e21 100644 --- a/tensorflow/core/kernels/decode_bmp_op.cc +++ b/tensorflow/core/kernels/decode_bmp_op.cc @@ -16,7 +16,6 @@ limitations under the License. // See docs in ../ops/image_ops.cc #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor.h" @@ -55,7 +54,7 @@ class DecodeBmpOp : public OpKernel { contents.shape().DebugString())); // Start decoding image to get shape details - const absl::string_view input = contents.scalar<string>()(); + const StringPiece input = contents.scalar<string>()(); OP_REQUIRES(context, (32 <= input.size()), errors::InvalidArgument("Incomplete bmp content, requires at " diff --git a/tensorflow/core/kernels/decode_csv_op.cc b/tensorflow/core/kernels/decode_csv_op.cc index d2999102b67..6bfb5bd5bc0 100644 --- a/tensorflow/core/kernels/decode_csv_op.cc +++ b/tensorflow/core/kernels/decode_csv_op.cc @@ -15,7 +15,6 @@ limitations under the License. // See docs in ../ops/parsing_ops.cc. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -83,7 +82,7 @@ class DecodeCSVOp : public OpKernel { } for (int64 i = 0; i < records_size; ++i) { - const absl::string_view record(records_t(i)); + const StringPiece record(records_t(i)); std::vector<string> fields; ExtractFields(ctx, record, &fields); OP_REQUIRES(ctx, fields.size() == out_type_.size(), @@ -206,7 +205,7 @@ class DecodeCSVOp : public OpKernel { bool select_all_cols_; string na_value_; - void ExtractFields(OpKernelContext* ctx, absl::string_view input, + void ExtractFields(OpKernelContext* ctx, StringPiece input, std::vector<string>* result) { int64 current_idx = 0; int64 num_fields_parsed = 0; diff --git a/tensorflow/core/kernels/decode_image_op.cc b/tensorflow/core/kernels/decode_image_op.cc index ed1b85042a8..2cafa44f37a 100644 --- a/tensorflow/core/kernels/decode_image_op.cc +++ b/tensorflow/core/kernels/decode_image_op.cc @@ -16,7 +16,6 @@ limitations under the License. // See docs in ../ops/image_ops.cc #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor.h" @@ -40,7 +39,7 @@ enum FileFormat { }; // Classify the contents of a file based on starting bytes (the magic number). -FileFormat ClassifyFileFormat(absl::string_view data) { +FileFormat ClassifyFileFormat(StringPiece data) { // The 4th byte of JPEG is '\xe0' or '\xe1', so check just the first three if (str_util::StartsWith(data, "\xff\xd8\xff")) return kJpgFormat; if (str_util::StartsWith(data, "\x89PNG\r\n\x1a\n")) return kPngFormat; @@ -48,7 +47,7 @@ FileFormat ClassifyFileFormat(absl::string_view data) { return kUnknownFormat; } -string FileFormatString(FileFormat magic, absl::string_view data) { +string FileFormatString(FileFormat magic, StringPiece data) { switch (magic) { case kPngFormat: return "PNG"; @@ -153,7 +152,7 @@ class DecodeImageOp : public OpKernel { contents.shape().DebugString())); // Determine format - const absl::string_view input = contents.scalar<string>()(); + const StringPiece input = contents.scalar<string>()(); const auto magic = ClassifyFileFormat(input); OP_REQUIRES( context, @@ -184,7 +183,7 @@ class DecodeImageOp : public OpKernel { } } - void DecodeJpeg(OpKernelContext* context, absl::string_view input) { + void DecodeJpeg(OpKernelContext* context, StringPiece input) { OP_REQUIRES(context, channels_ == 0 || channels_ == 1 || channels_ == 3, errors::InvalidArgument( "channels must be 0, 1, or 3 for JPEG, got ", channels_)); @@ -232,7 +231,7 @@ class DecodeImageOp : public OpKernel { input.size())); } - void DecodePng(OpKernelContext* context, absl::string_view input) { + void DecodePng(OpKernelContext* context, StringPiece input) { // Start decoding png to get shape details png::DecodeContext decode; OP_REQUIRES(context, @@ -288,7 +287,7 @@ class DecodeImageOp : public OpKernel { } } - void DecodeGif(OpKernelContext* context, absl::string_view input) { + void DecodeGif(OpKernelContext* context, StringPiece input) { OP_REQUIRES(context, channels_ == 0 || channels_ == 3, errors::InvalidArgument("channels must be 0 or 3 for GIF, got ", channels_)); diff --git a/tensorflow/core/kernels/deep_conv2d.cc b/tensorflow/core/kernels/deep_conv2d.cc index 8d6ab69f629..1aa8c72d667 100644 --- a/tensorflow/core/kernels/deep_conv2d.cc +++ b/tensorflow/core/kernels/deep_conv2d.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #define USE_EIGEN_TENSOR #define EIGEN_USE_THREADS @@ -82,7 +81,7 @@ static int64 GetDirectConvCost(int filter_rows, int filter_cols, int in_depth, static bool ReadBoolFromEnvVar(const char* env_var_name, bool default_val) { const char* tf_env_var_val = getenv(env_var_name); if (tf_env_var_val != nullptr) { - absl::string_view tf_env_var_val_str(tf_env_var_val); + StringPiece tf_env_var_val_str(tf_env_var_val); if (tf_env_var_val_str == "0") { return false; } diff --git a/tensorflow/core/kernels/extract_jpeg_shape_op.cc b/tensorflow/core/kernels/extract_jpeg_shape_op.cc index e36f8c37e79..60d798af567 100644 --- a/tensorflow/core/kernels/extract_jpeg_shape_op.cc +++ b/tensorflow/core/kernels/extract_jpeg_shape_op.cc @@ -16,7 +16,6 @@ limitations under the License. // See docs in ../ops/image_ops.cc #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor.h" @@ -42,7 +41,7 @@ class ExtractJpegShapeOp : public OpKernel { OP_REQUIRES(context, TensorShapeUtils::IsScalar(contents.shape()), errors::InvalidArgument("contents must be scalar, got shape ", contents.shape().DebugString())); - const absl::string_view input = contents.scalar<string>()(); + const StringPiece input = contents.scalar<string>()(); OP_REQUIRES(context, input.size() <= std::numeric_limits<int>::max(), errors::InvalidArgument("JPEG contents are too large for int: ", input.size())); diff --git a/tensorflow/core/kernels/gpu_utils.h b/tensorflow/core/kernels/gpu_utils.h index a28247c1f47..86146f75f4d 100644 --- a/tensorflow/core/kernels/gpu_utils.h +++ b/tensorflow/core/kernels/gpu_utils.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_KERNELS_GPU_UTILS_H_ #define TENSORFLOW_CORE_KERNELS_GPU_UTILS_H_ -#include "absl/strings/string_view.h" #if GOOGLE_CUDA #include <unordered_map> @@ -121,7 +120,7 @@ class AutoTuneMap { } }; - string GetActionSummary(absl::string_view action, const Parameters& params, + string GetActionSummary(StringPiece action, const Parameters& params, const Config& config) { return strings::Printf("autotune_map %s %s: %s -> (%s)", name_.c_str(), string(action).c_str(), params.ToString().c_str(), diff --git a/tensorflow/core/kernels/hexagon/BUILD b/tensorflow/core/kernels/hexagon/BUILD index f332c1fbe27..4870d9ae200 100644 --- a/tensorflow/core/kernels/hexagon/BUILD +++ b/tensorflow/core/kernels/hexagon/BUILD @@ -40,7 +40,6 @@ tf_cc_test( "//tensorflow/core/kernels:remote_fused_graph_ops", "//tensorflow/core/kernels:reshape_op", "//tensorflow/core/kernels:softmax_op", - "@com_google_absl//absl/strings", ], ) @@ -71,7 +70,6 @@ tf_kernel_library( "//tensorflow/core:protos_all_cc", "//tensorflow/core/kernels:remote_fused_graph_execute_utils", "//third_party/eigen3", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/kernels/hexagon/graph_transfer_utils.cc b/tensorflow/core/kernels/hexagon/graph_transfer_utils.cc index 655b4b255d4..40bf5a4dc71 100644 --- a/tensorflow/core/kernels/hexagon/graph_transfer_utils.cc +++ b/tensorflow/core/kernels/hexagon/graph_transfer_utils.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/kernels/hexagon/graph_transfer_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/remote_fused_graph_execute_info.pb.h" @@ -154,7 +153,7 @@ GraphTransferUtils::BuildRemoteFusedGraphExecuteInfo( .Attr("Tinputs", input_types) .Attr("Toutputs", output_types) .Attr("serialized_remote_fused_graph_execute_info", - absl::string_view(execute_info.SerializeAsString())); + StringPiece(execute_info.SerializeAsString())); CHECK(scope.ok()); scope.UpdateBuilder(&builder); scope.UpdateStatus(builder.Finalize(scope.graph(), &node)); diff --git a/tensorflow/core/kernels/hexagon/graph_transferer.cc b/tensorflow/core/kernels/hexagon/graph_transferer.cc index 345d2285613..477e729dcb9 100644 --- a/tensorflow/core/kernels/hexagon/graph_transferer.cc +++ b/tensorflow/core/kernels/hexagon/graph_transferer.cc @@ -18,7 +18,6 @@ limitations under the License. #include <algorithm> #include <cinttypes> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph_transfer_info.pb.h" #include "tensorflow/core/framework/op.h" @@ -588,7 +587,7 @@ bool GraphTransferer::HasPaddingAndStrides(const Node& node) { } bool GraphTransferer::NeedsToAddRank(const Node& node) { - const absl::string_view op_type(node.type_string()); + const StringPiece op_type(node.type_string()); if (op_type == "Transpose" || op_type == "ExpandDims") { return true; } @@ -596,7 +595,7 @@ bool GraphTransferer::NeedsToAddRank(const Node& node) { } bool GraphTransferer::IsPadNode(const Node& node) { - const absl::string_view op_type(node.type_string()); + const StringPiece op_type(node.type_string()); if (op_type == "Pad") { return true; } diff --git a/tensorflow/core/kernels/hexagon/graph_transferer_test.cc b/tensorflow/core/kernels/hexagon/graph_transferer_test.cc index 5d1734e4774..765795b1f4a 100644 --- a/tensorflow/core/kernels/hexagon/graph_transferer_test.cc +++ b/tensorflow/core/kernels/hexagon/graph_transferer_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/const_op.h" #include "tensorflow/core/framework/graph_transfer_info.pb.h" #include "tensorflow/core/framework/tensor_testutil.h" @@ -100,7 +99,7 @@ static Output BuildSoftmaxOps(const Scope& scope, const Input& logits) { static Output BuildConv2DOps(const Scope& scope, const Input& input, const Input& filter, const gtl::ArraySlice<int>& strides, - const absl::string_view& padding) { + const StringPiece& padding) { EXPECT_TRUE(scope.ok()); auto _input = ops::AsNodeOut(scope, input); EXPECT_TRUE(scope.ok()); @@ -124,7 +123,7 @@ static Output BuildConv2DOps(const Scope& scope, const Input& input, static Output BuildMaxPoolOps(const Scope& scope, const Input& input, const gtl::ArraySlice<int>& ksize, const gtl::ArraySlice<int>& strides, - const absl::string_view& padding) { + const StringPiece& padding) { EXPECT_TRUE(scope.ok()); auto _input = ops::AsNodeOut(scope, input); EXPECT_TRUE(scope.ok()); diff --git a/tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc b/tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc index 9949b3d89cd..cc469f6dba1 100644 --- a/tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc +++ b/tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/kernels/hexagon/hexagon_control_wrapper.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph_transfer_info.pb.h" #include "tensorflow/core/framework/remote_fused_graph_execute_info.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h" @@ -411,7 +410,7 @@ Status HexagonControlWrapper::FuseRemoteGraph( bool HexagonControlWrapper::FillInputNode(const string& node_name, const Tensor& tensor) { - absl::string_view tensor_data = tensor.tensor_data(); + StringPiece tensor_data = tensor.tensor_data(); const ConstByteArray ba = ConstByteArray(reinterpret_cast<const uint8*>(tensor_data.data()), tensor_data.size(), tensor.dtype()); diff --git a/tensorflow/core/kernels/immutable_constant_op_test.cc b/tensorflow/core/kernels/immutable_constant_op_test.cc index 7a23fef1357..b2dc16d5d72 100644 --- a/tensorflow/core/kernels/immutable_constant_op_test.cc +++ b/tensorflow/core/kernels/immutable_constant_op_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <algorithm> #include <tuple> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/standard_ops.h" #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/tensor.h" @@ -65,7 +64,7 @@ class TestFileSystem : public NullFileSystem { const string& fname, std::unique_ptr<ReadOnlyMemoryRegion>* result) override { float val = 0; - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(fname, &scheme, &host, &path); // For the tests create in-memory regions with float values equal to the // region name. @@ -149,8 +148,8 @@ Status CreateTempFile(Env* env, float value, uint64 size, string* filename) { std::unique_ptr<WritableFile> file; TF_RETURN_IF_ERROR(env->NewWritableFile(*filename, &file)); for (uint64 i = 0; i < size; ++i) { - absl::string_view sp(static_cast<char*>(static_cast<void*>(&value)), - sizeof(value)); + StringPiece sp(static_cast<char*>(static_cast<void*>(&value)), + sizeof(value)); TF_RETURN_IF_ERROR(file->Append(sp)); } TF_RETURN_IF_ERROR(file->Close()); diff --git a/tensorflow/core/kernels/list_kernels.cc b/tensorflow/core/kernels/list_kernels.cc index ed957932856..2088c135866 100644 --- a/tensorflow/core/kernels/list_kernels.cc +++ b/tensorflow/core/kernels/list_kernels.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include <limits> -#include "absl/strings/string_view.h" #define EIGEN_USE_THREADS #if GOOGLE_CUDA @@ -100,7 +99,7 @@ bool TensorList::Decode(const VariantTensorData& data) { string metadata; data.get_metadata(&metadata); uint64 scratch; - absl::string_view iter(metadata); + StringPiece iter(metadata); core::GetVarint64(&iter, &scratch); element_dtype = static_cast<DataType>(scratch); std::vector<int64> dims; diff --git a/tensorflow/core/kernels/reduce_join_op.cc b/tensorflow/core/kernels/reduce_join_op.cc index 6a571dfca26..e2a3b861e52 100644 --- a/tensorflow/core/kernels/reduce_join_op.cc +++ b/tensorflow/core/kernels/reduce_join_op.cc @@ -17,13 +17,13 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -160,7 +160,7 @@ class ReduceJoinOp : public OpKernel { const int64 reduction_iter_size = GetReductionIterSize(reduced_indices, input_shape); - gtl::InlinedVector<absl::string_view, 8> curr_strings(reduction_iter_size); + gtl::InlinedVector<StringPiece, 8> curr_strings(reduction_iter_size); for (int64 output_index = 0; output_index < output_shape.num_elements(); ++output_index) { int64 output_full_index = LinearSubIndexToFullIndex( diff --git a/tensorflow/core/kernels/remote_fused_graph_execute_op_test.cc b/tensorflow/core/kernels/remote_fused_graph_execute_op_test.cc index c0ae6eb4b8f..ec769d41f96 100644 --- a/tensorflow/core/kernels/remote_fused_graph_execute_op_test.cc +++ b/tensorflow/core/kernels/remote_fused_graph_execute_op_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/cc/framework/ops.h" #include "tensorflow/cc/framework/scope.h" #include "tensorflow/cc/ops/const_op.h" @@ -118,7 +117,7 @@ static Output BuildRemoteFusedGraphExecuteOp( .Attr("Tinputs", input_types) .Attr("Toutputs", output_types) .Attr("serialized_remote_fused_graph_execute_info", - absl::string_view(execute_info.SerializeAsString())); + StringPiece(execute_info.SerializeAsString())); CHECK(scope.ok()); scope.UpdateBuilder(&builder); scope.UpdateStatus(builder.Finalize(scope.graph(), &ret)); diff --git a/tensorflow/core/kernels/restore_v2_op_test.cc b/tensorflow/core/kernels/restore_v2_op_test.cc index 2b679845645..36631570c7b 100644 --- a/tensorflow/core/kernels/restore_v2_op_test.cc +++ b/tensorflow/core/kernels/restore_v2_op_test.cc @@ -19,7 +19,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/framework/allocator.h" @@ -58,7 +57,7 @@ class RestoreV2OpTest : public OpsTestBase { TF_ASSERT_OK(InitOp()); } - void RunTest(absl::string_view save_op_to_use) { + void RunTest(StringPiece save_op_to_use) { const string filename = io::JoinPath(testing::TmpDir(), "tensor_simple-", save_op_to_use); const std::vector<string> tensor_names = { diff --git a/tensorflow/core/kernels/shape_op_test.cc b/tensorflow/core/kernels/shape_op_test.cc index f720ec99263..30cb1e0a7f8 100644 --- a/tensorflow/core/kernels/shape_op_test.cc +++ b/tensorflow/core/kernels/shape_op_test.cc @@ -16,7 +16,6 @@ limitations under the License. #include <functional> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/cc/client/client_session.h" #include "tensorflow/cc/ops/array_ops.h" #include "tensorflow/cc/ops/const_op.h" @@ -64,7 +63,7 @@ REGISTER_UNARY_VARIANT_DECODE_FUNCTION(KnownVecSize, "KNOWN VECTOR SIZE TYPE"); REGISTER_UNARY_VARIANT_SHAPE_FUNCTION(KnownVecSize, GetShapeFromKnownVecSize); -static void ExpectHasError(const Status& s, absl::string_view substr) { +static void ExpectHasError(const Status& s, StringPiece substr) { EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << ">>" << s << "<<, expected substring >>" << substr << "<<"; } diff --git a/tensorflow/core/kernels/sparse_cross_op.cc b/tensorflow/core/kernels/sparse_cross_op.cc index 644a75501ff..4ebb7fbcc70 100644 --- a/tensorflow/core/kernels/sparse_cross_op.cc +++ b/tensorflow/core/kernels/sparse_cross_op.cc @@ -19,7 +19,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_def_builder.h" @@ -27,6 +26,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/types.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/fingerprint.h" #include "tensorflow/core/util/work_sharder.h" @@ -92,8 +92,8 @@ string SparseTensorColumn<string>::Feature(int64 batch, int64 n) const { } template <> -absl::string_view SparseTensorColumn<absl::string_view>::Feature( - int64 batch, int64 n) const { +StringPiece SparseTensorColumn<StringPiece>::Feature(int64 batch, + int64 n) const { const int64 start = feature_start_indices_[batch]; return values_.vec<string>().data()[start + n]; } @@ -130,8 +130,8 @@ string DenseTensorColumn<string>::Feature(int64 batch, int64 n) const { } template <> -absl::string_view DenseTensorColumn<absl::string_view>::Feature(int64 batch, - int64 n) const { +StringPiece DenseTensorColumn<StringPiece>::Feature(int64 batch, + int64 n) const { return tensor_.matrix<string>()(batch, n); } diff --git a/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc b/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc index 7098983fdef..29577ebb4ed 100644 --- a/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc +++ b/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/kernel_benchmark_testlib.h" #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/fake_input.h" @@ -33,7 +32,7 @@ namespace tensorflow { namespace { -static void ExpectHasSubstr(absl::string_view s, absl::string_view expected) { +static void ExpectHasSubstr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/core/kernels/sparse_reduce_op.cc b/tensorflow/core/kernels/sparse_reduce_op.cc index 0908979fa26..a465564739f 100644 --- a/tensorflow/core/kernels/sparse_reduce_op.cc +++ b/tensorflow/core/kernels/sparse_reduce_op.cc @@ -15,7 +15,6 @@ limitations under the License. // See docs in ../ops/sparse_ops.cc. -#include "absl/strings/string_view.h" #define EIGEN_USE_THREADS #include "tensorflow/core/framework/op_kernel.h" @@ -136,7 +135,7 @@ struct SumOp { static void Run(OpKernelContext *ctx, typename TTypes<T>::Scalar &s, const typename TTypes<T>::UnalignedVec &v) { s.device(ctx->eigen_cpu_device()) = v.sum(); } - static absl::string_view Name() { + static StringPiece Name() { return "sum"; } }; @@ -146,7 +145,7 @@ struct MaxOp { static void Run(OpKernelContext *ctx, typename TTypes<T>::Scalar &s, const typename TTypes<T>::UnalignedVec &v) { s.device(ctx->eigen_cpu_device()) = v.maximum(); } - static absl::string_view Name() { + static StringPiece Name() { return "max"; } }; diff --git a/tensorflow/core/kernels/spectrogram_test_utils.cc b/tensorflow/core/kernels/spectrogram_test_utils.cc index 227f225d900..872a6e9d1bc 100644 --- a/tensorflow/core/kernels/spectrogram_test_utils.cc +++ b/tensorflow/core/kernels/spectrogram_test_utils.cc @@ -18,7 +18,6 @@ limitations under the License. #include <math.h> #include <stddef.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -176,9 +175,8 @@ bool WriteDoubleVectorToFile(const string& file_name, return false; } for (int i = 0; i < data.size(); ++i) { - if (!file - ->Append(absl::string_view( - reinterpret_cast<const char*>(&(data[i])), sizeof(data[i]))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&(data[i])), + sizeof(data[i]))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; @@ -199,9 +197,8 @@ bool WriteFloatVectorToFile(const string& file_name, return false; } for (int i = 0; i < data.size(); ++i) { - if (!file - ->Append(absl::string_view( - reinterpret_cast<const char*>(&(data[i])), sizeof(data[i]))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&(data[i])), + sizeof(data[i]))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; @@ -222,9 +219,8 @@ bool WriteDoubleArrayToFile(const string& file_name, int size, return false; } for (int i = 0; i < size; ++i) { - if (!file - ->Append(absl::string_view( - reinterpret_cast<const char*>(&(data[i])), sizeof(data[i]))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&(data[i])), + sizeof(data[i]))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; @@ -245,9 +241,8 @@ bool WriteFloatArrayToFile(const string& file_name, int size, return false; } for (int i = 0; i < size; ++i) { - if (!file - ->Append(absl::string_view( - reinterpret_cast<const char*>(&(data[i])), sizeof(data[i]))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&(data[i])), + sizeof(data[i]))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; @@ -271,18 +266,16 @@ bool WriteComplexVectorToRawFloatFile( for (int i = 0; i < data.size(); ++i) { for (int j = 0; j < data[i].size(); ++j) { const float real_part(real(data[i][j])); - if (!file->Append( - absl::string_view(reinterpret_cast<const char*>(&real_part), - sizeof(real_part))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&real_part), + sizeof(real_part))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; } const float imag_part(imag(data[i][j])); - if (!file->Append( - absl::string_view(reinterpret_cast<const char*>(&imag_part), - sizeof(imag_part))) + if (!file->Append(StringPiece(reinterpret_cast<const char*>(&imag_part), + sizeof(imag_part))) .ok()) { LOG(ERROR) << "Failed to append to file " << file_name; return false; diff --git a/tensorflow/core/kernels/string_join_op.cc b/tensorflow/core/kernels/string_join_op.cc index 3cbb4c7249a..28cca9f4484 100644 --- a/tensorflow/core/kernels/string_join_op.cc +++ b/tensorflow/core/kernels/string_join_op.cc @@ -17,7 +17,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" @@ -63,7 +62,7 @@ class StringJoinOp : public OpKernel { &output_tensor)); auto output_flat = output_tensor->flat<string>(); - std::vector<absl::string_view> strings(input_list.size()); + std::vector<StringPiece> strings(input_list.size()); for (size_t i = 0; i < input_shape.num_elements(); ++i) { for (int j = 0; j < input_list.size(); ++j) { strings[j] = (is_scalar[j]) ? inputs[j](0) : inputs[j](i); diff --git a/tensorflow/core/kernels/string_split_op.cc b/tensorflow/core/kernels/string_split_op.cc index 82ac01caea7..3884370a6c6 100644 --- a/tensorflow/core/kernels/string_split_op.cc +++ b/tensorflow/core/kernels/string_split_op.cc @@ -17,12 +17,12 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -36,11 +36,11 @@ namespace { template <typename Predicate> std::vector<StringPiece> SplitOnChar(const string& str, const char delim, Predicate p) { - std::vector<absl::string_view> result; - absl::string_view text(str); + std::vector<StringPiece> result; + StringPiece text(str); auto f = text.find(delim); - while (f != absl::string_view::npos) { - absl::string_view token = text.substr(0, f); + while (f != StringPiece::npos) { + StringPiece token = text.substr(0, f); if (p(token)) { result.emplace_back(token); } @@ -60,14 +60,13 @@ std::vector<StringPiece> SplitOnChar(const string& str, const char delim, template <typename Predicate> std::vector<StringPiece> SplitOnCharSet(const string& str, const string& delim_set, Predicate p) { - std::vector<absl::string_view> result; - absl::string_view text(str); - absl::string_view delims(delim_set); + std::vector<StringPiece> result; + StringPiece text(str); + StringPiece delims(delim_set); size_t token_start = 0; for (size_t i = 0; i < text.size() + 1; i++) { - if ((i == text.size()) || - (delims.find(text[i]) != absl::string_view::npos)) { - absl::string_view token(text.data() + token_start, i - token_start); + if ((i == text.size()) || (delims.find(text[i]) != StringPiece::npos)) { + StringPiece token(text.data() + token_start, i - token_start); if (p(token)) { result.emplace_back(token); } @@ -84,13 +83,13 @@ template <typename Predicate> std::vector<StringPiece> Split(const string& str, const string& delimiter, Predicate predicate) { if (str.empty()) { - return std::vector<absl::string_view>(); + return std::vector<StringPiece>(); } if (delimiter.empty()) { - std::vector<absl::string_view> result; + std::vector<StringPiece> result; result.resize(str.size()); for (size_t i = 0; i < str.size(); ++i) { - result[i] = absl::string_view(str.data() + i, 1); + result[i] = StringPiece(str.data() + i, 1); } return result; } @@ -100,8 +99,8 @@ std::vector<StringPiece> Split(const string& str, const string& delimiter, return SplitOnCharSet(str, delimiter, predicate); } -std::vector<absl::string_view> SplitV2(const string& str, absl::string_view sep, - int maxsplit) { +std::vector<StringPiece> SplitV2(const string& str, StringPiece sep, + int maxsplit) { // This SplitV2 method matches the behavior of python's str.split: // If sep is given, consecutive delimiters are not grouped together // and are deemed to delimit empty strings (for example, '1,,2'.split(',') @@ -116,16 +115,16 @@ std::vector<absl::string_view> SplitV2(const string& str, absl::string_view sep, // splitting an empty string or a string consisting of just whitespace // with a None separator returns []. - std::vector<absl::string_view> result; + std::vector<StringPiece> result; - absl::string_view text(str); + StringPiece text(str); if (maxsplit == 0) { result.emplace_back(text); return result; } if (sep.empty()) { - absl::string_view token; + StringPiece token; // Remove leading whitespaces. str_util::RemoveLeadingWhitespace(&text); int split = 0; @@ -143,13 +142,13 @@ std::vector<absl::string_view> SplitV2(const string& str, absl::string_view sep, auto p = std::search(text.begin(), text.end(), sep.begin(), sep.end()); int split = 0; while (p != text.end()) { - absl::string_view token = text.substr(0, p - text.begin()); + StringPiece token = text.substr(0, p - text.begin()); result.push_back(token); text.remove_prefix(token.size()); text.remove_prefix(sep.size()); ++split; if (maxsplit > 0 && split == maxsplit) { - result.push_back(absl::string_view(text)); + result.push_back(StringPiece(text)); return result; } p = std::search(text.begin(), text.end(), sep.begin(), sep.end()); @@ -191,7 +190,7 @@ class StringSplitOp : public OpKernel { const auto delimiter_vec = delimiter_tensor->flat<string>(); const string& delimiter = delimiter_vec(0); // Empty delimiter means split the input character by character. - std::vector<absl::string_view> tokens; + std::vector<StringPiece> tokens; // Guess that we'll be unpacking a handful of tokens per example. static constexpr int kReserveSize = 4; tokens.reserve(batch_size * kReserveSize); @@ -200,7 +199,7 @@ class StringSplitOp : public OpKernel { int64 max_num_entries = 0; std::vector<int64> num_indices(batch_size); for (int64 i = 0; i < batch_size; ++i) { - std::vector<absl::string_view> parts = + std::vector<StringPiece> parts = skip_empty_ ? Split(input_vec(i), delimiter, str_util::SkipEmpty()) : Split(input_vec(i), delimiter, str_util::AllowEmpty()); int64 n_entries = parts.size(); @@ -263,8 +262,8 @@ class StringSplitV2Op : public OpKernel { errors::InvalidArgument("sep must be a scalar, got shape: ", sep_tensor->shape().DebugString())); const auto sep_vec = sep_tensor->flat<string>(); - absl::string_view sep(sep_vec(0)); - std::vector<absl::string_view> tokens; + StringPiece sep(sep_vec(0)); + std::vector<StringPiece> tokens; // Guess that we'll be unpacking a handful of tokens per example. static constexpr int kReserveSize = 4; tokens.reserve(batch_size * kReserveSize); @@ -273,8 +272,7 @@ class StringSplitV2Op : public OpKernel { int64 max_num_entries = 0; std::vector<int64> num_indices(batch_size); for (int64 i = 0; i < batch_size; ++i) { - std::vector<absl::string_view> parts = - SplitV2(input_vec(i), sep, maxsplit_); + std::vector<StringPiece> parts = SplitV2(input_vec(i), sep, maxsplit_); int64 n_entries = parts.size(); num_indices[i] = n_entries; output_size += n_entries; diff --git a/tensorflow/core/kernels/string_strip_op.cc b/tensorflow/core/kernels/string_strip_op.cc index 8b7b0bd250b..544dca96ba7 100644 --- a/tensorflow/core/kernels/string_strip_op.cc +++ b/tensorflow/core/kernels/string_strip_op.cc @@ -17,7 +17,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" @@ -42,7 +41,7 @@ class StringStripOp : public OpKernel { auto output = output_tensor->flat<string>(); for (int64 i = 0; i < input.size(); ++i) { - absl::string_view entry(input(i)); + StringPiece entry(input(i)); str_util::RemoveWhitespaceContext(&entry); output(i) = string(entry); } diff --git a/tensorflow/core/kernels/string_to_hash_bucket_op.h b/tensorflow/core/kernels/string_to_hash_bucket_op.h index d2c13719e63..62ef35bbba4 100644 --- a/tensorflow/core/kernels/string_to_hash_bucket_op.h +++ b/tensorflow/core/kernels/string_to_hash_bucket_op.h @@ -18,7 +18,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/lib/core/errors.h" @@ -27,7 +26,7 @@ limitations under the License. namespace tensorflow { -template <uint64 hash(absl::string_view)> +template <uint64 hash(StringPiece)> class StringToHashBucketOp : public OpKernel { public: explicit StringToHashBucketOp(OpKernelConstruction* ctx) : OpKernel(ctx) { diff --git a/tensorflow/core/kernels/string_util.h b/tensorflow/core/kernels/string_util.h index 0af3449d8d4..d40e93ea334 100644 --- a/tensorflow/core/kernels/string_util.h +++ b/tensorflow/core/kernels/string_util.h @@ -15,7 +15,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_KERNELS_STRING_UTIL_H_ #define TENSORFLOW_CORE_KERNELS_STRING_UTIL_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" namespace tensorflow { @@ -50,7 +49,7 @@ int32 UTF8StrLen(const string& string); // the end of the string is reached before the requested characters, then the // position will point to the end of string and this function will return false. template <typename T> -bool ForwardNUTF8CharPositions(const absl::string_view in, +bool ForwardNUTF8CharPositions(const StringPiece in, const T num_utf8_chars_to_shift, T* pos) { const size_t size = in.size(); T utf8_chars_counted = 0; @@ -71,7 +70,7 @@ bool ForwardNUTF8CharPositions(const absl::string_view in, // the string is reached before the requested character, then the position will // point to the beginning of the string and this function will return false. template <typename T> -bool BackNUTF8CharPositions(const absl::string_view in, +bool BackNUTF8CharPositions(const StringPiece in, const T num_utf8_chars_to_shift, T* pos) { const size_t start = 0; T utf8_chars_counted = 0; diff --git a/tensorflow/core/kernels/substr_op.cc b/tensorflow/core/kernels/substr_op.cc index 030c2ff37cc..93c427039dd 100644 --- a/tensorflow/core/kernels/substr_op.cc +++ b/tensorflow/core/kernels/substr_op.cc @@ -17,7 +17,6 @@ limitations under the License. #include <cstdlib> #include <string> -#include "absl/strings/string_view.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/op.h" @@ -29,6 +28,7 @@ limitations under the License. #include "tensorflow/core/kernels/bounds_check.h" #include "tensorflow/core/kernels/string_util.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" #include "tensorflow/core/util/bcast.h" @@ -73,7 +73,7 @@ class SubstrOp : public OpKernel { const T len = tensorflow::internal::SubtleMustCopy(len_tensor.scalar<T>()()); for (size_t i = 0; i < input_tensor.NumElements(); ++i) { - absl::string_view in(input(i)); + StringPiece in(input(i)); T byte_pos = pos; T byte_len = len; switch (unit_) { @@ -90,7 +90,7 @@ class SubstrOp : public OpKernel { errors::InvalidArgument("pos ", pos, " out of range for ", "string b'", in, "' at index ", i)); } - absl::string_view sub_in = in.substr(byte_pos, byte_len); + StringPiece sub_in = in.substr(byte_pos, byte_len); output(i).assign(sub_in.data(), sub_in.size()); } } else { @@ -98,7 +98,7 @@ class SubstrOp : public OpKernel { auto pos_flat = pos_tensor.flat<T>(); auto len_flat = len_tensor.flat<T>(); for (size_t i = 0; i < input_tensor.NumElements(); ++i) { - absl::string_view in(input(i)); + StringPiece in(input(i)); const T pos = tensorflow::internal::SubtleMustCopy(pos_flat(i)); const T len = tensorflow::internal::SubtleMustCopy(len_flat(i)); T byte_pos = pos; @@ -117,7 +117,7 @@ class SubstrOp : public OpKernel { errors::InvalidArgument("pos ", pos, " out of range for ", "string b'", in, "' at index ", i)); } - absl::string_view sub_in = in.substr(byte_pos, byte_len); + StringPiece sub_in = in.substr(byte_pos, byte_len); output(i).assign(sub_in.data(), sub_in.size()); } } @@ -177,7 +177,7 @@ class SubstrOp : public OpKernel { // Iterate through broadcasted tensors and perform substr for (int i = 0; i < output_shape.dim_size(0); ++i) { - absl::string_view in(input_bcast(i)); + StringPiece in(input_bcast(i)); const T pos = tensorflow::internal::SubtleMustCopy(pos_bcast(i)); const T len = tensorflow::internal::SubtleMustCopy(len_bcast(i)); T byte_pos = pos; @@ -197,7 +197,7 @@ class SubstrOp : public OpKernel { errors::InvalidArgument("pos ", pos, " out of range for ", "string b'", in, "' at index ", i)); } - absl::string_view sub_in = in.substr(byte_pos, byte_len); + StringPiece sub_in = in.substr(byte_pos, byte_len); output(i).assign(sub_in.data(), sub_in.size()); } break; @@ -241,7 +241,7 @@ class SubstrOp : public OpKernel { // Iterate through broadcasted tensors and perform substr for (int i = 0; i < output_shape.dim_size(0); ++i) { for (int j = 0; j < output_shape.dim_size(1); ++j) { - absl::string_view in(input_bcast(i, j)); + StringPiece in(input_bcast(i, j)); const T pos = tensorflow::internal::SubtleMustCopy(pos_bcast(i, j)); const T len = @@ -263,7 +263,7 @@ class SubstrOp : public OpKernel { "string b'", in, "' at index (", i, ", ", j, ")")); } - absl::string_view sub_in = in.substr(byte_pos, byte_len); + StringPiece sub_in = in.substr(byte_pos, byte_len); output(i, j).assign(sub_in.data(), sub_in.size()); } } @@ -280,8 +280,7 @@ class SubstrOp : public OpKernel { private: // This adjusts the requested position. Note it does not perform any bound // checks. - static inline T AdjustedPosIndex(const T pos_requested, - const absl::string_view s) { + static inline T AdjustedPosIndex(const T pos_requested, const StringPiece s) { if (pos_requested < 0) { return s.size() + pos_requested; } @@ -290,7 +289,7 @@ class SubstrOp : public OpKernel { // Return true if successful; otherwise, return false if the `pos` argument // is out of range in the string. - static inline bool UpdatePosAndLenForUtf8(const absl::string_view in, T* pos, + static inline bool UpdatePosAndLenForUtf8(const StringPiece in, T* pos, T* len) { if (*pos >= 0) { return UpdatePositivePosAndLenForUtf8(in, *pos, *len, pos, len); @@ -299,9 +298,9 @@ class SubstrOp : public OpKernel { } } - static bool UpdatePositivePosAndLenForUtf8(const absl::string_view in, - const T pos, const T len, - T* char_pos, T* char_len) { + static bool UpdatePositivePosAndLenForUtf8(const StringPiece in, const T pos, + const T len, T* char_pos, + T* char_len) { *char_pos = 0; // Determine byte position of the substring start. if (!ForwardNUTF8CharPositions(in, pos, char_pos)) { @@ -320,9 +319,9 @@ class SubstrOp : public OpKernel { // This function expects a negative position relative to the end of the // string, but will update the character position to a positive number // relative to the beginning of the string. - static bool UpdateNegativePosAndLenForUtf8(const absl::string_view in, - const T pos, const T len, - T* char_pos, T* char_len) { + static bool UpdateNegativePosAndLenForUtf8(const StringPiece in, const T pos, + const T len, T* char_pos, + T* char_len) { // Initially treat the length as position of the end of the substring. *char_len = in.size(); // This is the number of character to skip from the end of the string to diff --git a/tensorflow/core/kernels/tensor_array_ops.cc b/tensorflow/core/kernels/tensor_array_ops.cc index 3bb8e50e76c..a97a71b344d 100644 --- a/tensorflow/core/kernels/tensor_array_ops.cc +++ b/tensorflow/core/kernels/tensor_array_ops.cc @@ -15,7 +15,6 @@ limitations under the License. // See docs in ../ops/data_flow_ops.cc. -#include "absl/strings/string_view.h" #define EIGEN_USE_THREADS #include <limits> @@ -293,13 +292,13 @@ class TensorArrayGradOp : public TensorArrayCreationOp { } else { container = "_tensor_arrays"; const auto& resource = ctx->input(0).flat<ResourceHandle>()(0); - if (absl::string_view(resource.name()).substr(0, container.size()) != + if (StringPiece(resource.name()).substr(0, container.size()) != container) { return errors::InvalidArgument("Wrong input container. ", resource.name()); } tensor_array_name = - string(absl::string_view(resource.name()).substr(container.size())); + string(StringPiece(resource.name()).substr(container.size())); } auto output_handle = tensor_array_output_handle->flat<string>(); diff --git a/tensorflow/core/kernels/word2vec_kernels.cc b/tensorflow/core/kernels/word2vec_kernels.cc index 10a3a368428..3477445197a 100644 --- a/tensorflow/core/kernels/word2vec_kernels.cc +++ b/tensorflow/core/kernels/word2vec_kernels.cc @@ -13,9 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_kernel.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/random/distribution_sampler.h" #include "tensorflow/core/lib/random/philox_random.h" @@ -33,9 +33,9 @@ const int kSentenceSize = 1000; namespace { -bool ScanWord(absl::string_view* input, string* word) { +bool ScanWord(StringPiece* input, string* word) { str_util::RemoveLeadingWhitespace(input); - absl::string_view tmp; + StringPiece tmp; if (str_util::ConsumeNonWhitespace(input, &tmp)) { word->assign(tmp.data(), tmp.size()); return true; @@ -179,7 +179,7 @@ class SkipgramOp : public OpKernel { Status Init(Env* env, const string& filename) { string data; TF_RETURN_IF_ERROR(ReadFileToString(env, filename, &data)); - absl::string_view input = data; + StringPiece input = data; string w; corpus_size_ = 0; std::unordered_map<string, int32> word_freq; diff --git a/tensorflow/core/lib/core/coding.cc b/tensorflow/core/lib/core/coding.cc index 60828d423a0..50872eef83a 100644 --- a/tensorflow/core/lib/core/coding.cc +++ b/tensorflow/core/lib/core/coding.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/core/coding.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/byte_order.h" namespace tensorflow { @@ -152,14 +151,14 @@ const char* GetVarint32PtrFallback(const char* p, const char* limit, return nullptr; } -bool GetVarint32(absl::string_view* input, uint32* value) { +bool GetVarint32(StringPiece* input, uint32* value) { const char* p = input->data(); const char* limit = p + input->size(); const char* q = GetVarint32Ptr(p, limit, value); if (q == nullptr) { return false; } else { - *input = absl::string_view(q, limit - q); + *input = StringPiece(q, limit - q); return true; } } @@ -181,14 +180,14 @@ const char* GetVarint64Ptr(const char* p, const char* limit, uint64* value) { return nullptr; } -bool GetVarint64(absl::string_view* input, uint64* value) { +bool GetVarint64(StringPiece* input, uint64* value) { const char* p = input->data(); const char* limit = p + input->size(); const char* q = GetVarint64Ptr(p, limit, value); if (q == nullptr) { return false; } else { - *input = absl::string_view(q, limit - q); + *input = StringPiece(q, limit - q); return true; } } diff --git a/tensorflow/core/lib/core/coding.h b/tensorflow/core/lib/core/coding.h index 9add2b1afcc..4a70ffa6190 100644 --- a/tensorflow/core/lib/core/coding.h +++ b/tensorflow/core/lib/core/coding.h @@ -21,8 +21,8 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_CORE_CODING_H_ #define TENSORFLOW_CORE_LIB_CORE_CODING_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/raw_coding.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -46,8 +46,8 @@ extern void PutFixed64(string* dst, uint64 value); extern void PutVarint32(string* dst, uint32 value); extern void PutVarint64(string* dst, uint64 value); -extern bool GetVarint32(absl::string_view* input, uint32* value); -extern bool GetVarint64(absl::string_view* input, uint64* value); +extern bool GetVarint32(StringPiece* input, uint32* value); +extern bool GetVarint64(StringPiece* input, uint64* value); extern const char* GetVarint32Ptr(const char* p, const char* limit, uint32* v); extern const char* GetVarint64Ptr(const char* p, const char* limit, uint64* v); diff --git a/tensorflow/core/lib/core/status.cc b/tensorflow/core/lib/core/status.cc index f21600328ba..cb2a06e620c 100644 --- a/tensorflow/core/lib/core/status.cc +++ b/tensorflow/core/lib/core/status.cc @@ -15,11 +15,10 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include <stdio.h> -#include "absl/strings/string_view.h" namespace tensorflow { -Status::Status(tensorflow::error::Code code, absl::string_view msg) { +Status::Status(tensorflow::error::Code code, StringPiece msg) { assert(code != tensorflow::error::OK); state_ = std::unique_ptr<State>(new State); state_->code = code; diff --git a/tensorflow/core/lib/core/status.h b/tensorflow/core/lib/core/status.h index 4227a8e11b7..eb0ff555a5f 100644 --- a/tensorflow/core/lib/core/status.h +++ b/tensorflow/core/lib/core/status.h @@ -20,8 +20,8 @@ limitations under the License. #include <iosfwd> #include <memory> #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/error_codes.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/types.h" @@ -42,7 +42,7 @@ class Status { /// \brief Create a status with the specified error code and msg as a /// human-readable string containing more detailed information. - Status(tensorflow::error::Code code, absl::string_view msg); + Status(tensorflow::error::Code code, tensorflow::StringPiece msg); /// Copy the specified status. Status(const Status& s); diff --git a/tensorflow/core/lib/core/stringpiece_test.cc b/tensorflow/core/lib/core/stringpiece_test.cc index 420ae677080..e4b489fe17f 100644 --- a/tensorflow/core/lib/core/stringpiece_test.cc +++ b/tensorflow/core/lib/core/stringpiece_test.cc @@ -13,8 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include "tensorflow/core/lib/core/stringpiece.h" + #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -23,24 +24,24 @@ TEST(StringPiece, Ctor) { { // const char* without size. const char* hello = "hello"; - absl::string_view s20(hello); + StringPiece s20(hello); EXPECT_TRUE(s20.data() == hello); EXPECT_EQ(5, s20.size()); // const char* with size. - absl::string_view s21(hello, 4); + StringPiece s21(hello, 4); EXPECT_TRUE(s21.data() == hello); EXPECT_EQ(4, s21.size()); // Not recommended, but valid C++ - absl::string_view s22(hello, 6); + StringPiece s22(hello, 6); EXPECT_TRUE(s22.data() == hello); EXPECT_EQ(6, s22.size()); } { string hola = "hola"; - absl::string_view s30(hola); + StringPiece s30(hola); EXPECT_TRUE(s30.data() == hola.data()); EXPECT_EQ(4, s30.size()); @@ -48,15 +49,15 @@ TEST(StringPiece, Ctor) { hola.push_back('\0'); hola.append("h2"); hola.push_back('\0'); - absl::string_view s31(hola); + StringPiece s31(hola); EXPECT_TRUE(s31.data() == hola.data()); EXPECT_EQ(8, s31.size()); } } TEST(StringPiece, ConversionToString) { - EXPECT_EQ("", string(absl::string_view(""))); - EXPECT_EQ("foo", string(absl::string_view("foo"))); + EXPECT_EQ("", string(StringPiece(""))); + EXPECT_EQ("foo", string(StringPiece("foo"))); } } // namespace tensorflow diff --git a/tensorflow/core/lib/db/BUILD b/tensorflow/core/lib/db/BUILD index efba522005d..7a64306c6e9 100644 --- a/tensorflow/core/lib/db/BUILD +++ b/tensorflow/core/lib/db/BUILD @@ -16,7 +16,6 @@ cc_library( ":snapfn", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", "@org_sqlite", ], ) @@ -42,6 +41,5 @@ tf_cc_test( "//tensorflow/core:lib", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/lib/db/sqlite.cc b/tensorflow/core/lib/db/sqlite.cc index 83c419988f2..cf11f3a331e 100644 --- a/tensorflow/core/lib/db/sqlite.cc +++ b/tensorflow/core/lib/db/sqlite.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/db/sqlite.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/stringprintf.h" @@ -82,8 +81,7 @@ sqlite3_stmt* PrepareRawOrDie(sqlite3* db, const char* sql) { return stmt; } -Status SetPragma(Sqlite* db, const char* pragma, - const absl::string_view& value) { +Status SetPragma(Sqlite* db, const char* pragma, const StringPiece& value) { if (value.empty()) return Status::OK(); for (auto p = value.begin(); p < value.end(); ++p) { if (!(('0' <= *p && *p <= '9') || ('A' <= *p && *p <= 'Z') || @@ -98,9 +96,9 @@ Status SetPragma(Sqlite* db, const char* pragma, return stmt.Step(&unused_done); } -const absl::string_view GetEnv(const char* var) { +const StringPiece GetEnv(const char* var) { const char* val = std::getenv(var); - return (val == nullptr) ? absl::string_view() : absl::string_view(val); + return (val == nullptr) ? StringPiece() : StringPiece(val); } Status EnvPragma(Sqlite* db, const char* pragma, const char* var) { @@ -162,7 +160,7 @@ Sqlite::~Sqlite() { CHECK_EQ(SQLITE_OK, sqlite3_close(db_)); } -Status Sqlite::Prepare(const absl::string_view& sql, SqliteStatement* stmt) { +Status Sqlite::Prepare(const StringPiece& sql, SqliteStatement* stmt) { SqliteLock lock(*this); sqlite3_stmt* ps = nullptr; int rc = sqlite3_prepare_v2(db_, sql.data(), static_cast<int>(sql.size()), diff --git a/tensorflow/core/lib/db/sqlite.h b/tensorflow/core/lib/db/sqlite.h index d54a5f7ed28..efe97f78d25 100644 --- a/tensorflow/core/lib/db/sqlite.h +++ b/tensorflow/core/lib/db/sqlite.h @@ -17,10 +17,10 @@ limitations under the License. #include <mutex> -#include "absl/strings/string_view.h" #include "sqlite3.h" #include "tensorflow/core/lib/core/refcount.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/thread_annotations.h" #include "tensorflow/core/platform/types.h" @@ -87,8 +87,8 @@ class LOCKABLE Sqlite : public core::RefCounted { /// routine will retry automatically and then possibly fail. /// /// The returned statement holds a reference to this object. - Status Prepare(const absl::string_view& sql, SqliteStatement* stmt); - SqliteStatement PrepareOrDie(const absl::string_view& sql); + Status Prepare(const StringPiece& sql, SqliteStatement* stmt); + SqliteStatement PrepareOrDie(const StringPiece& sql); /// \brief Returns extended result code of last error. /// @@ -228,22 +228,22 @@ class SqliteStatement { /// /// When using the unsafe methods, the data must not be changed or /// freed until this statement is Reset() or finalized. - void BindText(int parameter, const absl::string_view& text) { + void BindText(int parameter, const StringPiece& text) { Update(sqlite3_bind_text64(stmt_, parameter, text.data(), text.size(), SQLITE_TRANSIENT, SQLITE_UTF8), parameter); size_ += text.size(); } - void BindText(const char* parameter, const absl::string_view& text) { + void BindText(const char* parameter, const StringPiece& text) { BindText(GetParameterIndex(parameter), text); } - void BindTextUnsafe(int parameter, const absl::string_view& text) { + void BindTextUnsafe(int parameter, const StringPiece& text) { Update(sqlite3_bind_text64(stmt_, parameter, text.data(), text.size(), SQLITE_STATIC, SQLITE_UTF8), parameter); size_ += text.size(); } - void BindTextUnsafe(const char* parameter, const absl::string_view& text) { + void BindTextUnsafe(const char* parameter, const StringPiece& text) { BindTextUnsafe(GetParameterIndex(parameter), text); } @@ -251,22 +251,22 @@ class SqliteStatement { /// /// When using the unsafe methods, the data must not be changed or /// freed until this statement is Reset() or finalized. - void BindBlob(int parameter, const absl::string_view& blob) { + void BindBlob(int parameter, const StringPiece& blob) { Update(sqlite3_bind_blob64(stmt_, parameter, blob.data(), blob.size(), SQLITE_TRANSIENT), parameter); size_ += blob.size(); } - void BindBlob(const char* parameter, const absl::string_view& blob) { + void BindBlob(const char* parameter, const StringPiece& blob) { BindBlob(GetParameterIndex(parameter), blob); } - void BindBlobUnsafe(int parameter, const absl::string_view& blob) { + void BindBlobUnsafe(int parameter, const StringPiece& blob) { Update(sqlite3_bind_blob64(stmt_, parameter, blob.data(), blob.size(), SQLITE_STATIC), parameter); size_ += blob.size(); } - void BindBlobUnsafe(const char* parameter, const absl::string_view& text) { + void BindBlobUnsafe(const char* parameter, const StringPiece& text) { BindBlobUnsafe(GetParameterIndex(parameter), text); } @@ -309,7 +309,7 @@ class SqliteStatement { /// Empty values are returned as NULL. The returned memory will no /// longer be valid the next time Step() or Reset() is called. No NUL /// terminator is added. - absl::string_view ColumnStringUnsafe(int column) const TF_MUST_USE_RESULT { + StringPiece ColumnStringUnsafe(int column) const TF_MUST_USE_RESULT { return {static_cast<const char*>(sqlite3_column_blob(stmt_, column)), static_cast<size_t>(ColumnSize(column))}; } @@ -438,7 +438,7 @@ class SCOPED_LOCKABLE SqliteTransaction { EXCLUSIVE_LOCKS_REQUIRED(__VA_ARGS__) #define SQLITE_TRANSACTIONS_EXCLUDED(...) LOCKS_EXCLUDED(__VA_ARGS__) -inline SqliteStatement Sqlite::PrepareOrDie(const absl::string_view& sql) { +inline SqliteStatement Sqlite::PrepareOrDie(const StringPiece& sql) { SqliteStatement stmt; TF_CHECK_OK(Prepare(sql, &stmt)); return stmt; diff --git a/tensorflow/core/lib/db/sqlite_test.cc b/tensorflow/core/lib/db/sqlite_test.cc index 2826fe73c85..15900559601 100644 --- a/tensorflow/core/lib/db/sqlite_test.cc +++ b/tensorflow/core/lib/db/sqlite_test.cc @@ -17,8 +17,8 @@ limitations under the License. #include <array> #include <climits> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/test.h" @@ -169,7 +169,7 @@ TEST_F(SqliteTest, UnsafeColumn) { TF_ASSERT_OK(stmt.StepAndReset()); stmt = db_->PrepareOrDie("SELECT b FROM T ORDER BY a"); TF_ASSERT_OK(stmt.Step(&is_done_)); - absl::string_view p = stmt.ColumnStringUnsafe(0); + StringPiece p = stmt.ColumnStringUnsafe(0); EXPECT_EQ('h', *p.data()); TF_ASSERT_OK(stmt.Step(&is_done_)); // This will actually happen, but it's not safe to test this behavior. diff --git a/tensorflow/core/lib/hash/hash.h b/tensorflow/core/lib/hash/hash.h index 8560f517ddf..675bab71919 100644 --- a/tensorflow/core/lib/hash/hash.h +++ b/tensorflow/core/lib/hash/hash.h @@ -24,7 +24,7 @@ limitations under the License. #include <functional> #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -94,12 +94,12 @@ struct hash<string> { }; template <> -struct hash<absl::string_view> { - size_t operator()(absl::string_view sp) const { +struct hash<StringPiece> { + size_t operator()(StringPiece sp) const { return static_cast<size_t>(Hash64(sp.data(), sp.size())); } }; -using StringPieceHasher = ::tensorflow::hash<absl::string_view>; +using StringPieceHasher = ::tensorflow::hash<StringPiece>; template <typename T, typename U> struct hash<std::pair<T, U>> { diff --git a/tensorflow/core/lib/hash/hash_test.cc b/tensorflow/core/lib/hash/hash_test.cc index 3223ef81fe2..7d583131322 100644 --- a/tensorflow/core/lib/hash/hash_test.cc +++ b/tensorflow/core/lib/hash/hash_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" @@ -87,10 +86,10 @@ BENCHMARK(BM_Hash32)->Range(1, 1024); TEST(StringPieceHasher, Equality) { StringPieceHasher hasher; - absl::string_view s1("foo"); - absl::string_view s2("bar"); - absl::string_view s3("baz"); - absl::string_view s4("zot"); + StringPiece s1("foo"); + StringPiece s2("bar"); + StringPiece s3("baz"); + StringPiece s4("zot"); EXPECT_TRUE(hasher(s1) != hasher(s2)); EXPECT_TRUE(hasher(s1) != hasher(s3)); @@ -110,11 +109,11 @@ TEST(StringPieceHasher, HashMap) { string s2("bar"); string s3("baz"); - absl::string_view p1(s1); - absl::string_view p2(s2); - absl::string_view p3(s3); + StringPiece p1(s1); + StringPiece p2(s2); + StringPiece p3(s3); - std::unordered_map<absl::string_view, int, StringPieceHasher> map; + std::unordered_map<StringPiece, int, StringPieceHasher> map; map.insert(std::make_pair(p1, 0)); map.insert(std::make_pair(p2, 1)); diff --git a/tensorflow/core/lib/io/block.cc b/tensorflow/core/lib/io/block.cc index 3e4ce3c08bb..4c30486cc49 100644 --- a/tensorflow/core/lib/io/block.cc +++ b/tensorflow/core/lib/io/block.cc @@ -18,7 +18,6 @@ limitations under the License. #include "tensorflow/core/lib/io/block.h" #include <algorithm> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/io/format.h" @@ -96,11 +95,10 @@ class Block::Iter : public Iterator { uint32 current_; uint32 restart_index_; // Index of restart block in which current_ falls string key_; - absl::string_view value_; + StringPiece value_; Status status_; - inline int Compare(const absl::string_view& a, - const absl::string_view& b) const { + inline int Compare(const StringPiece& a, const StringPiece& b) const { return a.compare(b); } @@ -121,7 +119,7 @@ class Block::Iter : public Iterator { // ParseNextKey() starts at the end of value_, so set value_ accordingly uint32 offset = GetRestartPoint(index); - value_ = absl::string_view(data_ + offset, 0); + value_ = StringPiece(data_ + offset, 0); } public: @@ -136,11 +134,11 @@ class Block::Iter : public Iterator { bool Valid() const override { return current_ < restarts_; } Status status() const override { return status_; } - absl::string_view key() const override { + StringPiece key() const override { assert(Valid()); return key_; } - absl::string_view value() const override { + StringPiece value() const override { assert(Valid()); return value_; } @@ -150,7 +148,7 @@ class Block::Iter : public Iterator { ParseNextKey(); } - void Seek(const absl::string_view& target) override { + void Seek(const StringPiece& target) override { // Binary search in restart array to find the last restart point // with a key < target uint32 left = 0; @@ -166,7 +164,7 @@ class Block::Iter : public Iterator { CorruptionError(); return; } - absl::string_view mid_key(key_ptr, non_shared); + StringPiece mid_key(key_ptr, non_shared); if (Compare(mid_key, target) < 0) { // Key at "mid" is smaller than "target". Therefore all // blocks before "mid" are uninteresting. @@ -201,7 +199,7 @@ class Block::Iter : public Iterator { restart_index_ = num_restarts_; status_ = errors::DataLoss("bad entry in block"); key_.clear(); - value_ = absl::string_view(); + value_ = StringPiece(); } bool ParseNextKey() { @@ -224,7 +222,7 @@ class Block::Iter : public Iterator { } else { key_.resize(shared); key_.append(p, non_shared); - value_ = absl::string_view(p + non_shared, value_length); + value_ = StringPiece(p + non_shared, value_length); while (restart_index_ + 1 < num_restarts_ && GetRestartPoint(restart_index_ + 1) < current_) { ++restart_index_; diff --git a/tensorflow/core/lib/io/block_builder.cc b/tensorflow/core/lib/io/block_builder.cc index 44e564bf58a..b2921c076cc 100644 --- a/tensorflow/core/lib/io/block_builder.cc +++ b/tensorflow/core/lib/io/block_builder.cc @@ -41,7 +41,6 @@ limitations under the License. #include <assert.h> #include <algorithm> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/io/table_builder.h" @@ -69,7 +68,7 @@ size_t BlockBuilder::CurrentSizeEstimate() const { sizeof(uint32)); // Restart array length } -absl::string_view BlockBuilder::Finish() { +StringPiece BlockBuilder::Finish() { // Append restart array CHECK_LE(restarts_.size(), std::numeric_limits<uint32_t>::max()); for (const auto r : restarts_) { @@ -78,12 +77,11 @@ absl::string_view BlockBuilder::Finish() { // Downcast safe because of the CHECK. core::PutFixed32(&buffer_, static_cast<uint32_t>(restarts_.size())); finished_ = true; - return absl::string_view(buffer_); + return StringPiece(buffer_); } -void BlockBuilder::Add(const absl::string_view& key, - const absl::string_view& value) { - absl::string_view last_key_piece(last_key_); +void BlockBuilder::Add(const StringPiece& key, const StringPiece& value) { + StringPiece last_key_piece(last_key_); assert(!finished_); assert(counter_ <= options_->block_restart_interval); assert(buffer_.empty() // No values yet? @@ -119,7 +117,7 @@ void BlockBuilder::Add(const absl::string_view& key, // Update state last_key_.resize(shared); last_key_.append(key.data() + shared, non_shared); - assert(absl::string_view(last_key_) == key); + assert(StringPiece(last_key_) == key); counter_++; } diff --git a/tensorflow/core/lib/io/block_builder.h b/tensorflow/core/lib/io/block_builder.h index 1237f7fb7fb..117b6a0bb8f 100644 --- a/tensorflow/core/lib/io/block_builder.h +++ b/tensorflow/core/lib/io/block_builder.h @@ -19,7 +19,7 @@ limitations under the License. #include <vector> #include <stdint.h> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -36,12 +36,12 @@ class BlockBuilder { // REQUIRES: Finish() has not been called since the last call to Reset(). // REQUIRES: key is larger than any previously added key - void Add(const absl::string_view& key, const absl::string_view& value); + void Add(const StringPiece& key, const StringPiece& value); // Finish building the block and return a slice that refers to the // block contents. The returned slice will remain valid for the // lifetime of this builder or until Reset() is called. - absl::string_view Finish(); + StringPiece Finish(); // Returns an estimate of the current (uncompressed) size of the block // we are building. diff --git a/tensorflow/core/lib/io/format.cc b/tensorflow/core/lib/io/format.cc index 81c9d59d4af..0c24c660a24 100644 --- a/tensorflow/core/lib/io/format.cc +++ b/tensorflow/core/lib/io/format.cc @@ -15,7 +15,6 @@ limitations under the License. #include <limits> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/format.h" #include "tensorflow/core/lib/core/coding.h" @@ -36,7 +35,7 @@ void BlockHandle::EncodeTo(string* dst) const { core::PutVarint64(dst, size_); } -Status BlockHandle::DecodeFrom(absl::string_view* input) { +Status BlockHandle::DecodeFrom(StringPiece* input) { if (core::GetVarint64(input, &offset_) && core::GetVarint64(input, &size_)) { return Status::OK(); } else { @@ -56,7 +55,7 @@ void Footer::EncodeTo(string* dst) const { assert(dst->size() == original_size + kEncodedLength); } -Status Footer::DecodeFrom(absl::string_view* input) { +Status Footer::DecodeFrom(StringPiece* input) { const char* magic_ptr = input->data() + kEncodedLength - 8; const uint32 magic_lo = core::DecodeFixed32(magic_ptr); const uint32 magic_hi = core::DecodeFixed32(magic_ptr + 4); @@ -73,14 +72,14 @@ Status Footer::DecodeFrom(absl::string_view* input) { if (result.ok()) { // We skip over any leftover data (just padding for now) in "input" const char* end = magic_ptr + 8; - *input = absl::string_view(end, input->data() + input->size() - end); + *input = StringPiece(end, input->data() + input->size() - end); } return result; } Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle, BlockContents* result) { - result->data = absl::string_view(); + result->data = StringPiece(); result->cachable = false; result->heap_allocated = false; @@ -93,7 +92,7 @@ Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle, } char* buf = new char[n + kBlockTrailerSize]; - absl::string_view contents; + StringPiece contents; Status s = file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf); if (!s.ok()) { delete[] buf; @@ -125,11 +124,11 @@ Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle, // Use it directly under the assumption that it will be live // while the file is open. delete[] buf; - result->data = absl::string_view(data, n); + result->data = StringPiece(data, n); result->heap_allocated = false; result->cachable = false; // Do not double-cache } else { - result->data = absl::string_view(buf, n); + result->data = StringPiece(buf, n); result->heap_allocated = true; result->cachable = true; } @@ -149,7 +148,7 @@ Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle, return errors::DataLoss("corrupted compressed block contents"); } delete[] buf; - result->data = absl::string_view(ubuf, ulength); + result->data = StringPiece(ubuf, ulength); result->heap_allocated = true; result->cachable = true; break; diff --git a/tensorflow/core/lib/io/format.h b/tensorflow/core/lib/io/format.h index 96a92f1209b..fd5c3470f6a 100644 --- a/tensorflow/core/lib/io/format.h +++ b/tensorflow/core/lib/io/format.h @@ -18,8 +18,8 @@ limitations under the License. #include <stdint.h> #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/table_builder.h" namespace tensorflow { @@ -43,7 +43,7 @@ class BlockHandle { void set_size(uint64 size) { size_ = size; } void EncodeTo(string* dst) const; - Status DecodeFrom(absl::string_view* input); + Status DecodeFrom(StringPiece* input); // Maximum encoding length of a BlockHandle enum { kMaxEncodedLength = 10 + 10 }; @@ -68,7 +68,7 @@ class Footer { void set_index_handle(const BlockHandle& h) { index_handle_ = h; } void EncodeTo(string* dst) const; - Status DecodeFrom(absl::string_view* input); + Status DecodeFrom(StringPiece* input); // Encoded length of a Footer. Note that the serialization of a // Footer will always occupy exactly this many bytes. It consists @@ -89,7 +89,7 @@ static const uint64 kTableMagicNumber = 0xdb4775248b80fb57ull; static const size_t kBlockTrailerSize = 5; struct BlockContents { - absl::string_view data; // Actual contents of data + StringPiece data; // Actual contents of data bool cachable; // True iff data can be cached bool heap_allocated; // True iff caller should delete[] data.data() }; diff --git a/tensorflow/core/lib/io/inputbuffer.cc b/tensorflow/core/lib/io/inputbuffer.cc index a12cf97a9ca..4d35af49b2c 100644 --- a/tensorflow/core/lib/io/inputbuffer.cc +++ b/tensorflow/core/lib/io/inputbuffer.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/io/inputbuffer.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/platform/logging.h" @@ -32,7 +31,7 @@ InputBuffer::InputBuffer(RandomAccessFile* file, size_t buffer_bytes) InputBuffer::~InputBuffer() { delete[] buf_; } Status InputBuffer::FillBuffer() { - absl::string_view data; + StringPiece data; Status s = file_->Read(file_pos_, size_, &data, buf_); if (data.data() != buf_) { memmove(buf_, data.data(), data.size()); diff --git a/tensorflow/core/lib/io/inputbuffer_test.cc b/tensorflow/core/lib/io/inputbuffer_test.cc index 2404d5e6784..3608008b301 100644 --- a/tensorflow/core/lib/io/inputbuffer_test.cc +++ b/tensorflow/core/lib/io/inputbuffer_test.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/lib/io/inputbuffer.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/lib/core/coding.h" @@ -193,31 +192,31 @@ TEST(InputBuffer, ReadNBytes) { EXPECT_EQ(0, in.Tell()); TF_ASSERT_OK(in.ReadNBytes(3, read, &bytes_read)); - EXPECT_EQ(absl::string_view(read, 3), "012"); + EXPECT_EQ(StringPiece(read, 3), "012"); EXPECT_EQ(3, in.Tell()); TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read)); - EXPECT_EQ(absl::string_view(read, 3), "012"); + EXPECT_EQ(StringPiece(read, 3), "012"); EXPECT_EQ(3, in.Tell()); TF_ASSERT_OK(in.ReadNBytes(4, read, &bytes_read)); - EXPECT_EQ(absl::string_view(read, 4), "3456"); + EXPECT_EQ(StringPiece(read, 4), "3456"); EXPECT_EQ(7, in.Tell()); TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read)); - EXPECT_EQ(absl::string_view(read, 4), "3456"); + EXPECT_EQ(StringPiece(read, 4), "3456"); EXPECT_EQ(7, in.Tell()); EXPECT_TRUE(errors::IsOutOfRange(in.ReadNBytes(5, read, &bytes_read))); - EXPECT_EQ(absl::string_view(read, 3), "789"); + EXPECT_EQ(StringPiece(read, 3), "789"); EXPECT_EQ(10, in.Tell()); EXPECT_TRUE(errors::IsOutOfRange(in.ReadNBytes(5, read, &bytes_read))); - EXPECT_EQ(absl::string_view(read, 3), "789"); + EXPECT_EQ(StringPiece(read, 3), "789"); EXPECT_EQ(10, in.Tell()); TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read)); - EXPECT_EQ(absl::string_view(read, 3), "789"); + EXPECT_EQ(StringPiece(read, 3), "789"); EXPECT_EQ(10, in.Tell()); } } @@ -313,7 +312,7 @@ TEST(InputBuffer, ReadVarint32) { for (uint32 number : data) { varint.clear(); core::PutVarint32(&varint, number); - TF_CHECK_OK(file->Append(absl::string_view(varint))); + TF_CHECK_OK(file->Append(StringPiece(varint))); } } @@ -352,7 +351,7 @@ TEST(InputBuffer, ReadVarint64) { for (uint64 number : data) { varint.clear(); core::PutVarint64(&varint, number); - TF_CHECK_OK(file->Append(absl::string_view(varint))); + TF_CHECK_OK(file->Append(StringPiece(varint))); } } diff --git a/tensorflow/core/lib/io/iterator.cc b/tensorflow/core/lib/io/iterator.cc index 5ba6c2d8840..50eaa50b5cc 100644 --- a/tensorflow/core/lib/io/iterator.cc +++ b/tensorflow/core/lib/io/iterator.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/io/iterator.h" -#include "absl/strings/string_view.h" namespace tensorflow { namespace table { @@ -56,16 +55,16 @@ class EmptyIterator : public Iterator { public: explicit EmptyIterator(const Status& s) : status_(s) {} bool Valid() const override { return false; } - void Seek(const absl::string_view& target) override {} + void Seek(const StringPiece& target) override {} void SeekToFirst() override {} void Next() override { assert(false); } - absl::string_view key() const override { + StringPiece key() const override { assert(false); - return absl::string_view(); + return StringPiece(); } - absl::string_view value() const override { + StringPiece value() const override { assert(false); - return absl::string_view(); + return StringPiece(); } Status status() const override { return status_; } diff --git a/tensorflow/core/lib/io/iterator.h b/tensorflow/core/lib/io/iterator.h index 8532b0f4e6c..2b9326d7dd5 100644 --- a/tensorflow/core/lib/io/iterator.h +++ b/tensorflow/core/lib/io/iterator.h @@ -26,8 +26,8 @@ limitations under the License. #ifndef TENSORFLOW_LIB_IO_ITERATOR_H_ #define TENSORFLOW_LIB_IO_ITERATOR_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { namespace table { @@ -48,7 +48,7 @@ class Iterator { // Position at the first key in the source that is at or past target. // The iterator is Valid() after this call iff the source contains // an entry that comes at or past target. - virtual void Seek(const absl::string_view& target) = 0; + virtual void Seek(const StringPiece& target) = 0; // Moves to the next entry in the source. After this call, Valid() is // true iff the iterator was not positioned at the last entry in the source. @@ -59,13 +59,13 @@ class Iterator { // the returned slice is valid only until the next modification of // the iterator. // REQUIRES: Valid() - virtual absl::string_view key() const = 0; + virtual StringPiece key() const = 0; // Return the value for the current entry. The underlying storage for // the returned slice is valid only until the next modification of // the iterator. // REQUIRES: Valid() - virtual absl::string_view value() const = 0; + virtual StringPiece value() const = 0; // If an error has occurred, return it. Else return an ok status. virtual Status status() const = 0; diff --git a/tensorflow/core/lib/io/path.cc b/tensorflow/core/lib/io/path.cc index f64a7e1d86a..b75dcecadf9 100644 --- a/tensorflow/core/lib/io/path.cc +++ b/tensorflow/core/lib/io/path.cc @@ -20,7 +20,6 @@ limitations under the License. #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> -#include "absl/strings/string_view.h" #if !defined(PLATFORM_WINDOWS) #include <unistd.h> #endif @@ -36,10 +35,10 @@ namespace tensorflow { namespace io { namespace internal { -string JoinPathImpl(std::initializer_list<absl::string_view> paths) { +string JoinPathImpl(std::initializer_list<StringPiece> paths) { string result; - for (absl::string_view path : paths) { + for (StringPiece path : paths) { if (path.empty()) continue; if (result.empty()) { @@ -69,65 +68,62 @@ string JoinPathImpl(std::initializer_list<absl::string_view> paths) { // no "/" in the path, the first part of the output is the scheme and host, and // the second is the path. If the only "/" in the path is the first character, // it is included in the first part of the output. -std::pair<absl::string_view, absl::string_view> SplitPath( - absl::string_view uri) { - absl::string_view scheme, host, path; +std::pair<StringPiece, StringPiece> SplitPath(StringPiece uri) { + StringPiece scheme, host, path; ParseURI(uri, &scheme, &host, &path); auto pos = path.rfind('/'); #ifdef PLATFORM_WINDOWS - if (pos == absl::string_view::npos) pos = path.rfind('\\'); + if (pos == StringPiece::npos) pos = path.rfind('\\'); #endif // Handle the case with no '/' in 'path'. - if (pos == absl::string_view::npos) - return std::make_pair( - absl::string_view(uri.begin(), host.end() - uri.begin()), path); + if (pos == StringPiece::npos) + return std::make_pair(StringPiece(uri.begin(), host.end() - uri.begin()), + path); // Handle the case with a single leading '/' in 'path'. if (pos == 0) return std::make_pair( - absl::string_view(uri.begin(), path.begin() + 1 - uri.begin()), - absl::string_view(path.data() + 1, path.size() - 1)); + StringPiece(uri.begin(), path.begin() + 1 - uri.begin()), + StringPiece(path.data() + 1, path.size() - 1)); return std::make_pair( - absl::string_view(uri.begin(), path.begin() + pos - uri.begin()), - absl::string_view(path.data() + pos + 1, path.size() - (pos + 1))); + StringPiece(uri.begin(), path.begin() + pos - uri.begin()), + StringPiece(path.data() + pos + 1, path.size() - (pos + 1))); } // Return the parts of the basename of path, split on the final ".". // If there is no "." in the basename or "." is the final character in the // basename, the second value will be empty. -std::pair<absl::string_view, absl::string_view> SplitBasename( - absl::string_view path) { +std::pair<StringPiece, StringPiece> SplitBasename(StringPiece path) { path = Basename(path); auto pos = path.rfind('.'); - if (pos == absl::string_view::npos) - return std::make_pair(path, - absl::string_view(path.data() + path.size(), 0)); + if (pos == StringPiece::npos) + return std::make_pair(path, StringPiece(path.data() + path.size(), 0)); return std::make_pair( - absl::string_view(path.data(), pos), - absl::string_view(path.data() + pos + 1, path.size() - (pos + 1))); + StringPiece(path.data(), pos), + StringPiece(path.data() + pos + 1, path.size() - (pos + 1))); } } // namespace internal -bool IsAbsolutePath(absl::string_view path) { +bool IsAbsolutePath(StringPiece path) { return !path.empty() && path[0] == '/'; } -absl::string_view Dirname(absl::string_view path) { +StringPiece Dirname(StringPiece path) { return internal::SplitPath(path).first; } -absl::string_view Basename(absl::string_view path) { +StringPiece Basename(StringPiece path) { return internal::SplitPath(path).second; } -absl::string_view Extension(absl::string_view path) { +StringPiece Extension(StringPiece path) { return internal::SplitBasename(path).second; } -string CleanPath(absl::string_view unclean_path) { +string CleanPath(StringPiece unclean_path) { string path(unclean_path); const char* src = path.c_str(); string::iterator dst = path.begin(); @@ -208,8 +204,8 @@ string CleanPath(absl::string_view unclean_path) { return path; } -void ParseURI(absl::string_view remaining, absl::string_view* scheme, - absl::string_view* host, absl::string_view* path) { +void ParseURI(StringPiece remaining, StringPiece* scheme, StringPiece* host, + StringPiece* path) { // 0. Parse scheme // Make sure scheme matches [a-zA-Z][0-9a-zA-Z.]* // TODO(keveman): Allow "+" and "-" in the scheme. @@ -221,8 +217,8 @@ void ParseURI(absl::string_view remaining, absl::string_view* scheme, .OneLiteral("://") .GetResult(&remaining, scheme)) { // If there's no scheme, assume the entire string is a path. - *scheme = absl::string_view(remaining.begin(), 0); - *host = absl::string_view(remaining.begin(), 0); + *scheme = StringPiece(remaining.begin(), 0); + *host = StringPiece(remaining.begin(), 0); *path = remaining; return; } @@ -231,7 +227,7 @@ void ParseURI(absl::string_view remaining, absl::string_view* scheme, if (!strings::Scanner(remaining).ScanUntil('/').GetResult(&remaining, host)) { // No path, so the rest of the URI is the host. *host = remaining; - *path = absl::string_view(remaining.end(), 0); + *path = StringPiece(remaining.end(), 0); return; } @@ -239,8 +235,7 @@ void ParseURI(absl::string_view remaining, absl::string_view* scheme, *path = remaining; } -string CreateURI(absl::string_view scheme, absl::string_view host, - absl::string_view path) { +string CreateURI(StringPiece scheme, StringPiece host, StringPiece path) { if (scheme.empty()) { return string(path); } diff --git a/tensorflow/core/lib/io/path.h b/tensorflow/core/lib/io/path.h index 288b6ee9514..38fb0c5d861 100644 --- a/tensorflow/core/lib/io/path.h +++ b/tensorflow/core/lib/io/path.h @@ -16,13 +16,13 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_IO_PATH_H_ #define TENSORFLOW_CORE_LIB_IO_PATH_H_ -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { namespace io { namespace internal { -string JoinPathImpl(std::initializer_list<absl::string_view> paths); +string JoinPathImpl(std::initializer_list<tensorflow::StringPiece> paths); } // Utility routines for processing filenames @@ -49,20 +49,20 @@ string JoinPath(const T&... args) { #endif /* SWIG */ // Return true if path is absolute. -bool IsAbsolutePath(absl::string_view path); +bool IsAbsolutePath(tensorflow::StringPiece path); // Returns the part of the path before the final "/". If there is a single // leading "/" in the path, the result will be the leading "/". If there is // no "/" in the path, the result is the empty prefix of the input. -absl::string_view Dirname(absl::string_view path); +tensorflow::StringPiece Dirname(tensorflow::StringPiece path); // Returns the part of the path after the final "/". If there is no // "/" in the path, the result is the same as the input. -absl::string_view Basename(absl::string_view path); +tensorflow::StringPiece Basename(tensorflow::StringPiece path); // Returns the part of the basename of path after the final ".". If // there is no "." in the basename, the result is empty. -absl::string_view Extension(absl::string_view path); +tensorflow::StringPiece Extension(tensorflow::StringPiece path); // Collapse duplicate "/"s, resolve ".." and "." path elements, remove // trailing "/". @@ -71,7 +71,7 @@ absl::string_view Extension(absl::string_view path); // invoke any system calls (getcwd(2)) in order to resolve relative // paths with respect to the actual working directory. That is, this is purely // string manipulation, completely independent of process state. -string CleanPath(absl::string_view path); +string CleanPath(tensorflow::StringPiece path); // Populates the scheme, host, and path from a URI. scheme, host, and path are // guaranteed by this function to point into the contents of uri, even if @@ -81,13 +81,13 @@ string CleanPath(absl::string_view path); // - If the URI is invalid, scheme and host are set to empty strings and the // passed string is assumed to be a path // - If the URI omits the path (e.g. file://host), then the path is left empty. -void ParseURI(absl::string_view uri, absl::string_view* scheme, - absl::string_view* host, absl::string_view* path); +void ParseURI(tensorflow::StringPiece uri, tensorflow::StringPiece* scheme, + tensorflow::StringPiece* host, tensorflow::StringPiece* path); // Creates a URI from a scheme, host, and path. If the scheme is empty, we just // return the path. -string CreateURI(absl::string_view scheme, absl::string_view host, - absl::string_view path); +string CreateURI(tensorflow::StringPiece scheme, tensorflow::StringPiece host, + tensorflow::StringPiece path); // Creates a temporary file name with an extension. string GetTempFilename(const string& extension); diff --git a/tensorflow/core/lib/io/path_test.cc b/tensorflow/core/lib/io/path_test.cc index e22b03f0b0b..0090b9100ca 100644 --- a/tensorflow/core/lib/io/path_test.cc +++ b/tensorflow/core/lib/io/path_test.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/io/path.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -102,8 +101,8 @@ TEST(PathTest, CleanPath) { #define EXPECT_PARSE_URI(uri, scheme, host, path) \ do { \ - absl::string_view u(uri); \ - absl::string_view s, h, p; \ + StringPiece u(uri); \ + StringPiece s, h, p; \ ParseURI(u, &s, &h, &p); \ EXPECT_EQ(scheme, s); \ EXPECT_EQ(host, h); \ diff --git a/tensorflow/core/lib/io/proto_encode_helper.h b/tensorflow/core/lib/io/proto_encode_helper.h index 7e989e921fb..34905520f14 100644 --- a/tensorflow/core/lib/io/proto_encode_helper.h +++ b/tensorflow/core/lib/io/proto_encode_helper.h @@ -16,8 +16,8 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_IO_PROTO_ENCODE_HELPER_H_ #define TENSORFLOW_CORE_LIB_IO_PROTO_ENCODE_HELPER_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/protobuf.h" // A helper class for appending various kinds of values in protocol @@ -48,7 +48,7 @@ class ProtoEncodeHelper { Encode32(combine(tag, WIRETYPE_VARINT)); EncodeBool(v); } - void WriteString(int tag, absl::string_view v) { + void WriteString(int tag, StringPiece v) { Encode32(combine(tag, WIRETYPE_LENGTH_DELIMITED)); Encode32(v.size()); EncodeBytes(v.data(), v.size()); @@ -57,7 +57,7 @@ class ProtoEncodeHelper { Encode32(combine(tag, WIRETYPE_LENGTH_DELIMITED)); Encode32(len); } - void WriteRawBytes(absl::string_view v) { EncodeBytes(v.data(), v.size()); } + void WriteRawBytes(StringPiece v) { EncodeBytes(v.data(), v.size()); } private: // Note: this module's behavior must match the protocol buffer wire encoding diff --git a/tensorflow/core/lib/io/random_inputstream.cc b/tensorflow/core/lib/io/random_inputstream.cc index 4d9fe754976..e85367df9c8 100644 --- a/tensorflow/core/lib/io/random_inputstream.cc +++ b/tensorflow/core/lib/io/random_inputstream.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/io/random_inputstream.h" #include <memory> -#include "absl/strings/string_view.h" namespace tensorflow { namespace io { @@ -38,7 +37,7 @@ Status RandomAccessInputStream::ReadNBytes(int64 bytes_to_read, result->clear(); result->resize(bytes_to_read); char* result_buffer = &(*result)[0]; - absl::string_view data; + StringPiece data; Status s = file_->Read(pos_, bytes_to_read, &data, result_buffer); if (data.data() != result_buffer) { memmove(result_buffer, data.data(), data.size()); @@ -62,7 +61,7 @@ Status RandomAccessInputStream::SkipNBytes(int64 bytes_to_skip) { // Try to read 1 bytes first, if we could complete the read then EOF is // not reached yet and we could return. if (bytes_to_skip > 0) { - absl::string_view data; + StringPiece data; Status s = file_->Read(pos_ + bytes_to_skip - 1, 1, &data, scratch.get()); if ((s.ok() || errors::IsOutOfRange(s)) && data.size() == 1) { pos_ += bytes_to_skip; @@ -72,7 +71,7 @@ Status RandomAccessInputStream::SkipNBytes(int64 bytes_to_skip) { // Read kDefaultSkipSize at a time till bytes_to_skip. while (bytes_to_skip > 0) { int64 bytes_to_read = std::min<int64>(kMaxSkipSize, bytes_to_skip); - absl::string_view data; + StringPiece data; Status s = file_->Read(pos_, bytes_to_read, &data, scratch.get()); if (s.ok() || errors::IsOutOfRange(s)) { pos_ += data.size(); diff --git a/tensorflow/core/lib/io/record_writer.cc b/tensorflow/core/lib/io/record_writer.cc index 0aead25457b..2c6db2487ea 100644 --- a/tensorflow/core/lib/io/record_writer.cc +++ b/tensorflow/core/lib/io/record_writer.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/io/record_writer.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/hash/crc32c.h" #include "tensorflow/core/lib/io/compression.h" @@ -89,7 +88,7 @@ RecordWriter::~RecordWriter() { } } -Status RecordWriter::WriteRecord(absl::string_view data) { +Status RecordWriter::WriteRecord(StringPiece data) { if (dest_ == nullptr) { return Status(::tensorflow::error::FAILED_PRECONDITION, "Writer not initialized or previously closed"); @@ -103,9 +102,9 @@ Status RecordWriter::WriteRecord(absl::string_view data) { char footer[kFooterSize]; PopulateHeader(header, data.data(), data.size()); PopulateFooter(footer, data.data(), data.size()); - TF_RETURN_IF_ERROR(dest_->Append(absl::string_view(header, sizeof(header)))); + TF_RETURN_IF_ERROR(dest_->Append(StringPiece(header, sizeof(header)))); TF_RETURN_IF_ERROR(dest_->Append(data)); - return dest_->Append(absl::string_view(footer, sizeof(footer))); + return dest_->Append(StringPiece(footer, sizeof(footer))); } Status RecordWriter::Close() { diff --git a/tensorflow/core/lib/io/record_writer.h b/tensorflow/core/lib/io/record_writer.h index d797ab82f32..1212e1fafb4 100644 --- a/tensorflow/core/lib/io/record_writer.h +++ b/tensorflow/core/lib/io/record_writer.h @@ -16,9 +16,9 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_IO_RECORD_WRITER_H_ #define TENSORFLOW_CORE_LIB_IO_RECORD_WRITER_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/hash/crc32c.h" #if !defined(IS_SLIM_BUILD) #include "tensorflow/core/lib/io/zlib_compression_options.h" @@ -69,7 +69,7 @@ class RecordWriter { // implicit Close() call in the destructor. ~RecordWriter(); - Status WriteRecord(absl::string_view slice); + Status WriteRecord(StringPiece slice); // Flushes any buffered data held by underlying containers of the // RecordWriter to the WritableFile. Does *not* flush the diff --git a/tensorflow/core/lib/io/recordio_test.cc b/tensorflow/core/lib/io/recordio_test.cc index eda33163818..946d7188d3b 100644 --- a/tensorflow/core/lib/io/recordio_test.cc +++ b/tensorflow/core/lib/io/recordio_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status_test_util.h" @@ -59,7 +58,7 @@ class StringDest : public WritableFile { Status Close() override { return Status::OK(); } Status Flush() override { return Status::OK(); } Status Sync() override { return Status::OK(); } - Status Append(absl::string_view slice) override { + Status Append(StringPiece slice) override { contents_->append(slice.data(), slice.size()); return Status::OK(); } @@ -73,7 +72,7 @@ class StringSource : public RandomAccessFile { explicit StringSource(string* contents) : contents_(contents), force_error_(false) {} - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { if (force_error_) { force_error_ = false; @@ -87,7 +86,7 @@ class StringSource : public RandomAccessFile { if (contents_->size() < offset + n) { n = contents_->size() - offset; } - *result = absl::string_view(contents_->data() + offset, n); + *result = StringPiece(contents_->data() + offset, n); return Status::OK(); } @@ -124,7 +123,7 @@ class RecordioTest : public ::testing::Test { void Write(const string& msg) { ASSERT_TRUE(!reading_) << "Write() after starting to read"; - TF_ASSERT_OK(writer_->WriteRecord(absl::string_view(msg))); + TF_ASSERT_OK(writer_->WriteRecord(StringPiece(msg))); } size_t WrittenBytes() const { return contents_.size(); } @@ -268,7 +267,7 @@ TEST_F(RecordioTest, NonSequentialReadsWithCompression) { } // Tests of all the error paths in log_reader.cc follow: -void AssertHasSubstr(absl::string_view s, absl::string_view expected) { +void AssertHasSubstr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << s << " does not contain " << expected; } diff --git a/tensorflow/core/lib/io/snappy/snappy_buffers_test.cc b/tensorflow/core/lib/io/snappy/snappy_buffers_test.cc index c82b4243906..e0918c70a79 100644 --- a/tensorflow/core/lib/io/snappy/snappy_buffers_test.cc +++ b/tensorflow/core/lib/io/snappy/snappy_buffers_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/inputbuffer.h" #include "tensorflow/core/lib/io/snappy/snappy_inputbuffer.h" @@ -69,7 +68,7 @@ Status TestMultipleWrites(size_t compress_input_buf_size, compress_output_buf_size); for (int i = 0; i < num_writes; i++) { - TF_RETURN_IF_ERROR(out.Write(absl::string_view(data))); + TF_RETURN_IF_ERROR(out.Write(StringPiece(data))); if (with_flush) { TF_RETURN_IF_ERROR(out.Flush()); } @@ -88,7 +87,7 @@ Status TestMultipleWrites(size_t compress_input_buf_size, std::unique_ptr<RandomAccessFile> file_reader; TF_RETURN_IF_ERROR(env->NewRandomAccessFile(fname, &file_reader)); - absl::string_view data; + StringPiece data; size_t file_pos = 0; size_t bytes_to_read = 256; char* scratch = new char[bytes_to_read]; @@ -98,14 +97,14 @@ Status TestMultipleWrites(size_t compress_input_buf_size, while ((file_reader->Read(file_pos, bytes_to_read, &data, scratch)).ok()) { file_pos += data.size(); TF_CHECK_OK( - corrupt_file_writer->Append(absl::string_view(buffer, buffer_size))); + corrupt_file_writer->Append(StringPiece(buffer, buffer_size))); memcpy(buffer, data.data(), data.size()); buffer_size = data.size(); } // Drop the last byte. File is now corrupt. - TF_CHECK_OK(corrupt_file_writer->Append( - absl::string_view(buffer, buffer_size - 1))); + TF_CHECK_OK( + corrupt_file_writer->Append(StringPiece(buffer, buffer_size - 1))); TF_CHECK_OK(corrupt_file_writer->Flush()); TF_CHECK_OK(corrupt_file_writer->Close()); delete[] scratch; @@ -137,7 +136,7 @@ Status TestMultipleWrites(size_t compress_input_buf_size, static bool SnappyCompressionSupported() { string out; - absl::string_view in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + StringPiece in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; return port::Snappy_Compress(in.data(), in.size(), &out); } diff --git a/tensorflow/core/lib/io/snappy/snappy_inputbuffer.cc b/tensorflow/core/lib/io/snappy/snappy_inputbuffer.cc index 35572e6ae1b..853d86cb230 100644 --- a/tensorflow/core/lib/io/snappy/snappy_inputbuffer.cc +++ b/tensorflow/core/lib/io/snappy/snappy_inputbuffer.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/io/snappy/snappy_inputbuffer.h" -#include "absl/strings/string_view.h" namespace tensorflow { namespace io { @@ -160,7 +159,7 @@ Status SnappyInputBuffer::ReadFromFile() { bytes_to_read -= avail_in_; read_location += avail_in_; } - absl::string_view data; + StringPiece data; // Try to read enough data to fill up input_buffer_. Status s = file_->Read(file_pos_, bytes_to_read, &data, read_location); if (data.data() != read_location) { diff --git a/tensorflow/core/lib/io/snappy/snappy_outputbuffer.cc b/tensorflow/core/lib/io/snappy/snappy_outputbuffer.cc index d7c1deeb0bd..3c310167326 100644 --- a/tensorflow/core/lib/io/snappy/snappy_outputbuffer.cc +++ b/tensorflow/core/lib/io/snappy/snappy_outputbuffer.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/io/snappy/snappy_outputbuffer.h" -#include "absl/strings/string_view.h" namespace tensorflow { namespace io { @@ -31,7 +30,7 @@ SnappyOutputBuffer::SnappyOutputBuffer(WritableFile* file, next_out_(output_buffer_.get()), avail_out_(output_buffer_bytes) {} -Status SnappyOutputBuffer::Write(absl::string_view data) { +Status SnappyOutputBuffer::Write(StringPiece data) { // // The deflated output is accumulated in output_buffer_ and gets written to // file as and when needed. @@ -81,7 +80,7 @@ int32 SnappyOutputBuffer::AvailableInputSpace() const { return input_buffer_capacity_ - avail_in_; } -void SnappyOutputBuffer::AddToInputBuffer(absl::string_view data) { +void SnappyOutputBuffer::AddToInputBuffer(StringPiece data) { size_t bytes_to_write = data.size(); DCHECK_LE(bytes_to_write, AvailableInputSpace()); @@ -141,7 +140,7 @@ Status SnappyOutputBuffer::DeflateBuffered() { Status SnappyOutputBuffer::FlushOutputBufferToFile() { size_t bytes_to_write = output_buffer_capacity_ - avail_out_; if (bytes_to_write > 0) { - Status s = file_->Append(absl::string_view( + Status s = file_->Append(StringPiece( reinterpret_cast<char*>(output_buffer_.get()), bytes_to_write)); if (s.ok()) { next_out_ = output_buffer_.get(); diff --git a/tensorflow/core/lib/io/snappy/snappy_outputbuffer.h b/tensorflow/core/lib/io/snappy/snappy_outputbuffer.h index 7a0a3b0e197..5aea503846d 100644 --- a/tensorflow/core/lib/io/snappy/snappy_outputbuffer.h +++ b/tensorflow/core/lib/io/snappy/snappy_outputbuffer.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_CORE_LIB_IO_SNAPPY_OUTPUTBUFFER_H_ #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/macros.h" @@ -62,7 +61,7 @@ class SnappyOutputBuffer { // to file when the buffer is full. // // To immediately write contents to file call `Flush()`. - Status Write(absl::string_view data); + Status Write(StringPiece data); // Compresses any cached input and writes all output to file. This must be // called before the destructor to avoid any data loss. @@ -71,7 +70,7 @@ class SnappyOutputBuffer { private: // Appends `data` to `input_buffer_`. // Throws if `data.size()` > AvailableInputSpace(). - void AddToInputBuffer(absl::string_view data); + void AddToInputBuffer(StringPiece data); // Appends `data` to `output_buffer_`. Flushes buffer contents to file when // buffer gets full. diff --git a/tensorflow/core/lib/io/table.cc b/tensorflow/core/lib/io/table.cc index 2c982f85dd1..1ef7bb6ccda 100644 --- a/tensorflow/core/lib/io/table.cc +++ b/tensorflow/core/lib/io/table.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/io/table.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/io/block.h" @@ -47,7 +46,7 @@ Status Table::Open(const Options& options, RandomAccessFile* file, uint64 size, } char footer_space[Footer::kEncodedLength]; - absl::string_view footer_input; + StringPiece footer_input; Status s = file->Read(size - Footer::kEncodedLength, Footer::kEncodedLength, &footer_input, footer_space); if (!s.ok()) return s; @@ -92,14 +91,14 @@ static void DeleteBlock(void* arg, void* ignored) { // Convert an index iterator value (i.e., an encoded BlockHandle) // into an iterator over the contents of the corresponding block. -Iterator* Table::BlockReader(void* arg, const absl::string_view& index_value) { +Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) { Table* table = reinterpret_cast<Table*>(arg); // Cache* block_cache = table->rep_->options.block_cache; Block* block = nullptr; // Cache::Handle* cache_handle = NULL; BlockHandle handle; - absl::string_view input = index_value; + StringPiece input = index_value; Status s = handle.DecodeFrom(&input); // We intentionally allow extra stuff in index_value so that we // can add more features in the future. @@ -127,9 +126,9 @@ Iterator* Table::NewIterator() const { &Table::BlockReader, const_cast<Table*>(this)); } -Status Table::InternalGet(const absl::string_view& k, void* arg, - void (*saver)(void*, const absl::string_view&, - const absl::string_view&)) { +Status Table::InternalGet(const StringPiece& k, void* arg, + void (*saver)(void*, const StringPiece&, + const StringPiece&)) { Status s; Iterator* iiter = rep_->index_block->NewIterator(); iiter->Seek(k); @@ -150,13 +149,13 @@ Status Table::InternalGet(const absl::string_view& k, void* arg, return s; } -uint64 Table::ApproximateOffsetOf(const absl::string_view& key) const { +uint64 Table::ApproximateOffsetOf(const StringPiece& key) const { Iterator* index_iter = rep_->index_block->NewIterator(); index_iter->Seek(key); uint64 result; if (index_iter->Valid()) { BlockHandle handle; - absl::string_view input = index_iter->value(); + StringPiece input = index_iter->value(); Status s = handle.DecodeFrom(&input); if (s.ok()) { result = handle.offset(); diff --git a/tensorflow/core/lib/io/table.h b/tensorflow/core/lib/io/table.h index aa1ae0ecbf4..b9c6b8d9d23 100644 --- a/tensorflow/core/lib/io/table.h +++ b/tensorflow/core/lib/io/table.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_CORE_LIB_IO_TABLE_H_ #include <stdint.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/iterator.h" namespace tensorflow { @@ -61,22 +60,21 @@ class Table { // bytes, and so includes effects like compression of the underlying data. // E.g., the approximate offset of the last key in the table will // be close to the file length. - uint64 ApproximateOffsetOf(const absl::string_view& key) const; + uint64 ApproximateOffsetOf(const StringPiece& key) const; private: struct Rep; Rep* rep_; explicit Table(Rep* rep) { rep_ = rep; } - static Iterator* BlockReader(void*, const absl::string_view&); + static Iterator* BlockReader(void*, const StringPiece&); // Calls (*handle_result)(arg, ...) with the entry found after a call // to Seek(key). May not make such a call if filter policy says // that key is not present. - Status InternalGet(const absl::string_view& key, void* arg, - void (*handle_result)(void* arg, - const absl::string_view& k, - const absl::string_view& v)); + Status InternalGet(const StringPiece& key, void* arg, + void (*handle_result)(void* arg, const StringPiece& k, + const StringPiece& v)); // No copying allowed Table(const Table&); diff --git a/tensorflow/core/lib/io/table_builder.cc b/tensorflow/core/lib/io/table_builder.cc index c127f3779e5..81333a7b224 100644 --- a/tensorflow/core/lib/io/table_builder.cc +++ b/tensorflow/core/lib/io/table_builder.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/lib/io/table_builder.h" #include <assert.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/hash/crc32c.h" @@ -31,7 +30,7 @@ namespace table { namespace { -void FindShortestSeparator(string* start, const absl::string_view& limit) { +void FindShortestSeparator(string* start, const StringPiece& limit) { // Find length of common prefix size_t min_length = std::min(start->size(), limit.size()); size_t diff_index = 0; @@ -48,7 +47,7 @@ void FindShortestSeparator(string* start, const absl::string_view& limit) { diff_byte + 1 < static_cast<uint8>(limit[diff_index])) { (*start)[diff_index]++; start->resize(diff_index + 1); - assert(absl::string_view(*start).compare(limit) < 0); + assert(StringPiece(*start).compare(limit) < 0); } } } @@ -116,13 +115,12 @@ TableBuilder::~TableBuilder() { delete rep_; } -void TableBuilder::Add(const absl::string_view& key, - const absl::string_view& value) { +void TableBuilder::Add(const StringPiece& key, const StringPiece& value) { Rep* r = rep_; assert(!r->closed); if (!ok()) return; if (r->num_entries > 0) { - assert(key.compare(absl::string_view(r->last_key)) > 0); + assert(key.compare(StringPiece(r->last_key)) > 0); // See if this key+value would make our current block overly large. If // so, emit the current block before adding this key/value const int kOverlyLargeBlockRatio = 2; @@ -137,7 +135,7 @@ void TableBuilder::Add(const absl::string_view& key, FindShortestSeparator(&r->last_key, key); string handle_encoding; r->pending_handle.EncodeTo(&handle_encoding); - r->index_block.Add(r->last_key, absl::string_view(handle_encoding)); + r->index_block.Add(r->last_key, StringPiece(handle_encoding)); r->pending_index_entry = false; } @@ -171,9 +169,9 @@ void TableBuilder::WriteBlock(BlockBuilder* block, BlockHandle* handle) { // crc: uint32 assert(ok()); Rep* r = rep_; - absl::string_view raw = block->Finish(); + StringPiece raw = block->Finish(); - absl::string_view block_contents; + StringPiece block_contents; CompressionType type = r->options.compression; // TODO(postrelease): Support more compression options: zlib? switch (type) { @@ -200,7 +198,7 @@ void TableBuilder::WriteBlock(BlockBuilder* block, BlockHandle* handle) { block->Reset(); } -void TableBuilder::WriteRawBlock(const absl::string_view& block_contents, +void TableBuilder::WriteRawBlock(const StringPiece& block_contents, CompressionType type, BlockHandle* handle) { Rep* r = rep_; handle->set_offset(r->offset); @@ -212,7 +210,7 @@ void TableBuilder::WriteRawBlock(const absl::string_view& block_contents, uint32 crc = crc32c::Value(block_contents.data(), block_contents.size()); crc = crc32c::Extend(crc, trailer, 1); // Extend crc to cover block type core::EncodeFixed32(trailer + 1, crc32c::Mask(crc)); - r->status = r->file->Append(absl::string_view(trailer, kBlockTrailerSize)); + r->status = r->file->Append(StringPiece(trailer, kBlockTrailerSize)); if (r->status.ok()) { r->offset += block_contents.size() + kBlockTrailerSize; } @@ -242,7 +240,7 @@ Status TableBuilder::Finish() { FindShortSuccessor(&r->last_key); string handle_encoding; r->pending_handle.EncodeTo(&handle_encoding); - r->index_block.Add(r->last_key, absl::string_view(handle_encoding)); + r->index_block.Add(r->last_key, StringPiece(handle_encoding)); r->pending_index_entry = false; } WriteBlock(&r->index_block, &index_block_handle); diff --git a/tensorflow/core/lib/io/table_builder.h b/tensorflow/core/lib/io/table_builder.h index c0c9afbf666..0e37e0a77f1 100644 --- a/tensorflow/core/lib/io/table_builder.h +++ b/tensorflow/core/lib/io/table_builder.h @@ -25,7 +25,6 @@ limitations under the License. #define TENSORFLOW_CORE_LIB_IO_TABLE_BUILDER_H_ #include <stdint.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/io/table_options.h" @@ -49,7 +48,7 @@ class TableBuilder { // Add key,value to the table being constructed. // REQUIRES: key is after any previously added key in lexicographic order. // REQUIRES: Finish(), Abandon() have not been called - void Add(const absl::string_view& key, const absl::string_view& value); + void Add(const StringPiece& key, const StringPiece& value); // Advanced operation: writes any buffered key/value pairs to file. // Can be used to ensure that two adjacent entries never live in @@ -83,7 +82,7 @@ class TableBuilder { private: bool ok() const { return status().ok(); } void WriteBlock(BlockBuilder* block, BlockHandle* handle); - void WriteRawBlock(const absl::string_view& data, CompressionType, + void WriteRawBlock(const StringPiece& data, CompressionType, BlockHandle* handle); struct Rep; diff --git a/tensorflow/core/lib/io/table_test.cc b/tensorflow/core/lib/io/table_test.cc index 4821240964c..9cebbf40c67 100644 --- a/tensorflow/core/lib/io/table_test.cc +++ b/tensorflow/core/lib/io/table_test.cc @@ -19,7 +19,6 @@ limitations under the License. #include <map> #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/io/block.h" #include "tensorflow/core/lib/io/block_builder.h" @@ -36,17 +35,17 @@ namespace tensorflow { namespace table { namespace { -typedef std::pair<absl::string_view, absl::string_view> StringPiecePair; +typedef std::pair<StringPiece, StringPiece> StringPiecePair; } namespace test { -static absl::string_view RandomString(random::SimplePhilox* rnd, int len, - string* dst) { +static StringPiece RandomString(random::SimplePhilox* rnd, int len, + string* dst) { dst->resize(len); for (int i = 0; i < len; i++) { (*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95)); // ' ' .. '~' } - return absl::string_view(*dst); + return StringPiece(*dst); } static string RandomKey(random::SimplePhilox* rnd, int len) { // Make sure to generate a wide variety of characters so we @@ -59,9 +58,9 @@ static string RandomKey(random::SimplePhilox* rnd, int len) { } return result; } -static absl::string_view CompressibleString(random::SimplePhilox* rnd, - double compressed_fraction, - size_t len, string* dst) { +static StringPiece CompressibleString(random::SimplePhilox* rnd, + double compressed_fraction, size_t len, + string* dst) { int raw = static_cast<int>(len * compressed_fraction); if (raw < 1) raw = 1; string raw_data; @@ -73,7 +72,7 @@ static absl::string_view CompressibleString(random::SimplePhilox* rnd, dst->append(raw_data); } dst->resize(len); - return absl::string_view(*dst); + return StringPiece(*dst); } } // namespace test @@ -84,7 +83,7 @@ namespace { struct STLLessThan { STLLessThan() {} bool operator()(const string& a, const string& b) const { - return absl::string_view(a).compare(absl::string_view(b)) < 0; + return StringPiece(a).compare(StringPiece(b)) < 0; } }; } // namespace @@ -99,7 +98,7 @@ class StringSink : public WritableFile { Status Flush() override { return Status::OK(); } Status Sync() override { return Status::OK(); } - Status Append(absl::string_view data) override { + Status Append(StringPiece data) override { contents_.append(data.data(), data.size()); return Status::OK(); } @@ -110,14 +109,14 @@ class StringSink : public WritableFile { class StringSource : public RandomAccessFile { public: - explicit StringSource(const absl::string_view& contents) + explicit StringSource(const StringPiece& contents) : contents_(contents.data(), contents.size()), bytes_read_(0) {} ~StringSource() override {} uint64 Size() const { return contents_.size(); } - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { if (offset > contents_.size()) { return errors::InvalidArgument("invalid Read offset"); @@ -126,7 +125,7 @@ class StringSource : public RandomAccessFile { n = contents_.size() - offset; } memcpy(scratch, &contents_[offset], n); - *result = absl::string_view(scratch, n); + *result = StringPiece(scratch, n); bytes_read_ += n; return Status::OK(); } @@ -147,7 +146,7 @@ class Constructor { explicit Constructor() : data_(STLLessThan()) {} virtual ~Constructor() {} - void Add(const string& key, const absl::string_view& value) { + void Add(const string& key, const StringPiece& value) { data_[key] = string(value); } @@ -230,7 +229,7 @@ class TableConstructor : public Constructor { Iterator* NewIterator() const override { return table_->NewIterator(); } - uint64 ApproximateOffsetOf(const absl::string_view& key) const { + uint64 ApproximateOffsetOf(const StringPiece& key) const { return table_->ApproximateOffsetOf(key); } @@ -348,7 +347,7 @@ class Harness : public ::testing::Test { model_iter = data.lower_bound(key); if (kVerbose) fprintf(stderr, "Seek '%s'\n", str_util::CEscape(key).c_str()); - iter->Seek(absl::string_view(key)); + iter->Seek(StringPiece(key)); ASSERT_EQ(ToStringPiecePair(data, model_iter), ToStringPiecePair(iter)); break; @@ -434,7 +433,7 @@ TEST_F(Harness, ZeroRestartPointsInBlock) { char data[sizeof(uint32)]; memset(data, 0, sizeof(data)); BlockContents contents; - contents.data = absl::string_view(data, sizeof(data)); + contents.data = StringPiece(data, sizeof(data)); contents.cachable = false; contents.heap_allocated = false; Block block(contents); @@ -567,7 +566,7 @@ TEST(TableTest, ApproximateOffsetOfPlain) { static bool SnappyCompressionSupported() { string out; - absl::string_view in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + StringPiece in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; return port::Snappy_Compress(in.data(), in.size(), &out); } diff --git a/tensorflow/core/lib/io/two_level_iterator.cc b/tensorflow/core/lib/io/two_level_iterator.cc index 9898d2ab424..ad66ae40d80 100644 --- a/tensorflow/core/lib/io/two_level_iterator.cc +++ b/tensorflow/core/lib/io/two_level_iterator.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/io/two_level_iterator.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/block.h" #include "tensorflow/core/lib/io/format.h" #include "tensorflow/core/lib/io/iterator.h" @@ -26,7 +25,7 @@ namespace table { namespace { -typedef Iterator* (*BlockFunction)(void*, const absl::string_view&); +typedef Iterator* (*BlockFunction)(void*, const StringPiece&); class TwoLevelIterator : public Iterator { public: @@ -35,18 +34,18 @@ class TwoLevelIterator : public Iterator { ~TwoLevelIterator() override; - void Seek(const absl::string_view& target) override; + void Seek(const StringPiece& target) override; void SeekToFirst() override; void Next() override; bool Valid() const override { return (data_iter_ == nullptr) ? false : data_iter_->Valid(); } - absl::string_view key() const override { + StringPiece key() const override { assert(Valid()); return data_iter_->key(); } - absl::string_view value() const override { + StringPiece value() const override { assert(Valid()); return data_iter_->value(); } @@ -92,7 +91,7 @@ TwoLevelIterator::~TwoLevelIterator() { delete data_iter_; } -void TwoLevelIterator::Seek(const absl::string_view& target) { +void TwoLevelIterator::Seek(const StringPiece& target) { index_iter_->Seek(target); InitDataBlock(); if (data_iter_ != nullptr) data_iter_->Seek(target); @@ -137,7 +136,7 @@ void TwoLevelIterator::InitDataBlock() { if (!index_iter_->Valid()) { SetDataIterator(nullptr); } else { - absl::string_view handle = index_iter_->value(); + StringPiece handle = index_iter_->value(); if (data_iter_ != nullptr && handle.compare(data_block_handle_) == 0) { // data_iter_ is already constructed with this iterator, so // no need to change anything diff --git a/tensorflow/core/lib/io/two_level_iterator.h b/tensorflow/core/lib/io/two_level_iterator.h index 7472ec5965f..ce972bc68b4 100644 --- a/tensorflow/core/lib/io/two_level_iterator.h +++ b/tensorflow/core/lib/io/two_level_iterator.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_LIB_IO_TWO_LEVEL_ITERATOR_H_ #define TENSORFLOW_LIB_IO_TWO_LEVEL_ITERATOR_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/iterator.h" namespace tensorflow { @@ -33,8 +32,7 @@ namespace table { // an iterator over the contents of the corresponding block. extern Iterator* NewTwoLevelIterator( Iterator* index_iter, - Iterator* (*block_function)(void* arg, - const absl::string_view& index_value), + Iterator* (*block_function)(void* arg, const StringPiece& index_value), void* arg); } // namespace table diff --git a/tensorflow/core/lib/io/zlib_buffers_test.cc b/tensorflow/core/lib/io/zlib_buffers_test.cc index 2ea197e9c86..156c712db87 100644 --- a/tensorflow/core/lib/io/zlib_buffers_test.cc +++ b/tensorflow/core/lib/io/zlib_buffers_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/random_inputstream.h" #include "tensorflow/core/lib/io/zlib_compression_options.h" @@ -76,7 +75,7 @@ void TestAllCombinations(CompressionOptions input_options, output_options); TF_ASSERT_OK(out.Init()); - TF_ASSERT_OK(out.Append(absl::string_view(data))); + TF_ASSERT_OK(out.Append(StringPiece(data))); TF_ASSERT_OK(out.Close()); TF_ASSERT_OK(file_writer->Flush()); TF_ASSERT_OK(file_writer->Close()); @@ -125,7 +124,7 @@ void TestMultipleWrites(uint8 input_buf_size, uint8 output_buf_size, TF_ASSERT_OK(out.Init()); for (int i = 0; i < num_writes; i++) { - TF_ASSERT_OK(out.Append(absl::string_view(data))); + TF_ASSERT_OK(out.Append(StringPiece(data))); if (with_flush) { TF_ASSERT_OK(out.Flush()); } @@ -177,7 +176,7 @@ TEST(ZlibInputStream, FailsToReadIfWindowBitsAreIncompatible) { output_options); TF_ASSERT_OK(out.Init()); - TF_ASSERT_OK(out.Append(absl::string_view(data))); + TF_ASSERT_OK(out.Append(StringPiece(data))); TF_ASSERT_OK(out.Close()); TF_ASSERT_OK(file_writer->Flush()); TF_ASSERT_OK(file_writer->Close()); @@ -204,7 +203,7 @@ void WriteCompressedFile(Env* env, const string& fname, int input_buf_size, output_options); TF_ASSERT_OK(out.Init()); - TF_ASSERT_OK(out.Append(absl::string_view(data))); + TF_ASSERT_OK(out.Append(StringPiece(data))); TF_ASSERT_OK(out.Close()); TF_ASSERT_OK(file_writer->Flush()); TF_ASSERT_OK(file_writer->Close()); diff --git a/tensorflow/core/lib/io/zlib_outputbuffer.cc b/tensorflow/core/lib/io/zlib_outputbuffer.cc index ccede3afe03..cba139e6ad2 100644 --- a/tensorflow/core/lib/io/zlib_outputbuffer.cc +++ b/tensorflow/core/lib/io/zlib_outputbuffer.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/io/zlib_outputbuffer.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" namespace tensorflow { @@ -73,7 +72,7 @@ int32 ZlibOutputBuffer::AvailableInputSpace() const { return input_buffer_capacity_ - z_stream_->avail_in; } -void ZlibOutputBuffer::AddToInputBuffer(absl::string_view data) { +void ZlibOutputBuffer::AddToInputBuffer(StringPiece data) { size_t bytes_to_write = data.size(); CHECK_LE(bytes_to_write, AvailableInputSpace()); @@ -133,7 +132,7 @@ Status ZlibOutputBuffer::DeflateBuffered(bool last) { Status ZlibOutputBuffer::FlushOutputBufferToFile() { uint32 bytes_to_write = output_buffer_capacity_ - z_stream_->avail_out; if (bytes_to_write > 0) { - Status s = file_->Append(absl::string_view( + Status s = file_->Append(StringPiece( reinterpret_cast<char*>(z_stream_output_.get()), bytes_to_write)); if (s.ok()) { z_stream_->next_out = z_stream_output_.get(); @@ -144,7 +143,7 @@ Status ZlibOutputBuffer::FlushOutputBufferToFile() { return Status::OK(); } -Status ZlibOutputBuffer::Append(absl::string_view data) { +Status ZlibOutputBuffer::Append(StringPiece data) { // If there is sufficient free space in z_stream_input_ to fit data we // add it there and return. // If there isn't enough space we deflate the existing contents of diff --git a/tensorflow/core/lib/io/zlib_outputbuffer.h b/tensorflow/core/lib/io/zlib_outputbuffer.h index 7dfc6e781d8..ccad2fda44b 100644 --- a/tensorflow/core/lib/io/zlib_outputbuffer.h +++ b/tensorflow/core/lib/io/zlib_outputbuffer.h @@ -20,7 +20,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/io/zlib_compression_options.h" #include "tensorflow/core/platform/env.h" @@ -63,7 +62,7 @@ class ZlibOutputBuffer : public WritableFile { // to file when the buffer is full. // // To immediately write contents to file call `Flush()`. - Status Append(absl::string_view data) override; + Status Append(StringPiece data) override; // Deflates any cached input and writes all output to file. Status Flush() override; @@ -112,7 +111,7 @@ class ZlibOutputBuffer : public WritableFile { // Adds `data` to `z_stream_input_`. // Throws if `data.size()` > AvailableInputSpace(). - void AddToInputBuffer(absl::string_view data); + void AddToInputBuffer(StringPiece data); // Returns the total space available in z_input_stream_ buffer. int32 AvailableInputSpace() const; diff --git a/tensorflow/core/lib/jpeg/jpeg_mem.h b/tensorflow/core/lib/jpeg/jpeg_mem.h index 865983a1460..03437a4e78a 100644 --- a/tensorflow/core/lib/jpeg/jpeg_mem.h +++ b/tensorflow/core/lib/jpeg/jpeg_mem.h @@ -24,7 +24,7 @@ limitations under the License. #include <functional> #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/jpeg.h" #include "tensorflow/core/platform/types.h" @@ -136,7 +136,7 @@ struct CompressFlags { int y_density = 300; // If not empty, embed this XMP metadata in the image header - absl::string_view xmp_metadata; + StringPiece xmp_metadata; // The distance in bytes from one scanline to the other. Should be at least // equal to width*components*sizeof(JSAMPLE). If 0 is passed, the stride diff --git a/tensorflow/core/lib/monitoring/collection_registry.cc b/tensorflow/core/lib/monitoring/collection_registry.cc index 8d9fd5a7214..fface033cb9 100644 --- a/tensorflow/core/lib/monitoring/collection_registry.cc +++ b/tensorflow/core/lib/monitoring/collection_registry.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/monitoring/collection_registry.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { @@ -46,7 +45,7 @@ void Collector::CollectMetricDescriptor( metric_descriptor->name = string(metric_def->name()); metric_descriptor->description = string(metric_def->description()); - for (const absl::string_view label_name : metric_def->label_descriptions()) { + for (const StringPiece label_name : metric_def->label_descriptions()) { metric_descriptor->label_names.emplace_back(label_name); } diff --git a/tensorflow/core/lib/monitoring/collection_registry.h b/tensorflow/core/lib/monitoring/collection_registry.h index c1493710dbd..9e4e1989dd8 100644 --- a/tensorflow/core/lib/monitoring/collection_registry.h +++ b/tensorflow/core/lib/monitoring/collection_registry.h @@ -19,8 +19,8 @@ limitations under the License. #include <map> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/summary.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/monitoring/collected_metrics.h" #include "tensorflow/core/lib/monitoring/metric_def.h" #include "tensorflow/core/platform/env.h" @@ -186,7 +186,7 @@ class CollectionRegistry { CollectionFunction collection_function; uint64 registration_time_millis; }; - std::map<absl::string_view, CollectionInfo> registry_ GUARDED_BY(mu_); + std::map<StringPiece, CollectionInfo> registry_ GUARDED_BY(mu_); TF_DISALLOW_COPY_AND_ASSIGN(CollectionRegistry); }; diff --git a/tensorflow/core/lib/monitoring/metric_def.h b/tensorflow/core/lib/monitoring/metric_def.h index 2d155474400..bc4365e439c 100644 --- a/tensorflow/core/lib/monitoring/metric_def.h +++ b/tensorflow/core/lib/monitoring/metric_def.h @@ -19,8 +19,8 @@ limitations under the License. #include <array> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/summary.pb.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -82,9 +82,9 @@ class AbstractMetricDef { ValueType value_type() const { return value_type_; } - absl::string_view name() const { return name_; } + StringPiece name() const { return name_; } - absl::string_view description() const { return description_; } + StringPiece description() const { return description_; } const std::vector<string>& label_descriptions() const { return label_descriptions_; @@ -95,8 +95,7 @@ class AbstractMetricDef { friend class MetricDef; AbstractMetricDef(const MetricKind kind, const ValueType value_type, - const absl::string_view name, - const absl::string_view description, + const StringPiece name, const StringPiece description, const std::vector<string>& label_descriptions) : kind_(kind), value_type_(value_type), @@ -128,7 +127,7 @@ template <MetricKind metric_kind, typename Value, int NumLabels> class MetricDef : public AbstractMetricDef { public: template <typename... LabelDesc> - MetricDef(const absl::string_view name, const absl::string_view description, + MetricDef(const StringPiece name, const StringPiece description, const LabelDesc&... label_descriptions) : AbstractMetricDef(metric_kind, internal::GetValueType<Value>(), name, description, {label_descriptions...}) { diff --git a/tensorflow/core/lib/png/png_io.cc b/tensorflow/core/lib/png/png_io.cc index 5aa5809bae6..e226a15ccca 100644 --- a/tensorflow/core/lib/png/png_io.cc +++ b/tensorflow/core/lib/png/png_io.cc @@ -24,7 +24,6 @@ limitations under the License. // NOTE(skal): we don't '#include <setjmp.h>' before png.h as it otherwise // provokes a compile error. We instead let png.h include what is needed. -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/casts.h" #include "tensorflow/core/lib/png/png_io.h" #include "tensorflow/core/platform/byte_order.h" @@ -130,7 +129,7 @@ void CommonFreeDecode(DecodeContext* context) { } } -bool DecodeHeader(absl::string_view png_string, int* width, int* height, +bool DecodeHeader(StringPiece png_string, int* width, int* height, int* components, int* channel_bit_depth, std::vector<std::pair<string, string> >* metadata) { DecodeContext context; @@ -191,7 +190,7 @@ bool DecodeHeader(absl::string_view png_string, int* width, int* height, return true; } -bool CommonInitDecode(absl::string_view png_string, int desired_channels, +bool CommonInitDecode(StringPiece png_string, int desired_channels, int desired_channel_bits, DecodeContext* context) { CHECK(desired_channel_bits == 8 || desired_channel_bits == 16) << "desired_channel_bits = " << desired_channel_bits; diff --git a/tensorflow/core/lib/png/png_io.h b/tensorflow/core/lib/png/png_io.h index bbe43253993..c876c5156ab 100644 --- a/tensorflow/core/lib/png/png_io.h +++ b/tensorflow/core/lib/png/png_io.h @@ -35,7 +35,7 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/png.h" #include "tensorflow/core/platform/types.h" @@ -58,7 +58,7 @@ struct DecodeContext { DecodeContext() : png_ptr(NULL), info_ptr(NULL) {} }; -bool DecodeHeader(absl::string_view png_string, int* width, int* height, +bool DecodeHeader(StringPiece png_string, int* width, int* height, int* components, int* channel_bit_depth, std::vector<std::pair<string, string> >* metadata); @@ -73,7 +73,7 @@ bool DecodeHeader(absl::string_view png_string, int* width, int* height, // // desired_channels may be 0 to detected it from the input. -bool CommonInitDecode(absl::string_view png_string, int desired_channels, +bool CommonInitDecode(StringPiece png_string, int desired_channels, int desired_channel_bits, DecodeContext* context); bool CommonFinishDecode(png_bytep data, int row_bytes, DecodeContext* context); diff --git a/tensorflow/core/lib/strings/base64.cc b/tensorflow/core/lib/strings/base64.cc index cd12afc171b..c5a521f18ae 100644 --- a/tensorflow/core/lib/strings/base64.cc +++ b/tensorflow/core/lib/strings/base64.cc @@ -17,7 +17,6 @@ limitations under the License. #include <cstring> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" namespace tensorflow { @@ -74,7 +73,7 @@ Status DecodeThreeChars(const char* codes, char* result) { } } // namespace -Status Base64Decode(absl::string_view data, string* decoded) { +Status Base64Decode(StringPiece data, string* decoded) { if (decoded == nullptr) { return errors::Internal("'decoded' cannot be nullptr."); } @@ -136,12 +135,11 @@ Status Base64Decode(absl::string_view data, string* decoded) { return Status::OK(); } -Status Base64Encode(absl::string_view source, string* encoded) { +Status Base64Encode(StringPiece source, string* encoded) { return Base64Encode(source, false, encoded); } -Status Base64Encode(absl::string_view source, bool with_padding, - string* encoded) { +Status Base64Encode(StringPiece source, bool with_padding, string* encoded) { const char* const base64_chars = kBase64UrlSafeChars; if (encoded == nullptr) { return errors::Internal("'encoded' cannot be nullptr."); diff --git a/tensorflow/core/lib/strings/base64.h b/tensorflow/core/lib/strings/base64.h index 3ea41f9ce3f..48a7f42b81d 100644 --- a/tensorflow/core/lib/strings/base64.h +++ b/tensorflow/core/lib/strings/base64.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_LIB_STRINGS_B64_H_ #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" namespace tensorflow { @@ -25,14 +24,13 @@ namespace tensorflow { /// \brief Converts data into web-safe base64 encoding. /// /// See https://en.wikipedia.org/wiki/Base64 -Status Base64Encode(absl::string_view data, bool with_padding, string* encoded); -Status Base64Encode(absl::string_view data, - string* encoded); // with_padding=false. +Status Base64Encode(StringPiece data, bool with_padding, string* encoded); +Status Base64Encode(StringPiece data, string* encoded); // with_padding=false. /// \brief Converts data from web-safe base64 encoding. /// /// See https://en.wikipedia.org/wiki/Base64 -Status Base64Decode(absl::string_view data, string* decoded); +Status Base64Decode(StringPiece data, string* decoded); } // namespace tensorflow diff --git a/tensorflow/core/lib/strings/numbers.cc b/tensorflow/core/lib/strings/numbers.cc index ba7e5544994..fff6f1fedc3 100644 --- a/tensorflow/core/lib/strings/numbers.cc +++ b/tensorflow/core/lib/strings/numbers.cc @@ -24,7 +24,6 @@ limitations under the License. #include <locale> #include <unordered_map> -#include "absl/strings/string_view.h" #include "double-conversion/double-conversion.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -212,16 +211,16 @@ size_t DoubleToBuffer(double value, char* buffer) { } namespace { -char SafeFirstChar(absl::string_view str) { +char SafeFirstChar(StringPiece str) { if (str.empty()) return '\0'; return str[0]; } -void SkipSpaces(absl::string_view* str) { +void SkipSpaces(StringPiece* str) { while (isspace(SafeFirstChar(*str))) str->remove_prefix(1); } } // namespace -bool safe_strto64(absl::string_view str, int64* value) { +bool safe_strto64(StringPiece str, int64* value) { SkipSpaces(&str); int64 vlimit = kint64max; @@ -262,7 +261,7 @@ bool safe_strto64(absl::string_view str, int64* value) { return true; } -bool safe_strtou64(absl::string_view str, uint64* value) { +bool safe_strtou64(StringPiece str, uint64* value) { SkipSpaces(&str); if (!isdigit(SafeFirstChar(str))) return false; @@ -283,7 +282,7 @@ bool safe_strtou64(absl::string_view str, uint64* value) { return true; } -bool safe_strto32(absl::string_view str, int32* value) { +bool safe_strto32(StringPiece str, int32* value) { SkipSpaces(&str); int64 vmax = kint32max; @@ -313,7 +312,7 @@ bool safe_strto32(absl::string_view str, int32* value) { return true; } -bool safe_strtou32(absl::string_view str, uint32* value) { +bool safe_strtou32(StringPiece str, uint32* value) { SkipSpaces(&str); if (!isdigit(SafeFirstChar(str))) return false; @@ -333,7 +332,7 @@ bool safe_strtou32(absl::string_view str, uint32* value) { return true; } -bool safe_strtof(absl::string_view str, float* value) { +bool safe_strtof(StringPiece str, float* value) { int processed_characters_count = -1; auto len = str.size(); @@ -346,7 +345,7 @@ bool safe_strtof(absl::string_view str, float* value) { return processed_characters_count > 0; } -bool safe_strtod(absl::string_view str, double* value) { +bool safe_strtod(StringPiece str, double* value) { int processed_characters_count = -1; auto len = str.size(); @@ -401,7 +400,7 @@ bool StringToFp(const string& s, Fprint* fp) { } } -absl::string_view Uint64ToHexString(uint64 v, char* buf) { +StringPiece Uint64ToHexString(uint64 v, char* buf) { static const char* hexdigits = "0123456789abcdef"; const int num_byte = 16; buf[num_byte] = '\0'; @@ -409,10 +408,10 @@ absl::string_view Uint64ToHexString(uint64 v, char* buf) { buf[i] = hexdigits[v & 0xf]; v >>= 4; } - return absl::string_view(buf, num_byte); + return StringPiece(buf, num_byte); } -bool HexStringToUint64(const absl::string_view& s, uint64* result) { +bool HexStringToUint64(const StringPiece& s, uint64* result) { uint64 v = 0; if (s.empty()) { return false; diff --git a/tensorflow/core/lib/strings/numbers.h b/tensorflow/core/lib/strings/numbers.h index f28cb0c28ce..959290ba8c7 100644 --- a/tensorflow/core/lib/strings/numbers.h +++ b/tensorflow/core/lib/strings/numbers.h @@ -18,7 +18,7 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -84,66 +84,66 @@ bool StringToFp(const string& s, Fprint* fp); // Convert a 64-bit fingerprint value to an ASCII representation that // is terminated by a '\0'. // Buf must point to an array of at least kFastToBufferSize characters -absl::string_view Uint64ToHexString(uint64 v, char* buf); +StringPiece Uint64ToHexString(uint64 v, char* buf); // Attempt to parse a uint64 in the form encoded by FastUint64ToHexString. If // successful, stores the value in *v and returns true. Otherwise, // returns false. -bool HexStringToUint64(const absl::string_view& s, uint64* v); +bool HexStringToUint64(const StringPiece& s, uint64* v); // Convert strings to 32bit integer values. // Leading and trailing spaces are allowed. // Return false with overflow or invalid input. -bool safe_strto32(absl::string_view str, int32* value); +bool safe_strto32(StringPiece str, int32* value); // Convert strings to unsigned 32bit integer values. // Leading and trailing spaces are allowed. // Return false with overflow or invalid input. -bool safe_strtou32(absl::string_view str, uint32* value); +bool safe_strtou32(StringPiece str, uint32* value); // Convert strings to 64bit integer values. // Leading and trailing spaces are allowed. // Return false with overflow or invalid input. -bool safe_strto64(absl::string_view str, int64* value); +bool safe_strto64(StringPiece str, int64* value); // Convert strings to unsigned 64bit integer values. // Leading and trailing spaces are allowed. // Return false with overflow or invalid input. -bool safe_strtou64(absl::string_view str, uint64* value); +bool safe_strtou64(StringPiece str, uint64* value); // Convert strings to floating point values. // Leading and trailing spaces are allowed. // Values may be rounded on over- and underflow. // Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`. -bool safe_strtof(absl::string_view str, float* value); +bool safe_strtof(StringPiece str, float* value); // Convert strings to double precision floating point values. // Leading and trailing spaces are allowed. // Values may be rounded on over- and underflow. // Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`. -bool safe_strtod(absl::string_view str, double* value); +bool safe_strtod(StringPiece str, double* value); -inline bool ProtoParseNumeric(absl::string_view s, int32* value) { +inline bool ProtoParseNumeric(StringPiece s, int32* value) { return safe_strto32(s, value); } -inline bool ProtoParseNumeric(absl::string_view s, uint32* value) { +inline bool ProtoParseNumeric(StringPiece s, uint32* value) { return safe_strtou32(s, value); } -inline bool ProtoParseNumeric(absl::string_view s, int64* value) { +inline bool ProtoParseNumeric(StringPiece s, int64* value) { return safe_strto64(s, value); } -inline bool ProtoParseNumeric(absl::string_view s, uint64* value) { +inline bool ProtoParseNumeric(StringPiece s, uint64* value) { return safe_strtou64(s, value); } -inline bool ProtoParseNumeric(absl::string_view s, float* value) { +inline bool ProtoParseNumeric(StringPiece s, float* value) { return safe_strtof(s, value); } -inline bool ProtoParseNumeric(absl::string_view s, double* value) { +inline bool ProtoParseNumeric(StringPiece s, double* value) { return safe_strtod(s, value); } @@ -151,7 +151,7 @@ inline bool ProtoParseNumeric(absl::string_view s, double* value) { // Leading and trailing spaces are allowed. // Values may be rounded on over- and underflow. template <typename T> -bool SafeStringToNumeric(absl::string_view s, T* value) { +bool SafeStringToNumeric(StringPiece s, T* value) { return ProtoParseNumeric(s, value); } diff --git a/tensorflow/core/lib/strings/numbers_test.cc b/tensorflow/core/lib/strings/numbers_test.cc index 0e5e59a66bf..5b595f98478 100644 --- a/tensorflow/core/lib/strings/numbers_test.cc +++ b/tensorflow/core/lib/strings/numbers_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <cmath> #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -48,7 +47,7 @@ TEST(Uint64ToHexString, Ints) { for (int delta = -1; delta <= 1; delta++) { uint64 fp = (1ull << s) + delta; char buf[kFastToBufferSize]; - absl::string_view s = Uint64ToHexString(fp, buf); + StringPiece s = Uint64ToHexString(fp, buf); uint64 fp2; EXPECT_TRUE(HexStringToUint64(s, &fp2)); EXPECT_EQ(fp, fp2) << s; @@ -145,11 +144,11 @@ TEST(safe_strto32, Int32s) { EXPECT_EQ(false, safe_strto32("-2147483649", &result)); // Check that the StringPiece's length is respected. - EXPECT_EQ(true, safe_strto32(absl::string_view("123", 1), &result)); + EXPECT_EQ(true, safe_strto32(StringPiece("123", 1), &result)); EXPECT_EQ(1, result); - EXPECT_EQ(true, safe_strto32(absl::string_view(" -123", 4), &result)); + EXPECT_EQ(true, safe_strto32(StringPiece(" -123", 4), &result)); EXPECT_EQ(-12, result); - EXPECT_EQ(false, safe_strto32(absl::string_view(nullptr, 0), &result)); + EXPECT_EQ(false, safe_strto32(StringPiece(nullptr, 0), &result)); } TEST(safe_strtou32, UInt32s) { @@ -178,11 +177,11 @@ TEST(safe_strtou32, UInt32s) { EXPECT_FALSE(safe_strtou32("-1", &result)); // Check that the StringPiece's length is respected. - EXPECT_TRUE(safe_strtou32(absl::string_view("123", 1), &result)); + EXPECT_TRUE(safe_strtou32(StringPiece("123", 1), &result)); EXPECT_EQ(1, result); - EXPECT_TRUE(safe_strtou32(absl::string_view(" 123", 3), &result)); + EXPECT_TRUE(safe_strtou32(StringPiece(" 123", 3), &result)); EXPECT_EQ(12, result); - EXPECT_FALSE(safe_strtou32(absl::string_view(nullptr, 0), &result)); + EXPECT_FALSE(safe_strtou32(StringPiece(nullptr, 0), &result)); } TEST(safe_strto64, Int64s) { @@ -214,11 +213,11 @@ TEST(safe_strto64, Int64s) { EXPECT_EQ(false, safe_strto64("-9223372036854775809", &result)); // Check that the StringPiece's length is respected. - EXPECT_EQ(true, safe_strto64(absl::string_view("123", 1), &result)); + EXPECT_EQ(true, safe_strto64(StringPiece("123", 1), &result)); EXPECT_EQ(1, result); - EXPECT_EQ(true, safe_strto64(absl::string_view(" -123", 4), &result)); + EXPECT_EQ(true, safe_strto64(StringPiece(" -123", 4), &result)); EXPECT_EQ(-12, result); - EXPECT_EQ(false, safe_strto64(absl::string_view(nullptr, 0), &result)); + EXPECT_EQ(false, safe_strto64(StringPiece(nullptr, 0), &result)); } TEST(safe_strtou64, UInt64s) { @@ -249,11 +248,11 @@ TEST(safe_strtou64, UInt64s) { EXPECT_FALSE(safe_strtou64("-1", &result)); // Check that the StringPiece's length is respected. - EXPECT_TRUE(safe_strtou64(absl::string_view("123", 1), &result)); + EXPECT_TRUE(safe_strtou64(StringPiece("123", 1), &result)); EXPECT_EQ(1, result); - EXPECT_TRUE(safe_strtou64(absl::string_view(" 123", 3), &result)); + EXPECT_TRUE(safe_strtou64(StringPiece(" 123", 3), &result)); EXPECT_EQ(12, result); - EXPECT_FALSE(safe_strtou64(absl::string_view(nullptr, 0), &result)); + EXPECT_FALSE(safe_strtou64(StringPiece(nullptr, 0), &result)); } TEST(safe_strtof, Float) { diff --git a/tensorflow/core/lib/strings/ordered_code.cc b/tensorflow/core/lib/strings/ordered_code.cc index 5b8ef934310..ef90050b4f6 100644 --- a/tensorflow/core/lib/strings/ordered_code.cc +++ b/tensorflow/core/lib/strings/ordered_code.cc @@ -18,7 +18,7 @@ limitations under the License. #include <assert.h> #include <stddef.h> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { @@ -160,7 +160,7 @@ const char* OrderedCode::TEST_SkipToNextSpecialByte(const char* start, // Helper routine to encode "s" and append to "*dest", escaping special // characters. -inline static void EncodeStringFragment(string* dest, absl::string_view s) { +inline static void EncodeStringFragment(string* dest, StringPiece s) { const char* p = s.data(); const char* limit = p + s.size(); const char* copy_start = p; @@ -187,7 +187,7 @@ inline static void EncodeStringFragment(string* dest, absl::string_view s) { } } -void OrderedCode::WriteString(string* dest, absl::string_view s) { +void OrderedCode::WriteString(string* dest, StringPiece s) { EncodeStringFragment(dest, s); AppendBytes(dest, kEscape1_Separator, 2); } @@ -212,7 +212,7 @@ void OrderedCode::WriteNumIncreasing(string* dest, uint64 val) { // If parse succeeds, return true, consume encoding from // "*src", and if result != NULL append the decoded string to "*result". // Otherwise, return false and leave both undefined. -inline static bool ReadStringInternal(absl::string_view* src, string* result) { +inline static bool ReadStringInternal(StringPiece* src, string* result) { const char* start = src->data(); const char* string_limit = src->data() + src->size(); @@ -267,11 +267,11 @@ inline static bool ReadStringInternal(absl::string_view* src, string* result) { return false; } -bool OrderedCode::ReadString(absl::string_view* src, string* result) { +bool OrderedCode::ReadString(StringPiece* src, string* result) { return ReadStringInternal(src, result); } -bool OrderedCode::ReadNumIncreasing(absl::string_view* src, uint64* result) { +bool OrderedCode::ReadNumIncreasing(StringPiece* src, uint64* result) { if (src->empty()) { return false; // Not enough bytes } @@ -485,8 +485,7 @@ void OrderedCode::WriteSignedNumIncreasing(string* dest, int64 val) { dest->append(begin, len); } -bool OrderedCode::ReadSignedNumIncreasing(absl::string_view* src, - int64* result) { +bool OrderedCode::ReadSignedNumIncreasing(StringPiece* src, int64* result) { if (src->empty()) return false; const uint64 xor_mask = (!((*src)[0] & 0x80)) ? ~0ULL : 0ULL; const unsigned char first_byte = (*src)[0] ^ (xor_mask & 0xff); diff --git a/tensorflow/core/lib/strings/ordered_code.h b/tensorflow/core/lib/strings/ordered_code.h index 54c7326011f..91870cfec63 100644 --- a/tensorflow/core/lib/strings/ordered_code.h +++ b/tensorflow/core/lib/strings/ordered_code.h @@ -39,7 +39,7 @@ limitations under the License. #define TENSORFLOW_LIB_STRINGS_ORDERED_CODE_H__ #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/types.h" @@ -53,7 +53,7 @@ class OrderedCode { // Encoding routines: each one of the following routines append // one item to "*dest" in an encoding where larger values are // ordered lexicographically after smaller values. - static void WriteString(string* dest, absl::string_view str); + static void WriteString(string* dest, StringPiece str); static void WriteNumIncreasing(string* dest, uint64 num); static void WriteSignedNumIncreasing(string* dest, int64 num); @@ -65,9 +65,9 @@ class OrderedCode { // result. In case of string result, the decoded string is appended to // "*result". Returns true if the next item was read successfully, false // otherwise. - static bool ReadString(absl::string_view* src, string* result); - static bool ReadNumIncreasing(absl::string_view* src, uint64* result); - static bool ReadSignedNumIncreasing(absl::string_view* src, int64* result); + static bool ReadString(StringPiece* src, string* result); + static bool ReadNumIncreasing(StringPiece* src, uint64* result); + static bool ReadSignedNumIncreasing(StringPiece* src, int64* result); // Helper for testing: corrupt "*str" by changing the kth item separator // in the string. diff --git a/tensorflow/core/lib/strings/ordered_code_test.cc b/tensorflow/core/lib/strings/ordered_code_test.cc index 53457b8ce72..ede9f4d3901 100644 --- a/tensorflow/core/lib/strings/ordered_code_test.cc +++ b/tensorflow/core/lib/strings/ordered_code_test.cc @@ -20,7 +20,7 @@ limitations under the License. #include <limits> #include <vector> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/random/simple_philox.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" @@ -47,7 +47,7 @@ string RandomString(random::SimplePhilox* rnd, size_t len) { template <typename T> void OCWriteIncreasing(string* dest, const T& val); template <typename T> -bool OCReadIncreasing(absl::string_view* src, T* result); +bool OCReadIncreasing(StringPiece* src, T* result); // Read/WriteIncreasing<string> template <> @@ -55,7 +55,7 @@ void OCWriteIncreasing<string>(string* dest, const string& val) { OrderedCode::WriteString(dest, val); } template <> -bool OCReadIncreasing<string>(absl::string_view* src, string* result) { +bool OCReadIncreasing<string>(StringPiece* src, string* result) { return OrderedCode::ReadString(src, result); } @@ -65,7 +65,7 @@ void OCWriteIncreasing<uint64>(string* dest, const uint64& val) { OrderedCode::WriteNumIncreasing(dest, val); } template <> -bool OCReadIncreasing<uint64>(absl::string_view* src, uint64* result) { +bool OCReadIncreasing<uint64>(StringPiece* src, uint64* result) { return OrderedCode::ReadNumIncreasing(src, result); } @@ -75,7 +75,7 @@ void OCWriteIncreasing<int64>(string* dest, const int64& val) { OrderedCode::WriteSignedNumIncreasing(dest, val); } template <> -bool OCReadIncreasing<int64>(absl::string_view* src, int64* result) { +bool OCReadIncreasing<int64>(StringPiece* src, int64* result) { return OrderedCode::ReadSignedNumIncreasing(src, result); } @@ -92,7 +92,7 @@ void OCWriteToString(string* result, T val) { } template <typename T> -bool OCRead(absl::string_view* s, T* val) { +bool OCRead(StringPiece* s, T* val) { return OCReadIncreasing<T>(s, val); } @@ -103,12 +103,12 @@ template <typename T> T TestRead(const string& a) { // gracefully reject any proper prefix of an encoding for (int i = 0; i < a.size() - 1; ++i) { - absl::string_view s(a.data(), i); + StringPiece s(a.data(), i); CHECK(!OCRead<T>(&s, nullptr)); CHECK_EQ(s, a.substr(0, i)); } - absl::string_view s(a); + StringPiece s(a); T v; CHECK(OCRead<T>(&s, &v)); CHECK(s.empty()); @@ -304,7 +304,7 @@ inline string StrNot(const string& s) { template <typename T> void TestInvalidEncoding(const string& s) { - absl::string_view p(s); + StringPiece p(s); EXPECT_FALSE(OCRead<T>(&p, nullptr)); EXPECT_EQ(s, p); } @@ -338,7 +338,7 @@ TEST(OrderedCodeInvalidEncodingsDeathTest, NonCanonical) { EXPECT_NE(OCWrite<uint64>(0), non_minimal); #ifndef NDEBUG - absl::string_view s(non_minimal); + StringPiece s(non_minimal); EXPECT_DEATH(OrderedCode::ReadNumIncreasing(&s, nullptr), "invalid encoding"); #else @@ -357,7 +357,7 @@ TEST(OrderedCodeInvalidEncodingsDeathTest, NonCanonical) { EXPECT_NE(OCWrite<int64>(0), non_minimal); #ifndef NDEBUG - absl::string_view s(non_minimal); + StringPiece s(non_minimal); EXPECT_DEATH(OrderedCode::ReadSignedNumIncreasing(&s, nullptr), "invalid encoding") << n; @@ -409,7 +409,7 @@ void BM_ReadNum(int n, T multiplier) { uint32 index = 0; while (n-- > 0) { T val; - absl::string_view s = values[index++ % kValues]; + StringPiece s = values[index++ % kValues]; OCRead<T>(&s, &val); } } @@ -446,8 +446,8 @@ TEST(String, EncodeDecode) { OCWriteToString<string>(&out, b); string a2, b2, dummy; - absl::string_view s = out; - absl::string_view s2 = out; + StringPiece s = out; + StringPiece s2 = out; CHECK(OCRead<string>(&s, &a2)); CHECK(OCRead<string>(&s2, nullptr)); CHECK_EQ(s, s2); @@ -467,9 +467,9 @@ TEST(String, EncodeDecode) { } // 'str' is a string literal that may contain '\0'. -#define STATIC_STR(str) absl::string_view((str), sizeof(str) - 1) +#define STATIC_STR(str) StringPiece((str), sizeof(str) - 1) -string EncodeStringIncreasing(absl::string_view value) { +string EncodeStringIncreasing(StringPiece value) { string encoded; OrderedCode::WriteString(&encoded, value); return encoded; @@ -523,7 +523,7 @@ TEST(EncodingIsExpected, String) { OrderedCode::WriteString(&result, t.first); EXPECT_EQ(t.second, result); - absl::string_view in = result; + StringPiece in = result; string decoded; EXPECT_TRUE(OrderedCode::ReadString(&in, &decoded)); EXPECT_EQ(t.first, decoded); @@ -755,7 +755,7 @@ TEST(EncodingIsExpected, Unsigned) { OrderedCode::WriteNumIncreasing(&result, num); EXPECT_EQ(t.second, result) << std::hex << num; - absl::string_view in = result; + StringPiece in = result; uint64 decoded; EXPECT_TRUE(OrderedCode::ReadNumIncreasing(&in, &decoded)); EXPECT_EQ(num, decoded); @@ -1202,7 +1202,7 @@ TEST(EncodingIsExpected, Signed) { OrderedCode::WriteSignedNumIncreasing(&result, num); EXPECT_EQ(t.second, result) << std::hex << num; - absl::string_view in = result; + StringPiece in = result; int64 decoded; EXPECT_TRUE(OrderedCode::ReadSignedNumIncreasing(&in, &decoded)); EXPECT_EQ(num, decoded); @@ -1244,7 +1244,7 @@ void BM_ReadString(int n, int len) { testing::StartTiming(); while (n-- > 0) { result.clear(); - absl::string_view s = data; + StringPiece s = data; OCRead<string>(&s, &result); } } diff --git a/tensorflow/core/lib/strings/proto_text_util.cc b/tensorflow/core/lib/strings/proto_text_util.cc index 906c1150d88..5e9fa24a873 100644 --- a/tensorflow/core/lib/strings/proto_text_util.cc +++ b/tensorflow/core/lib/strings/proto_text_util.cc @@ -14,13 +14,12 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/strings/proto_text_util.h" -#include "absl/strings/string_view.h" namespace tensorflow { namespace strings { bool ProtoParseBoolFromScanner(Scanner* scanner, bool* value) { - absl::string_view bool_str; + StringPiece bool_str; if (!scanner->RestartCapture() .Many(Scanner::LETTER_DIGIT) .GetResult(nullptr, &bool_str)) { @@ -42,7 +41,7 @@ bool ProtoParseStringLiteralFromScanner(Scanner* scanner, string* value) { const char quote = scanner->Peek(); if (quote != '\'' && quote != '"') return false; - absl::string_view value_sp; + StringPiece value_sp; if (!scanner->One(Scanner::ALL) .RestartCapture() .ScanEscapedUntil(quote) diff --git a/tensorflow/core/lib/strings/proto_text_util.h b/tensorflow/core/lib/strings/proto_text_util.h index 3a2bcef6d50..05dbda6e152 100644 --- a/tensorflow/core/lib/strings/proto_text_util.h +++ b/tensorflow/core/lib/strings/proto_text_util.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_STRINGS_PROTO_TEXT_UTIL_H_ #define TENSORFLOW_CORE_LIB_STRINGS_PROTO_TEXT_UTIL_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -101,8 +100,7 @@ class ProtoTextOutput { } private: - void AppendFieldAndValue(const char field_name[], - absl::string_view value_text) { + void AppendFieldAndValue(const char field_name[], StringPiece value_text) { StrAppend(output_, level_empty_ ? "" : field_separator_, indent_, field_name, kColonSeparator, value_text); level_empty_ = false; @@ -133,7 +131,7 @@ inline void ProtoSpaceAndComments(Scanner* scanner) { // failed. template <typename T> bool ProtoParseNumericFromScanner(Scanner* scanner, T* value) { - absl::string_view numeric_str; + StringPiece numeric_str; scanner->RestartCapture(); if (!scanner->Many(Scanner::LETTER_DIGIT_DOT_PLUS_MINUS) .GetResult(nullptr, &numeric_str)) { diff --git a/tensorflow/core/lib/strings/scanner.cc b/tensorflow/core/lib/strings/scanner.cc index 46d3858e309..39a2265aa27 100644 --- a/tensorflow/core/lib/strings/scanner.cc +++ b/tensorflow/core/lib/strings/scanner.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/lib/strings/scanner.h" -#include "absl/strings/string_view.h" namespace tensorflow { namespace strings { @@ -42,8 +41,7 @@ void Scanner::ScanUntilImpl(char end_ch, bool escaped) { } } -bool Scanner::GetResult(absl::string_view* remaining, - absl::string_view* capture) { +bool Scanner::GetResult(StringPiece* remaining, StringPiece* capture) { if (error_) { return false; } @@ -52,7 +50,7 @@ bool Scanner::GetResult(absl::string_view* remaining, } if (capture != nullptr) { const char* end = capture_end_ == nullptr ? cur_.data() : capture_end_; - *capture = absl::string_view(capture_start_, end - capture_start_); + *capture = StringPiece(capture_start_, end - capture_start_); } return true; } diff --git a/tensorflow/core/lib/strings/scanner.h b/tensorflow/core/lib/strings/scanner.h index 4a28cbf5aa2..c82e771368c 100644 --- a/tensorflow/core/lib/strings/scanner.h +++ b/tensorflow/core/lib/strings/scanner.h @@ -17,7 +17,7 @@ limitations under the License. #define TENSORFLOW_LIB_STRINGS_SCANNER_H_ #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/macros.h" @@ -61,9 +61,7 @@ class Scanner { UPPERLETTER, }; - explicit Scanner(absl::string_view source) : cur_(source) { - RestartCapture(); - } + explicit Scanner(StringPiece source) : cur_(source) { RestartCapture(); } // Consume the next character of the given class from input. If the next // character is not in the class, then GetResult will ultimately return false. @@ -77,14 +75,14 @@ class Scanner { // Consume the next s.size() characters of the input, if they match <s>. If // they don't match <s>, this is a no-op. - Scanner& ZeroOrOneLiteral(absl::string_view s) { + Scanner& ZeroOrOneLiteral(StringPiece s) { str_util::ConsumePrefix(&cur_, s); return *this; } // Consume the next s.size() characters of the input, if they match <s>. If // they don't match <s>, then GetResult will ultimately return false. - Scanner& OneLiteral(absl::string_view s) { + Scanner& OneLiteral(StringPiece s) { if (!str_util::ConsumePrefix(&cur_, s)) { error_ = true; } @@ -161,8 +159,8 @@ class Scanner { // Returns true if the input string successfully matched. When true is // returned, the remaining string is returned in <remaining> and the captured // string returned in <capture>, if non-NULL. - bool GetResult(absl::string_view* remaining = nullptr, - absl::string_view* capture = nullptr); + bool GetResult(StringPiece* remaining = nullptr, + StringPiece* capture = nullptr); private: void ScanUntilImpl(char end_ch, bool escaped); @@ -228,7 +226,7 @@ class Scanner { return false; } - absl::string_view cur_; + StringPiece cur_; const char* capture_start_ = nullptr; const char* capture_end_ = nullptr; bool error_ = false; diff --git a/tensorflow/core/lib/strings/scanner_test.cc b/tensorflow/core/lib/strings/scanner_test.cc index 79084ed4d65..b0f568a03e1 100644 --- a/tensorflow/core/lib/strings/scanner_test.cc +++ b/tensorflow/core/lib/strings/scanner_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/lib/strings/scanner.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -37,7 +36,7 @@ class ScannerTest : public ::testing::Test { }; TEST_F(ScannerTest, Any) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner(" horse0123") .Any(Scanner::SPACE) .Any(Scanner::DIGIT) @@ -64,7 +63,7 @@ TEST_F(ScannerTest, Any) { } TEST_F(ScannerTest, AnySpace) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner(" a b ") .AnySpace() .One(Scanner::LETTER) @@ -75,7 +74,7 @@ TEST_F(ScannerTest, AnySpace) { } TEST_F(ScannerTest, AnyEscapedNewline) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner("\\\n") .Any(Scanner::LETTER_DIGIT_UNDERSCORE) .GetResult(&remaining, &match)); @@ -84,7 +83,7 @@ TEST_F(ScannerTest, AnyEscapedNewline) { } TEST_F(ScannerTest, AnyEmptyString) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner("") .Any(Scanner::LETTER_DIGIT_UNDERSCORE) .GetResult(&remaining, &match)); @@ -100,7 +99,7 @@ TEST_F(ScannerTest, Eos) { } TEST_F(ScannerTest, Many) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner("abc").Many(Scanner::LETTER).GetResult()); EXPECT_FALSE(Scanner("0").Many(Scanner::LETTER).GetResult()); EXPECT_FALSE(Scanner("").Many(Scanner::LETTER).GetResult()); @@ -116,7 +115,7 @@ TEST_F(ScannerTest, Many) { } TEST_F(ScannerTest, One) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner("abc").One(Scanner::LETTER).GetResult()); EXPECT_FALSE(Scanner("0").One(Scanner::LETTER).GetResult()); EXPECT_FALSE(Scanner("").One(Scanner::LETTER).GetResult()); @@ -138,7 +137,7 @@ TEST_F(ScannerTest, OneLiteral) { } TEST_F(ScannerTest, ScanUntil) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner(R"(' \1 \2 \3 \' \\'rest)") .OneLiteral("'") .ScanUntil('\'') @@ -165,7 +164,7 @@ TEST_F(ScannerTest, ScanUntil) { } TEST_F(ScannerTest, ScanEscapedUntil) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE(Scanner(R"(' \1 \2 \3 \' \\'rest)") .OneLiteral("'") .ScanEscapedUntil('\'') @@ -185,7 +184,7 @@ TEST_F(ScannerTest, ScanEscapedUntil) { } TEST_F(ScannerTest, ZeroOrOneLiteral) { - absl::string_view remaining, match; + StringPiece remaining, match; EXPECT_TRUE( Scanner("abc").ZeroOrOneLiteral("abC").GetResult(&remaining, &match)); EXPECT_EQ("abc", remaining); @@ -206,7 +205,7 @@ TEST_F(ScannerTest, ZeroOrOneLiteral) { // Test output of GetResult (including the forms with optional params), // and that it can be called multiple times. TEST_F(ScannerTest, CaptureAndGetResult) { - absl::string_view remaining, match; + StringPiece remaining, match; Scanner scan(" first second"); EXPECT_TRUE(scan.Any(Scanner::SPACE) @@ -239,7 +238,7 @@ TEST_F(ScannerTest, CaptureAndGetResult) { // Tests that if StopCapture is not called, then calling GetResult, then // scanning more, then GetResult again will update the capture. TEST_F(ScannerTest, MultipleGetResultExtendsCapture) { - absl::string_view remaining, match; + StringPiece remaining, match; Scanner scan("one2three"); EXPECT_TRUE(scan.Many(Scanner::LETTER).GetResult(&remaining, &match)); @@ -256,8 +255,8 @@ TEST_F(ScannerTest, MultipleGetResultExtendsCapture) { TEST_F(ScannerTest, FailedMatchDoesntChangeResult) { // A failed match doesn't change pointers passed to GetResult. Scanner scan("name"); - absl::string_view remaining = "rem"; - absl::string_view match = "match"; + StringPiece remaining = "rem"; + StringPiece match = "match"; EXPECT_FALSE(scan.One(Scanner::SPACE).GetResult(&remaining, &match)); EXPECT_EQ("rem", remaining); EXPECT_EQ("match", match); @@ -266,8 +265,8 @@ TEST_F(ScannerTest, FailedMatchDoesntChangeResult) { TEST_F(ScannerTest, DefaultCapturesAll) { // If RestartCapture() is not called, the whole string is used. Scanner scan("a b"); - absl::string_view remaining = "rem"; - absl::string_view match = "match"; + StringPiece remaining = "rem"; + StringPiece match = "match"; EXPECT_TRUE(scan.Any(Scanner::LETTER) .AnySpace() .Any(Scanner::LETTER) diff --git a/tensorflow/core/lib/strings/str_util.cc b/tensorflow/core/lib/strings/str_util.cc index ba40916b948..3aba5ec80ef 100644 --- a/tensorflow/core/lib/strings/str_util.cc +++ b/tensorflow/core/lib/strings/str_util.cc @@ -18,7 +18,6 @@ limitations under the License. #include <ctype.h> #include <algorithm> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" @@ -28,7 +27,7 @@ namespace str_util { static char hex_char[] = "0123456789abcdef"; -string CEscape(absl::string_view src) { +string CEscape(StringPiece src) { string dest; for (unsigned char c : src) { @@ -87,7 +86,7 @@ inline int hex_digit_to_int(char c) { return x & 0xf; } -bool CUnescapeInternal(absl::string_view source, string* dest, +bool CUnescapeInternal(StringPiece source, string* dest, string::size_type* dest_len, string* error) { const char* p = source.data(); const char* end = source.end(); @@ -217,8 +216,8 @@ bool CUnescapeInternal(absl::string_view source, string* dest, } template <typename T> -bool SplitAndParseAsInts(absl::string_view text, char delim, - std::function<bool(absl::string_view, T*)> converter, +bool SplitAndParseAsInts(StringPiece text, char delim, + std::function<bool(StringPiece, T*)> converter, std::vector<T>* result) { result->clear(); std::vector<string> num_strings = Split(text, delim); @@ -232,7 +231,7 @@ bool SplitAndParseAsInts(absl::string_view text, char delim, } // namespace -bool CUnescape(absl::string_view source, string* dest, string* error) { +bool CUnescape(StringPiece source, string* dest, string* error) { dest->resize(source.size()); string::size_type dest_size; if (!CUnescapeInternal(source, dest, &dest_size, error)) { @@ -250,7 +249,7 @@ void StripTrailingWhitespace(string* s) { } // Return lower-cased version of s. -string Lowercase(absl::string_view s) { +string Lowercase(StringPiece s) { string result(s.data(), s.size()); for (char& c : result) { c = tolower(c); @@ -259,7 +258,7 @@ string Lowercase(absl::string_view s) { } // Return upper-cased version of s. -string Uppercase(absl::string_view s) { +string Uppercase(StringPiece s) { string result(s.data(), s.size()); for (char& c : result) { c = toupper(c); @@ -267,7 +266,7 @@ string Uppercase(absl::string_view s) { return result; } -string ArgDefCase(absl::string_view s) { +string ArgDefCase(StringPiece s) { const size_t n = s.size(); // Compute the size of resulting string. @@ -319,18 +318,18 @@ string ArgDefCase(absl::string_view s) { return result; } -void TitlecaseString(string* s, absl::string_view delimiters) { +void TitlecaseString(string* s, StringPiece delimiters) { bool upper = true; for (string::iterator ss = s->begin(); ss != s->end(); ++ss) { if (upper) { *ss = toupper(*ss); } - upper = (delimiters.find(*ss) != absl::string_view::npos); + upper = (delimiters.find(*ss) != StringPiece::npos); } } -string StringReplace(absl::string_view s, absl::string_view oldsub, - absl::string_view newsub, bool replace_all) { +string StringReplace(StringPiece s, StringPiece oldsub, StringPiece newsub, + bool replace_all) { // TODO(jlebar): We could avoid having to shift data around in the string if // we had a StringPiece::find() overload that searched for a StringPiece. string res(s); @@ -348,7 +347,7 @@ string StringReplace(absl::string_view s, absl::string_view oldsub, return res; } -size_t RemoveLeadingWhitespace(absl::string_view* text) { +size_t RemoveLeadingWhitespace(StringPiece* text) { size_t count = 0; const char* ptr = text->data(); while (count < text->size() && isspace(*ptr)) { @@ -359,7 +358,7 @@ size_t RemoveLeadingWhitespace(absl::string_view* text) { return count; } -size_t RemoveTrailingWhitespace(absl::string_view* text) { +size_t RemoveTrailingWhitespace(StringPiece* text) { size_t count = 0; const char* ptr = text->data() + text->size() - 1; while (count < text->size() && isspace(*ptr)) { @@ -370,12 +369,12 @@ size_t RemoveTrailingWhitespace(absl::string_view* text) { return count; } -size_t RemoveWhitespaceContext(absl::string_view* text) { +size_t RemoveWhitespaceContext(StringPiece* text) { // use RemoveLeadingWhitespace() and RemoveTrailingWhitespace() to do the job return (RemoveLeadingWhitespace(text) + RemoveTrailingWhitespace(text)); } -bool ConsumePrefix(absl::string_view* s, absl::string_view expected) { +bool ConsumePrefix(StringPiece* s, StringPiece expected) { if (StartsWith(*s, expected)) { s->remove_prefix(expected.size()); return true; @@ -383,7 +382,7 @@ bool ConsumePrefix(absl::string_view* s, absl::string_view expected) { return false; } -bool ConsumeSuffix(absl::string_view* s, absl::string_view expected) { +bool ConsumeSuffix(StringPiece* s, StringPiece expected) { if (EndsWith(*s, expected)) { s->remove_suffix(expected.size()); return true; @@ -391,7 +390,7 @@ bool ConsumeSuffix(absl::string_view* s, absl::string_view expected) { return false; } -bool ConsumeLeadingDigits(absl::string_view* s, uint64* val) { +bool ConsumeLeadingDigits(StringPiece* s, uint64* val) { const char* p = s->data(); const char* limit = p + s->size(); uint64 v = 0; @@ -416,7 +415,7 @@ bool ConsumeLeadingDigits(absl::string_view* s, uint64* val) { } } -bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val) { +bool ConsumeNonWhitespace(StringPiece* s, StringPiece* val) { const char* p = s->data(); const char* limit = p + s->size(); while (p < limit) { @@ -426,29 +425,29 @@ bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val) { } const size_t n = p - s->data(); if (n > 0) { - *val = absl::string_view(s->data(), n); + *val = StringPiece(s->data(), n); s->remove_prefix(n); return true; } else { - *val = absl::string_view(); + *val = StringPiece(); return false; } } -bool SplitAndParseAsInts(absl::string_view text, char delim, +bool SplitAndParseAsInts(StringPiece text, char delim, std::vector<int32>* result) { return SplitAndParseAsInts<int32>(text, delim, strings::safe_strto32, result); } -bool SplitAndParseAsInts(absl::string_view text, char delim, +bool SplitAndParseAsInts(StringPiece text, char delim, std::vector<int64>* result) { return SplitAndParseAsInts<int64>(text, delim, strings::safe_strto64, result); } -bool SplitAndParseAsFloats(absl::string_view text, char delim, +bool SplitAndParseAsFloats(StringPiece text, char delim, std::vector<float>* result) { return SplitAndParseAsInts<float>(text, delim, - [](absl::string_view str, float* value) { + [](StringPiece str, float* value) { return strings::safe_strtof(str, value); }, result); @@ -462,18 +461,18 @@ size_t Strnlen(const char* str, const size_t string_max_len) { return len; } -bool StrContains(absl::string_view haystack, absl::string_view needle) { +bool StrContains(StringPiece haystack, StringPiece needle) { return std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end()) != haystack.end(); } -bool StartsWith(absl::string_view text, absl::string_view prefix) { +bool StartsWith(StringPiece text, StringPiece prefix) { return prefix.empty() || (text.size() >= prefix.size() && memcmp(text.data(), prefix.data(), prefix.size()) == 0); } -bool EndsWith(absl::string_view text, absl::string_view suffix) { +bool EndsWith(StringPiece text, StringPiece suffix) { return suffix.empty() || (text.size() >= suffix.size() && memcmp(text.data() + (text.size() - suffix.size()), suffix.data(), suffix.size()) == 0); diff --git a/tensorflow/core/lib/strings/str_util.h b/tensorflow/core/lib/strings/str_util.h index a00434534e0..9f52cf29fc3 100644 --- a/tensorflow/core/lib/strings/str_util.h +++ b/tensorflow/core/lib/strings/str_util.h @@ -19,7 +19,7 @@ limitations under the License. #include <functional> #include <string> #include <vector> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/types.h" @@ -29,7 +29,7 @@ namespace str_util { // Returns a version of 'src' where unprintable characters have been // escaped using C-style escape sequences. -string CEscape(absl::string_view src); +string CEscape(StringPiece src); // Copies "source" to "dest", rewriting C-style escape sequences -- // '\n', '\r', '\\', '\ooo', etc -- to their ASCII equivalents. @@ -38,47 +38,47 @@ string CEscape(absl::string_view src); // 'error'. To disable error reporting, set 'error' to NULL. // // NOTE: Does not support \u or \U! -bool CUnescape(absl::string_view source, string* dest, string* error); +bool CUnescape(StringPiece source, string* dest, string* error); // Removes any trailing whitespace from "*s". void StripTrailingWhitespace(string* s); // Removes leading ascii_isspace() characters. // Returns number of characters removed. -size_t RemoveLeadingWhitespace(absl::string_view* text); +size_t RemoveLeadingWhitespace(StringPiece* text); // Removes trailing ascii_isspace() characters. // Returns number of characters removed. -size_t RemoveTrailingWhitespace(absl::string_view* text); +size_t RemoveTrailingWhitespace(StringPiece* text); // Removes leading and trailing ascii_isspace() chars. // Returns number of chars removed. -size_t RemoveWhitespaceContext(absl::string_view* text); +size_t RemoveWhitespaceContext(StringPiece* text); // Consume a leading positive integer value. If any digits were // found, store the value of the leading unsigned number in "*val", // advance "*s" past the consumed number, and return true. If // overflow occurred, returns false. Otherwise, returns false. -bool ConsumeLeadingDigits(absl::string_view* s, uint64* val); +bool ConsumeLeadingDigits(StringPiece* s, uint64* val); // Consume a leading token composed of non-whitespace characters only. // If *s starts with a non-zero number of non-whitespace characters, store // them in *val, advance *s past them, and return true. Else return false. -bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val); +bool ConsumeNonWhitespace(StringPiece* s, StringPiece* val); // If "*s" starts with "expected", consume it and return true. // Otherwise, return false. -bool ConsumePrefix(absl::string_view* s, absl::string_view expected); +bool ConsumePrefix(StringPiece* s, StringPiece expected); // If "*s" ends with "expected", remove it and return true. // Otherwise, return false. -bool ConsumeSuffix(absl::string_view* s, absl::string_view expected); +bool ConsumeSuffix(StringPiece* s, StringPiece expected); // Return lower-cased version of s. -string Lowercase(absl::string_view s); +string Lowercase(StringPiece s); // Return upper-cased version of s. -string Uppercase(absl::string_view s); +string Uppercase(StringPiece s); // Converts "^2ILoveYou!" to "i_love_you_". More specifically: // - converts all non-alphanumeric characters to underscores @@ -89,16 +89,16 @@ string Uppercase(absl::string_view s); // This method is useful for producing strings matching "[a-z][a-z0-9_]*" // as required by OpDef.ArgDef.name. The resulting string is either empty or // matches this regex. -string ArgDefCase(absl::string_view s); +string ArgDefCase(StringPiece s); // Capitalize first character of each word in "*s". "delimiters" is a // set of characters that can be used as word boundaries. -void TitlecaseString(string* s, absl::string_view delimiters); +void TitlecaseString(string* s, StringPiece delimiters); // Replaces the first occurrence (if replace_all is false) or all occurrences // (if replace_all is true) of oldsub in s with newsub. -string StringReplace(absl::string_view s, absl::string_view oldsub, - absl::string_view newsub, bool replace_all); +string StringReplace(StringPiece s, StringPiece oldsub, StringPiece newsub, + bool replace_all); // Join functionality template <typename T> @@ -111,13 +111,13 @@ template <typename T, typename Formatter> string Join(const T& s, const char* sep, Formatter f); struct AllowEmpty { - bool operator()(absl::string_view sp) const { return true; } + bool operator()(StringPiece sp) const { return true; } }; struct SkipEmpty { - bool operator()(absl::string_view sp) const { return !sp.empty(); } + bool operator()(StringPiece sp) const { return !sp.empty(); } }; struct SkipWhitespace { - bool operator()(absl::string_view sp) const { + bool operator()(StringPiece sp) const { RemoveTrailingWhitespace(&sp); return !sp.empty(); } @@ -125,36 +125,35 @@ struct SkipWhitespace { // Split strings using any of the supplied delimiters. For example: // Split("a,b.c,d", ".,") would return {"a", "b", "c", "d"}. -std::vector<string> Split(absl::string_view text, absl::string_view delims); +std::vector<string> Split(StringPiece text, StringPiece delims); template <typename Predicate> -std::vector<string> Split(absl::string_view text, absl::string_view delims, - Predicate p); +std::vector<string> Split(StringPiece text, StringPiece delims, Predicate p); // Split "text" at "delim" characters, and parse each component as // an integer. If successful, adds the individual numbers in order // to "*result" and returns true. Otherwise returns false. -bool SplitAndParseAsInts(absl::string_view text, char delim, +bool SplitAndParseAsInts(StringPiece text, char delim, std::vector<int32>* result); -bool SplitAndParseAsInts(absl::string_view text, char delim, +bool SplitAndParseAsInts(StringPiece text, char delim, std::vector<int64>* result); -bool SplitAndParseAsFloats(absl::string_view text, char delim, +bool SplitAndParseAsFloats(StringPiece text, char delim, std::vector<float>* result); // StartsWith() // // Returns whether a given string `text` begins with `prefix`. -bool StartsWith(absl::string_view text, absl::string_view prefix); +bool StartsWith(StringPiece text, StringPiece prefix); // EndsWith() // // Returns whether a given string `text` ends with `suffix`. -bool EndsWith(absl::string_view text, absl::string_view suffix); +bool EndsWith(StringPiece text, StringPiece suffix); // StrContains() // // Returns whether a given string `haystack` contains the substring `needle`. -bool StrContains(absl::string_view haystack, absl::string_view needle); +bool StrContains(StringPiece haystack, StringPiece needle); // ------------------------------------------------------------------ // Implementation details below @@ -193,21 +192,18 @@ string Join(const T& s, const char* sep, Formatter f) { return result; } -inline std::vector<string> Split(absl::string_view text, - absl::string_view delims) { +inline std::vector<string> Split(StringPiece text, StringPiece delims) { return Split(text, delims, AllowEmpty()); } template <typename Predicate> -std::vector<string> Split(absl::string_view text, absl::string_view delims, - Predicate p) { +std::vector<string> Split(StringPiece text, StringPiece delims, Predicate p) { std::vector<string> result; size_t token_start = 0; if (!text.empty()) { for (size_t i = 0; i < text.size() + 1; i++) { - if ((i == text.size()) || - (delims.find(text[i]) != absl::string_view::npos)) { - absl::string_view token(text.data() + token_start, i - token_start); + if ((i == text.size()) || (delims.find(text[i]) != StringPiece::npos)) { + StringPiece token(text.data() + token_start, i - token_start); if (p(token)) { result.emplace_back(token); } @@ -218,13 +214,13 @@ std::vector<string> Split(absl::string_view text, absl::string_view delims, return result; } -inline std::vector<string> Split(absl::string_view text, char delim) { - return Split(text, absl::string_view(&delim, 1)); +inline std::vector<string> Split(StringPiece text, char delim) { + return Split(text, StringPiece(&delim, 1)); } template <typename Predicate> -std::vector<string> Split(absl::string_view text, char delims, Predicate p) { - return Split(text, absl::string_view(&delims, 1), p); +std::vector<string> Split(StringPiece text, char delims, Predicate p) { + return Split(text, StringPiece(&delims, 1), p); } // Returns the length of the given null-terminated byte string 'str'. diff --git a/tensorflow/core/lib/strings/str_util_test.cc b/tensorflow/core/lib/strings/str_util_test.cc index 38157d60a5e..3bf3e99825f 100644 --- a/tensorflow/core/lib/strings/str_util_test.cc +++ b/tensorflow/core/lib/strings/str_util_test.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/lib/strings/str_util.h" #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -29,7 +28,7 @@ TEST(CEscape, Basic) { EXPECT_EQ(str_util::CEscape("\320hi\200"), "\\320hi\\200"); } -string ExpectCUnescapeSuccess(absl::string_view source) { +string ExpectCUnescapeSuccess(StringPiece source) { string dest; string error; EXPECT_TRUE(str_util::CUnescape(source, &dest, &error)) << error; @@ -50,7 +49,7 @@ TEST(CUnescape, HandlesCopyOnWriteStrings) { // For std::string, read and dest now share the same buffer. string error; - absl::string_view source = "llohe"; + StringPiece source = "llohe"; // CUnescape is going to write "llohe" to dest, so dest's buffer will be // reallocated, and read's buffer remains untouched. EXPECT_TRUE(str_util::CUnescape(source, &dest, &error)); @@ -82,71 +81,71 @@ TEST(StripTrailingWhitespace, Basic) { TEST(RemoveLeadingWhitespace, Basic) { string text = " \t \n \r Quick\t"; - absl::string_view data(text); + StringPiece data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 11); - EXPECT_EQ(data, absl::string_view("Quick\t")); + EXPECT_EQ(data, StringPiece("Quick\t")); // check that non-whitespace is not removed EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 0); - EXPECT_EQ(data, absl::string_view("Quick\t")); + EXPECT_EQ(data, StringPiece("Quick\t")); } TEST(RemoveLeadingWhitespace, TerminationHandling) { // check termination handling string text = "\t"; - absl::string_view data(text); + StringPiece data(text); EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 1); - EXPECT_EQ(data, absl::string_view("")); + EXPECT_EQ(data, StringPiece("")); // check termination handling again EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 0); - EXPECT_EQ(data, absl::string_view("")); + EXPECT_EQ(data, StringPiece("")); } TEST(RemoveTrailingWhitespace, Basic) { string text = " \t \n \r Quick \t"; - absl::string_view data(text); + StringPiece data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 2); - EXPECT_EQ(data, absl::string_view(" \t \n \r Quick")); + EXPECT_EQ(data, StringPiece(" \t \n \r Quick")); // check that non-whitespace is not removed EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 0); - EXPECT_EQ(data, absl::string_view(" \t \n \r Quick")); + EXPECT_EQ(data, StringPiece(" \t \n \r Quick")); } TEST(RemoveTrailingWhitespace, TerminationHandling) { // check termination handling string text = "\t"; - absl::string_view data(text); + StringPiece data(text); EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 1); - EXPECT_EQ(data, absl::string_view("")); + EXPECT_EQ(data, StringPiece("")); // check termination handling again EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 0); - EXPECT_EQ(data, absl::string_view("")); + EXPECT_EQ(data, StringPiece("")); } TEST(RemoveWhitespaceContext, Basic) { string text = " \t \n \r Quick \t"; - absl::string_view data(text); + StringPiece data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveWhitespaceContext(&data), 13); - EXPECT_EQ(data, absl::string_view("Quick")); + EXPECT_EQ(data, StringPiece("Quick")); // check that non-whitespace is not removed EXPECT_EQ(str_util::RemoveWhitespaceContext(&data), 0); - EXPECT_EQ(data, absl::string_view("Quick")); + EXPECT_EQ(data, StringPiece("Quick")); // Test empty string text = ""; data = text; EXPECT_EQ(str_util::RemoveWhitespaceContext(&data), 0); - EXPECT_EQ(data, absl::string_view("")); + EXPECT_EQ(data, StringPiece("")); } -void TestConsumeLeadingDigits(absl::string_view s, int64 expected, - absl::string_view remaining) { +void TestConsumeLeadingDigits(StringPiece s, int64 expected, + StringPiece remaining) { uint64 v; - absl::string_view input(s); + StringPiece input(s); if (str_util::ConsumeLeadingDigits(&input, &v)) { EXPECT_EQ(v, static_cast<uint64>(expected)); EXPECT_EQ(input, remaining); @@ -179,10 +178,10 @@ TEST(ConsumeLeadingDigits, Basic) { "184467440737095516159yz"); } -void TestConsumeNonWhitespace(absl::string_view s, absl::string_view expected, - absl::string_view remaining) { - absl::string_view v; - absl::string_view input(s); +void TestConsumeNonWhitespace(StringPiece s, StringPiece expected, + StringPiece remaining) { + StringPiece v; + StringPiece input(s); if (str_util::ConsumeNonWhitespace(&input, &v)) { EXPECT_EQ(v, expected); EXPECT_EQ(input, remaining); @@ -201,7 +200,7 @@ TEST(ConsumeNonWhitespace, Basic) { TEST(ConsumePrefix, Basic) { string s("abcdef"); - absl::string_view input(s); + StringPiece input(s); EXPECT_FALSE(str_util::ConsumePrefix(&input, "abcdefg")); EXPECT_EQ(input, "abcdef"); @@ -229,7 +228,7 @@ TEST(JoinStrings, Basic) { s = {"hi", "there", "strings"}; EXPECT_EQ(str_util::Join(s, " "), "hi there strings"); - std::vector<absl::string_view> sp; + std::vector<StringPiece> sp; sp = {"hi"}; EXPECT_EQ(str_util::Join(sp, ",,"), "hi"); sp = {"hi", "there", "strings"}; diff --git a/tensorflow/core/lib/strings/strcat.cc b/tensorflow/core/lib/strings/strcat.cc index fd708b837d0..f140ec3d260 100644 --- a/tensorflow/core/lib/strings/strcat.cc +++ b/tensorflow/core/lib/strings/strcat.cc @@ -20,7 +20,6 @@ limitations under the License. #include <stdio.h> #include <string.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/platform/logging.h" @@ -42,7 +41,7 @@ AlphaNum::AlphaNum(Hex hex) { value >>= 4; mask >>= 4; } while (mask != 0); - piece_ = absl::string_view(writer, end - writer); + piece_ = StringPiece(writer, end - writer); } // ---------------------------------------------------------------------- @@ -118,15 +117,15 @@ string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, namespace internal { // Do not call directly - these are not part of the public API. -string CatPieces(std::initializer_list<absl::string_view> pieces) { +string CatPieces(std::initializer_list<StringPiece> pieces) { string result; size_t total_size = 0; - for (const absl::string_view piece : pieces) total_size += piece.size(); + for (const StringPiece piece : pieces) total_size += piece.size(); gtl::STLStringResizeUninitialized(&result, total_size); char *const begin = &*result.begin(); char *out = begin; - for (const absl::string_view piece : pieces) { + for (const StringPiece piece : pieces) { const size_t this_size = piece.size(); memcpy(out, piece.data(), this_size); out += this_size; @@ -142,11 +141,10 @@ string CatPieces(std::initializer_list<absl::string_view> pieces) { #define DCHECK_NO_OVERLAP(dest, src) \ DCHECK_GE(uintptr_t((src).data() - (dest).data()), uintptr_t((dest).size())) -void AppendPieces(string *result, - std::initializer_list<absl::string_view> pieces) { +void AppendPieces(string *result, std::initializer_list<StringPiece> pieces) { size_t old_size = result->size(); size_t total_size = old_size; - for (const absl::string_view piece : pieces) { + for (const StringPiece piece : pieces) { DCHECK_NO_OVERLAP(*result, piece); total_size += piece.size(); } @@ -154,7 +152,7 @@ void AppendPieces(string *result, char *const begin = &*result->begin(); char *out = begin + old_size; - for (const absl::string_view piece : pieces) { + for (const StringPiece piece : pieces) { const size_t this_size = piece.size(); memcpy(out, piece.data(), this_size); out += this_size; diff --git a/tensorflow/core/lib/strings/strcat.h b/tensorflow/core/lib/strings/strcat.h index 1c7cb68c406..a620f594476 100644 --- a/tensorflow/core/lib/strings/strcat.h +++ b/tensorflow/core/lib/strings/strcat.h @@ -22,7 +22,7 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/types.h" @@ -121,20 +121,19 @@ class AlphaNum { AlphaNum(Hex hex); // NOLINT(runtime/explicit) AlphaNum(const char *c_str) : piece_(c_str) {} // NOLINT(runtime/explicit) - AlphaNum(const absl::string_view &pc) - : piece_(pc) {} // NOLINT(runtime/explicit) + 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) - absl::string_view::size_type size() const { return piece_.size(); } + StringPiece::size_type size() const { return piece_.size(); } const char *data() const { return piece_.data(); } - absl::string_view Piece() const { return piece_; } + StringPiece Piece() const { return piece_; } private: - absl::string_view piece_; + StringPiece piece_; char digits_[kFastToBufferSize]; // Use ":" not ':' @@ -177,9 +176,8 @@ string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, namespace internal { // Do not call directly - this is not part of the public API. -string CatPieces(std::initializer_list<absl::string_view> pieces); -void AppendPieces(string *dest, - std::initializer_list<absl::string_view> pieces); +string CatPieces(std::initializer_list<StringPiece> pieces); +void AppendPieces(string *dest, std::initializer_list<StringPiece> pieces); } // namespace internal diff --git a/tensorflow/core/lib/strings/strcat_test.cc b/tensorflow/core/lib/strings/strcat_test.cc index 2e06bd0eb8d..6c4e5526b11 100644 --- a/tensorflow/core/lib/strings/strcat_test.cc +++ b/tensorflow/core/lib/strings/strcat_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/types.h" @@ -67,7 +66,7 @@ TEST(StrCat, Basics) { string strs[] = {"Hello", "Cruel", "World"}; - absl::string_view pieces[] = {"Hello", "Cruel", "World"}; + StringPiece pieces[] = {"Hello", "Cruel", "World"}; const char *c_strs[] = {"Hello", "Cruel", "World"}; @@ -209,7 +208,7 @@ TEST(StrAppend, Basics) { string strs[] = {"Hello", "Cruel", "World"}; - absl::string_view pieces[] = {"Hello", "Cruel", "World"}; + StringPiece pieces[] = {"Hello", "Cruel", "World"}; const char *c_strs[] = {"Hello", "Cruel", "World"}; diff --git a/tensorflow/core/platform/cloud/BUILD b/tensorflow/core/platform/cloud/BUILD index 47265051190..647a797b82c 100644 --- a/tensorflow/core/platform/cloud/BUILD +++ b/tensorflow/core/platform/cloud/BUILD @@ -89,7 +89,6 @@ cc_library( "//tensorflow/core:framework_headers_lib", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", "@jsoncpp_git//:jsoncpp", ], alwayslink = 1, @@ -116,7 +115,6 @@ cc_library( ":http_request", "//tensorflow/core:framework_headers_lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", "@curl", ], ) @@ -134,7 +132,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:test", - "@com_google_absl//absl/strings", "@curl", ], ) @@ -154,7 +151,6 @@ cc_library( ":retrying_utils", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", "@jsoncpp_git//:jsoncpp", ], ) @@ -193,7 +189,6 @@ cc_library( ":compute_engine_metadata_client", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) @@ -225,7 +220,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "@boringssl//:crypto", - "@com_google_absl//absl/strings", "@jsoncpp_git//:jsoncpp", ], ) @@ -255,7 +249,6 @@ cc_library( ":retrying_utils", "//tensorflow/core:framework_headers_lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) @@ -311,7 +304,6 @@ tf_cc_test( "//tensorflow/core:lib", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) @@ -350,7 +342,6 @@ tf_cc_test( "//tensorflow/core:lib", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) @@ -370,7 +361,6 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "@boringssl//:crypto", - "@com_google_absl//absl/strings", ], ) @@ -390,7 +380,6 @@ tf_cc_test( "//tensorflow/core:lib_internal", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) @@ -432,7 +421,6 @@ tf_cc_test( "//tensorflow/core:lib_internal", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/platform/cloud/compute_engine_zone_provider.cc b/tensorflow/core/platform/cloud/compute_engine_zone_provider.cc index c406ba0eae9..e147d883710 100644 --- a/tensorflow/core/platform/cloud/compute_engine_zone_provider.cc +++ b/tensorflow/core/platform/cloud/compute_engine_zone_provider.cc @@ -16,7 +16,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/compute_engine_zone_provider.h" #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -36,7 +35,7 @@ Status ComputeEngineZoneProvider::GetZone(string* zone) { std::vector<char> response_buffer; TF_RETURN_IF_ERROR(google_metadata_client_->GetMetadata(kGceMetadataZonePath, &response_buffer)); - absl::string_view location(&response_buffer[0], response_buffer.size()); + StringPiece location(&response_buffer[0], response_buffer.size()); std::vector<string> elems = str_util::Split(location, "/"); if (elems.size() == 4) { diff --git a/tensorflow/core/platform/cloud/curl_http_request.cc b/tensorflow/core/platform/cloud/curl_http_request.cc index 6f85514fa84..5e1eabee5b0 100644 --- a/tensorflow/core/platform/cloud/curl_http_request.cc +++ b/tensorflow/core/platform/cloud/curl_http_request.cc @@ -15,7 +15,6 @@ limitations under the License. #include <algorithm> -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/cloud/curl_http_request.h" #include "tensorflow/core/lib/core/errors.h" @@ -276,7 +275,7 @@ void CurlHttpRequest::SetPostFromBuffer(const char* buffer, size_t size) { reinterpret_cast<void*>(this))); CHECK_CURL_OK(libcurl_->curl_easy_setopt(curl_, CURLOPT_READFUNCTION, &CurlHttpRequest::ReadCallback)); - post_body_buffer_ = absl::string_view(buffer, size); + post_body_buffer_ = StringPiece(buffer, size); } void CurlHttpRequest::SetPostEmptyBody() { @@ -387,8 +386,8 @@ size_t CurlHttpRequest::HeaderCallback(const void* ptr, size_t size, size_t nmemb, void* this_object) { CHECK(ptr); auto that = reinterpret_cast<CurlHttpRequest*>(this_object); - absl::string_view header(reinterpret_cast<const char*>(ptr), size * nmemb); - absl::string_view name, value; + StringPiece header(reinterpret_cast<const char*>(ptr), size * nmemb); + StringPiece name, value; // The supplied header has the form "<name>: <value>", parse it. if (strings::Scanner(header) .ScanEscapedUntil(':') @@ -447,7 +446,7 @@ Status CurlHttpRequest::Send() { auto get_error_message = [this]() -> string { string error_message = strings::StrCat( "Error executing an HTTP request: HTTP response code ", response_code_); - absl::string_view body = GetResponse(); + StringPiece body = GetResponse(); if (!body.empty()) { return strings::StrCat( error_message, " with body '", @@ -543,14 +542,13 @@ void CurlHttpRequest::CheckNotSent() const { CHECK(!is_sent_) << "The request has already been sent."; } -absl::string_view CurlHttpRequest::GetResponse() const { - absl::string_view response; +StringPiece CurlHttpRequest::GetResponse() const { + StringPiece response; if (IsDirectResponse()) { - response = absl::string_view(direct_response_.buffer_, - direct_response_.bytes_transferred_); + response = StringPiece(direct_response_.buffer_, + direct_response_.bytes_transferred_); } else { - response = - absl::string_view(response_buffer_->data(), response_buffer_->size()); + response = StringPiece(response_buffer_->data(), response_buffer_->size()); } return response; } diff --git a/tensorflow/core/platform/cloud/curl_http_request.h b/tensorflow/core/platform/cloud/curl_http_request.h index 22ae5d96878..1b2029926d6 100644 --- a/tensorflow/core/platform/cloud/curl_http_request.h +++ b/tensorflow/core/platform/cloud/curl_http_request.h @@ -19,10 +19,10 @@ limitations under the License. #include <string> #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #include <curl/curl.h> #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/cloud/http_request.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/macros.h" @@ -165,7 +165,7 @@ class CurlHttpRequest : public HttpRequest { curl_off_t ulnow); void CheckMethodNotSet() const; void CheckNotSent() const; - absl::string_view GetResponse() const; + StringPiece GetResponse() const; /// Helper to convert the given CURLcode and error buffer, representing the /// result of performing a transfer, into a Status with an error message. @@ -176,7 +176,7 @@ class CurlHttpRequest : public HttpRequest { FILE* put_body_ = nullptr; - absl::string_view post_body_buffer_; + StringPiece post_body_buffer_; size_t post_body_read_ = 0; std::vector<char>* response_buffer_ = nullptr; diff --git a/tensorflow/core/platform/cloud/curl_http_request_test.cc b/tensorflow/core/platform/cloud/curl_http_request_test.cc index e5f92d6ec87..eb9023d7089 100644 --- a/tensorflow/core/platform/cloud/curl_http_request_test.cc +++ b/tensorflow/core/platform/cloud/curl_http_request_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/curl_http_request.h" #include <fstream> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/platform/mem.h" @@ -145,8 +144,8 @@ class FakeLibCurl : public LibCurl { posted_content_ = ""; do { bytes_read = read_callback_(buffer, 1, sizeof(buffer), read_data_); - posted_content_ = strings::StrCat( - posted_content_, absl::string_view(buffer, bytes_read)); + posted_content_ = + strings::StrCat(posted_content_, StringPiece(buffer, bytes_read)); } while (bytes_read > 0); } if (write_data_ || write_callback_) { diff --git a/tensorflow/core/platform/cloud/gcs_file_system.cc b/tensorflow/core/platform/cloud/gcs_file_system.cc index 1b8c738edbe..c61b68aeebf 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system.cc @@ -22,7 +22,6 @@ limitations under the License. #include <cstring> #include <fstream> #include <vector> -#include "absl/strings/string_view.h" #ifdef _WIN32 #include <io.h> // for _mktemp #endif @@ -173,9 +172,9 @@ Status GetTmpFilename(string* filename) { /// "bucket-name" and "path/to/file.txt". /// If fname only contains the bucket and empty_object_ok = true, the returned /// object is empty. -Status ParseGcsPath(absl::string_view fname, bool empty_object_ok, - string* bucket, string* object) { - absl::string_view scheme, bucketp, objectp; +Status ParseGcsPath(StringPiece fname, bool empty_object_ok, string* bucket, + string* object) { + StringPiece scheme, bucketp, objectp; io::ParseURI(fname, &scheme, &bucketp, &objectp); if (scheme != "gs") { return errors::InvalidArgument("GCS path doesn't start with 'gs://': ", @@ -224,7 +223,7 @@ std::set<string> AddAllSubpaths(const std::vector<string>& paths) { std::set<string> result; result.insert(paths.begin(), paths.end()); for (const string& path : paths) { - absl::string_view subpath = io::Dirname(path); + StringPiece subpath = io::Dirname(path); while (!subpath.empty()) { result.emplace(string(subpath)); subpath = io::Dirname(subpath); @@ -233,7 +232,7 @@ std::set<string> AddAllSubpaths(const std::vector<string>& paths) { return result; } -Status ParseJson(absl::string_view json, Json::Value* result) { +Status ParseJson(StringPiece json, Json::Value* result) { Json::Reader reader; if (!reader.parse(json.data(), json.data() + json.size(), *result)) { return errors::Internal("Couldn't parse JSON response from GCS."); @@ -242,7 +241,7 @@ Status ParseJson(absl::string_view json, Json::Value* result) { } Status ParseJson(const std::vector<char>& json, Json::Value* result) { - return ParseJson(absl::string_view{json.data(), json.size()}, result); + return ParseJson(StringPiece{json.data(), json.size()}, result); } /// Reads a JSON value with the given name from a parent JSON value. @@ -306,13 +305,13 @@ class GcsRandomAccessFile : public RandomAccessFile { public: using ReadFn = std::function<Status(const string& filename, uint64 offset, size_t n, - absl::string_view* result, char* scratch)>; + StringPiece* result, char* scratch)>; GcsRandomAccessFile(const string& filename, ReadFn read_fn) : filename_(filename), read_fn_(std::move(read_fn)) {} /// The implementation of reads with an LRU block cache. Thread safe. - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { return read_fn_(filename_, offset, n, result, scratch); } @@ -373,7 +372,7 @@ class GcsWritableFile : public WritableFile { ~GcsWritableFile() override { Close().IgnoreError(); } - Status Append(absl::string_view data) override { + Status Append(StringPiece data) override { TF_RETURN_IF_ERROR(CheckWritable()); sync_needed_ = true; outfile_ << data; @@ -531,7 +530,7 @@ class GcsWritableFile : public WritableFile { // This means GCS doesn't have any bytes of the file yet. *uploaded = 0; } else { - absl::string_view range_piece(received_range); + StringPiece range_piece(received_range); str_util::ConsumePrefix(&range_piece, "bytes="); // May or may not be present. std::vector<int64> range_parts; @@ -605,7 +604,7 @@ class GcsReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { // Helper function to extract an environment variable and convert it into a // value of type T. template <typename T> -bool GetEnvVar(const char* varname, bool (*convert)(absl::string_view, T*), +bool GetEnvVar(const char* varname, bool (*convert)(StringPiece, T*), T* value) { const char* env_value = std::getenv(varname); if (!env_value) { @@ -614,14 +613,14 @@ bool GetEnvVar(const char* varname, bool (*convert)(absl::string_view, T*), return convert(env_value, value); } -bool StringPieceIdentity(absl::string_view str, absl::string_view* value) { +bool StringPieceIdentity(StringPiece str, StringPiece* value) { *value = str; return true; } /// \brief Utility function to split a comma delimited list of strings to an /// unordered set, lowercasing all values. -bool SplitByCommaToLowercaseSet(absl::string_view list, +bool SplitByCommaToLowercaseSet(StringPiece list, std::unordered_set<string>* set) { std::vector<string> vector = str_util::Split(tensorflow::str_util::Lowercase(list), ","); @@ -714,14 +713,14 @@ GcsFileSystem::GcsFileSystem() { } // Get the additional header - absl::string_view add_header_contents; + StringPiece add_header_contents; if (GetEnvVar(kAdditionalRequestHeader, StringPieceIdentity, &add_header_contents)) { size_t split = add_header_contents.find(':', 0); - if (split != absl::string_view::npos) { - absl::string_view header_name = add_header_contents.substr(0, split); - absl::string_view header_value = add_header_contents.substr(split + 1); + if (split != StringPiece::npos) { + StringPiece header_name = add_header_contents.substr(0, split); + StringPiece header_value = add_header_contents.substr(split + 1); if (!header_name.empty() && !header_value.empty()) { additional_header_.reset(new std::pair<const string, const string>( @@ -818,7 +817,7 @@ Status GcsFileSystem::NewRandomAccessFile( result->reset(new GcsRandomAccessFile(fname, [this, bucket, object]( const string& fname, uint64 offset, size_t n, - absl::string_view* result, + StringPiece* result, char* scratch) { tf_shared_lock l(block_cache_lock_); if (file_block_cache_->IsCacheEnabled()) { @@ -835,11 +834,11 @@ Status GcsFileSystem::NewRandomAccessFile( << fname; } } - *result = absl::string_view(); + *result = StringPiece(); size_t bytes_transferred; TF_RETURN_IF_ERROR( file_block_cache_->Read(fname, offset, n, scratch, &bytes_transferred)); - *result = absl::string_view(scratch, bytes_transferred); + *result = StringPiece(scratch, bytes_transferred); if (bytes_transferred < n) { return errors::OutOfRange("EOF reached, ", result->size(), " bytes were read out of ", n, @@ -955,7 +954,7 @@ Status GcsFileSystem::NewAppendableFile(const string& fname, std::unique_ptr<char[]> buffer(new char[kReadAppendableFileBufferSize]); Status status; uint64 offset = 0; - absl::string_view read_chunk; + StringPiece read_chunk; // Read the file from GCS in chunks and save it to a tmp file. string old_content_filename; @@ -995,7 +994,7 @@ Status GcsFileSystem::NewReadOnlyMemoryRegionFromFile( std::unique_ptr<RandomAccessFile> file; TF_RETURN_IF_ERROR(NewRandomAccessFile(fname, &file)); - absl::string_view piece; + StringPiece piece; TF_RETURN_IF_ERROR(file->Read(0, size, &piece, data.get())); result->reset(new GcsReadOnlyMemoryRegion(std::move(data), size)); @@ -1321,7 +1320,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, // The names should be relative to the 'dirname'. That means the // 'object_prefix', which is part of 'dirname', should be removed from // the beginning of 'name'. - absl::string_view relative_path(name); + StringPiece relative_path(name); if (!str_util::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal(strings::StrCat( "Unexpected response: the returned file name ", name, @@ -1350,7 +1349,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, "response."); } const string& prefix_str = prefix.asString(); - absl::string_view relative_path(prefix_str); + StringPiece relative_path(prefix_str); if (!str_util::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal( "Unexpected response: the returned folder name ", prefix_str, diff --git a/tensorflow/core/platform/cloud/gcs_file_system_test.cc b/tensorflow/core/platform/cloud/gcs_file_system_test.cc index 4903e68f3fc..702802b185a 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system_test.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/gcs_file_system.h" #include <fstream> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/cloud/http_request_fake.h" @@ -80,7 +79,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_NoBlockCache) { TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); char scratch[6]; - absl::string_view result; + StringPiece result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -234,7 +233,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_NoBlockCache_DifferentN) { TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); char small_scratch[3]; - absl::string_view result; + StringPiece result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(small_scratch), &result, small_scratch)); @@ -291,7 +290,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache) { nullptr /* gcs additional header */); char scratch[100]; - absl::string_view result; + StringPiece result; { // We are instantiating this in an enclosed scope to make sure after the // unique ptr goes out of scope, we can still access result. @@ -380,7 +379,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache_Flush) { nullptr /* gcs additional header */); char scratch[100]; - absl::string_view result; + StringPiece result; std::unique_ptr<RandomAccessFile> file; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); // Read the first chunk. The cache will be populated with the first block of @@ -429,7 +428,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache_MaxStaleness) { kTestTimeoutConfig, *kAllowedLocationsDefault, nullptr /* gcs additional header */); char scratch[100]; - absl::string_view result; + StringPiece result; // There should only be two HTTP requests issued to GCS even though we iterate // this loop 10 times. This shows that the underlying FileBlockCache persists // across file close/open boundaries. @@ -503,7 +502,7 @@ TEST(GcsFileSystemTest, TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); char scratch[5]; - absl::string_view result; + StringPiece result; // First read. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -569,7 +568,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_InconsistentRead) { TF_ASSERT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); char scratch[6]; - absl::string_view result; + StringPiece result; EXPECT_EQ(errors::Code::INTERNAL, file->Read(0, sizeof(scratch), &result, scratch).code()); @@ -632,7 +631,7 @@ TEST(GcsFileSystemTest, NewWritableFile) { std::unique_ptr<RandomAccessFile> rfile; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/path/writeable", &rfile)); char scratch[100]; - absl::string_view result; + StringPiece result; TF_EXPECT_OK(rfile->Read(0, 4, &result, scratch)); EXPECT_EQ("0123", result); // Open the writable file. @@ -792,7 +791,7 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadSucceedsOnGetStatus) { std::unique_ptr<RandomAccessFile> rfile; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/path/writeable", &rfile)); char scratch[100]; - absl::string_view result; + StringPiece result; TF_EXPECT_OK(rfile->Read(0, 4, &result, scratch)); EXPECT_EQ("0123", result); // Now write to the same file. Once the write succeeds, the cached block will @@ -1030,7 +1029,7 @@ TEST(GcsFileSystemTest, NewAppendableFile) { std::unique_ptr<RandomAccessFile> rfile; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/path/appendable", &rfile)); char scratch[100]; - absl::string_view result; + StringPiece result; TF_EXPECT_OK(rfile->Read(0, 8, &result, scratch)); EXPECT_EQ("content1", result); // Closing the appendable file will flush its contents to GCS, triggering HTTP @@ -1093,9 +1092,8 @@ TEST(GcsFileSystemTest, NewReadOnlyMemoryRegionFromFile) { TF_EXPECT_OK(fs.NewReadOnlyMemoryRegionFromFile( "gs://bucket/path/random_access.txt", ®ion)); - EXPECT_EQ(content, - absl::string_view(reinterpret_cast<const char*>(region->data()), - region->length())); + EXPECT_EQ(content, StringPiece(reinterpret_cast<const char*>(region->data()), + region->length())); } TEST(GcsFileSystemTest, NewReadOnlyMemoryRegionFromFile_NoObjectName) { @@ -1810,7 +1808,7 @@ TEST(GcsFileSystemTest, DeleteFile) { // Do an initial read of the file to load its contents into the block cache. char scratch[100]; - absl::string_view result; + StringPiece result; std::unique_ptr<RandomAccessFile> file; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/path/file1.txt", &file)); TF_EXPECT_OK(file->Read(0, 8, &result, scratch)); @@ -2201,7 +2199,7 @@ TEST(GcsFileSystemTest, RenameFile_Object) { // Do an initial read of the source and destination files to load their // contents into the block cache. char scratch[100]; - absl::string_view result; + StringPiece result; std::unique_ptr<RandomAccessFile> src; std::unique_ptr<RandomAccessFile> dst; TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/path/src.txt", &src)); @@ -3312,7 +3310,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_StatsRecording) { TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); char scratch[6]; - absl::string_view result; + StringPiece result; TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); EXPECT_EQ("012345", result); diff --git a/tensorflow/core/platform/cloud/google_auth_provider.cc b/tensorflow/core/platform/cloud/google_auth_provider.cc index b8f3e0c07c4..e15400780af 100644 --- a/tensorflow/core/platform/cloud/google_auth_provider.cc +++ b/tensorflow/core/platform/cloud/google_auth_provider.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/platform/cloud/google_auth_provider.h" -#include "absl/strings/string_view.h" #ifndef _WIN32 #include <pwd.h> #include <unistd.h> @@ -207,8 +206,8 @@ Status GoogleAuthProvider::GetTokenFromGce() { TF_RETURN_IF_ERROR(compute_engine_metadata_client_->GetMetadata( kGceTokenPath, &response_buffer)); - absl::string_view response = - absl::string_view(&response_buffer[0], response_buffer.size()); + StringPiece response = + StringPiece(&response_buffer[0], response_buffer.size()); TF_RETURN_IF_ERROR(oauth_client_->ParseOAuthResponse( response, request_timestamp_sec, ¤t_token_, diff --git a/tensorflow/core/platform/cloud/google_auth_provider_test.cc b/tensorflow/core/platform/cloud/google_auth_provider_test.cc index 17345665b62..ec31c5ee8c1 100644 --- a/tensorflow/core/platform/cloud/google_auth_provider_test.cc +++ b/tensorflow/core/platform/cloud/google_auth_provider_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/google_auth_provider.h" #include <stdlib.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/platform/cloud/http_request_fake.h" @@ -38,9 +37,8 @@ class FakeEnv : public EnvWrapper { class FakeOAuthClient : public OAuthClient { public: Status GetTokenFromServiceAccountJson( - Json::Value json, absl::string_view oauth_server_uri, - absl::string_view scope, string* token, - uint64* expiration_timestamp_sec) override { + Json::Value json, StringPiece oauth_server_uri, StringPiece scope, + string* token, uint64* expiration_timestamp_sec) override { provided_credentials_json = json; *token = return_token; *expiration_timestamp_sec = return_expiration_timestamp; @@ -49,7 +47,7 @@ class FakeOAuthClient : public OAuthClient { /// Retrieves a bearer token using a refresh token. Status GetTokenFromRefreshTokenJson( - Json::Value json, absl::string_view oauth_server_uri, string* token, + Json::Value json, StringPiece oauth_server_uri, string* token, uint64* expiration_timestamp_sec) override { provided_credentials_json = json; *token = return_token; diff --git a/tensorflow/core/platform/cloud/http_request_fake.h b/tensorflow/core/platform/cloud/http_request_fake.h index 0566ef89ffa..0a1164b64a7 100644 --- a/tensorflow/core/platform/cloud/http_request_fake.h +++ b/tensorflow/core/platform/cloud/http_request_fake.h @@ -20,11 +20,11 @@ limitations under the License. #include <fstream> #include <string> #include <vector> -#include "absl/strings/string_view.h" #include <curl/curl.h> #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/cloud/curl_http_request.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/protobuf.h" @@ -101,7 +101,7 @@ class FakeHttpRequest : public CurlHttpRequest { *captured_post_body_ = string(buffer, size); } else { actual_request_ += - strings::StrCat("Post body: ", absl::string_view(buffer, size), "\n"); + strings::StrCat("Post body: ", StringPiece(buffer, size), "\n"); } } void SetPutEmptyBody() override { actual_request_ += "Put: yes\n"; } diff --git a/tensorflow/core/platform/cloud/oauth_client.cc b/tensorflow/core/platform/cloud/oauth_client.cc index 97682c3e36a..9b85cae9b90 100644 --- a/tensorflow/core/platform/cloud/oauth_client.cc +++ b/tensorflow/core/platform/cloud/oauth_client.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/platform/cloud/oauth_client.h" -#include "absl/strings/string_view.h" #ifndef _WIN32 #include <pwd.h> #include <sys/types.h> @@ -85,7 +84,7 @@ Status ReadJsonInt(const Json::Value& json, const string& name, int64* value) { return Status::OK(); } -Status CreateSignature(RSA* private_key, absl::string_view to_sign, +Status CreateSignature(RSA* private_key, StringPiece to_sign, string* signature) { if (!private_key || !signature) { return errors::FailedPrecondition( @@ -121,14 +120,13 @@ Status CreateSignature(RSA* private_key, absl::string_view to_sign, return errors::Internal("DigestFinal (signature compute) failed."); } EVP_MD_CTX_cleanup(md_ctx.get()); - return Base64Encode( - absl::string_view(reinterpret_cast<char*>(sig.get()), sig_len), - signature); + return Base64Encode(StringPiece(reinterpret_cast<char*>(sig.get()), sig_len), + signature); } /// Encodes a claim for a JSON web token (JWT) to make an OAuth request. -Status EncodeJwtClaim(absl::string_view client_email, absl::string_view scope, - absl::string_view audience, uint64 request_timestamp_sec, +Status EncodeJwtClaim(StringPiece client_email, StringPiece scope, + StringPiece audience, uint64 request_timestamp_sec, string* encoded) { // Step 1: create the JSON with the claim. Json::Value root; @@ -150,7 +148,7 @@ Status EncodeJwtClaim(absl::string_view client_email, absl::string_view scope, } /// Encodes a header for a JSON web token (JWT) to make an OAuth request. -Status EncodeJwtHeader(absl::string_view key_id, string* encoded) { +Status EncodeJwtHeader(StringPiece key_id, string* encoded) { // Step 1: create the JSON with the header. Json::Value root; root["alg"] = kCryptoAlgorithm; @@ -176,8 +174,8 @@ OAuthClient::OAuthClient( : http_request_factory_(std::move(http_request_factory)), env_(env) {} Status OAuthClient::GetTokenFromServiceAccountJson( - Json::Value json, absl::string_view oauth_server_uri, - absl::string_view scope, string* token, uint64* expiration_timestamp_sec) { + Json::Value json, StringPiece oauth_server_uri, StringPiece scope, + string* token, uint64* expiration_timestamp_sec) { if (!token || !expiration_timestamp_sec) { return errors::FailedPrecondition( "'token' and 'expiration_timestamp_sec' cannot be nullptr."); @@ -223,15 +221,15 @@ Status OAuthClient::GetTokenFromServiceAccountJson( request->SetResultBuffer(&response_buffer); TF_RETURN_IF_ERROR(request->Send()); - absl::string_view response = - absl::string_view(response_buffer.data(), response_buffer.size()); + StringPiece response = + StringPiece(response_buffer.data(), response_buffer.size()); TF_RETURN_IF_ERROR(ParseOAuthResponse(response, request_timestamp_sec, token, expiration_timestamp_sec)); return Status::OK(); } Status OAuthClient::GetTokenFromRefreshTokenJson( - Json::Value json, absl::string_view oauth_server_uri, string* token, + Json::Value json, StringPiece oauth_server_uri, string* token, uint64* expiration_timestamp_sec) { if (!token || !expiration_timestamp_sec) { return errors::FailedPrecondition( @@ -255,14 +253,14 @@ Status OAuthClient::GetTokenFromRefreshTokenJson( request->SetResultBuffer(&response_buffer); TF_RETURN_IF_ERROR(request->Send()); - absl::string_view response = - absl::string_view(response_buffer.data(), response_buffer.size()); + StringPiece response = + StringPiece(response_buffer.data(), response_buffer.size()); TF_RETURN_IF_ERROR(ParseOAuthResponse(response, request_timestamp_sec, token, expiration_timestamp_sec)); return Status::OK(); } -Status OAuthClient::ParseOAuthResponse(absl::string_view response, +Status OAuthClient::ParseOAuthResponse(StringPiece response, uint64 request_timestamp_sec, string* token, uint64* expiration_timestamp_sec) { diff --git a/tensorflow/core/platform/cloud/oauth_client.h b/tensorflow/core/platform/cloud/oauth_client.h index 5598811258c..519d69acf98 100644 --- a/tensorflow/core/platform/cloud/oauth_client.h +++ b/tensorflow/core/platform/cloud/oauth_client.h @@ -17,7 +17,6 @@ limitations under the License. #define TENSORFLOW_CORE_PLATFORM_CLOUD_OAUTH_CLIENT_H_ #include <memory> -#include "absl/strings/string_view.h" #include "include/json/json.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/platform/cloud/http_request.h" @@ -38,16 +37,17 @@ class OAuthClient { /// Retrieves the authentication bearer token using a JSON file /// with the client's private key. virtual Status GetTokenFromServiceAccountJson( - Json::Value json, absl::string_view oauth_server_uri, - absl::string_view scope, string* token, uint64* expiration_timestamp_sec); + Json::Value json, StringPiece oauth_server_uri, StringPiece scope, + string* token, uint64* expiration_timestamp_sec); /// Retrieves a bearer token using a refresh token. - virtual Status GetTokenFromRefreshTokenJson( - Json::Value json, absl::string_view oauth_server_uri, string* token, - uint64* expiration_timestamp_sec); + virtual Status GetTokenFromRefreshTokenJson(Json::Value json, + StringPiece oauth_server_uri, + string* token, + uint64* expiration_timestamp_sec); /// Parses the JSON response with the token from an OAuth 2.0 server. - virtual Status ParseOAuthResponse(absl::string_view response, + virtual Status ParseOAuthResponse(StringPiece response, uint64 request_timestamp_sec, string* token, uint64* expiration_timestamp_sec); diff --git a/tensorflow/core/platform/cloud/oauth_client_test.cc b/tensorflow/core/platform/cloud/oauth_client_test.cc index d72d23c0ced..1cd0641cd3a 100644 --- a/tensorflow/core/platform/cloud/oauth_client_test.cc +++ b/tensorflow/core/platform/cloud/oauth_client_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/oauth_client.h" #include <fstream> -#include "absl/strings/string_view.h" #include <openssl/bio.h> #include <openssl/evp.h> #include <openssl/pem.h> @@ -116,7 +115,7 @@ TEST(OAuthClientTest, GetTokenFromServiceAccountJson) { EXPECT_EQ(13920, expiration_timestamp); // Now look at the JWT claim that was sent to the OAuth server. - absl::string_view grant_type, assertion; + StringPiece grant_type, assertion; ASSERT_TRUE(strings::Scanner(post_body) .OneLiteral("grant_type=") .RestartCapture() diff --git a/tensorflow/core/platform/cloud/retrying_file_system.h b/tensorflow/core/platform/cloud/retrying_file_system.h index 5c454a2b916..5ce6670dc7a 100644 --- a/tensorflow/core/platform/cloud/retrying_file_system.h +++ b/tensorflow/core/platform/cloud/retrying_file_system.h @@ -20,7 +20,6 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/random/random.h" @@ -151,7 +150,7 @@ class RetryingRandomAccessFile : public RandomAccessFile { const RetryConfig& retry_config) : base_file_(std::move(base_file)), retry_config_(retry_config) {} - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { return RetryingUtils::CallWithRetries( [this, offset, n, result, scratch]() { @@ -176,7 +175,7 @@ class RetryingWritableFile : public WritableFile { Close().IgnoreError(); } - Status Append(absl::string_view data) override { + Status Append(StringPiece data) override { return RetryingUtils::CallWithRetries( [this, &data]() { return base_file_->Append(data); }, retry_config_); } diff --git a/tensorflow/core/platform/cloud/retrying_file_system_test.cc b/tensorflow/core/platform/cloud/retrying_file_system_test.cc index fbce4a38f77..868eea096c2 100644 --- a/tensorflow/core/platform/cloud/retrying_file_system_test.cc +++ b/tensorflow/core/platform/cloud/retrying_file_system_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/cloud/retrying_file_system.h" #include <fstream> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" @@ -61,7 +60,7 @@ class MockCallSequence { class MockRandomAccessFile : public RandomAccessFile { public: explicit MockRandomAccessFile(const ExpectedCalls& calls) : calls_(calls) {} - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { return calls_.ConsumeNextCall("Read"); } @@ -73,7 +72,7 @@ class MockRandomAccessFile : public RandomAccessFile { class MockWritableFile : public WritableFile { public: explicit MockWritableFile(const ExpectedCalls& calls) : calls_(calls) {} - Status Append(absl::string_view data) override { + Status Append(StringPiece data) override { return calls_.ConsumeNextCall("Append"); } Status Close() override { return calls_.ConsumeNextCall("Close"); } @@ -193,7 +192,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_ImmediateSuccess) { TF_EXPECT_OK(fs.NewRandomAccessFile("filename.txt", &random_access_file)); // Use it and check the results. - absl::string_view result; + StringPiece result; char scratch[10]; TF_EXPECT_OK(random_access_file->Read(0, 10, &result, scratch)); } @@ -221,7 +220,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_SuccessWith3rdTry) { TF_EXPECT_OK(fs.NewRandomAccessFile("filename.txt", &random_access_file)); // Use it and check the results. - absl::string_view result; + StringPiece result; char scratch[10]; TF_EXPECT_OK(random_access_file->Read(0, 10, &result, scratch)); } @@ -246,7 +245,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_AllRetriesFailed) { TF_EXPECT_OK(fs.NewRandomAccessFile("filename.txt", &random_access_file)); // Use it and check the results. - absl::string_view result; + StringPiece result; char scratch[10]; const auto& status = random_access_file->Read(0, 10, &result, scratch); EXPECT_TRUE( @@ -277,7 +276,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_NoRetriesForSomeErrors) { TF_EXPECT_OK(fs.NewRandomAccessFile("filename.txt", &random_access_file)); // Use it and check the results. - absl::string_view result; + StringPiece result; char scratch[10]; EXPECT_EQ("Failed precondition", random_access_file->Read(0, 10, &result, scratch).error_message()); diff --git a/tensorflow/core/platform/default/device_tracer.cc b/tensorflow/core/platform/default/device_tracer.cc index 10487e0bae3..83c65dbfa97 100644 --- a/tensorflow/core/platform/default/device_tracer.cc +++ b/tensorflow/core/platform/default/device_tracer.cc @@ -20,7 +20,6 @@ limitations under the License. #include <stdlib.h> #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/step_stats_collector.h" #include "tensorflow/core/framework/step_stats.pb.h" #include "tensorflow/core/lib/core/errors.h" @@ -302,7 +301,7 @@ class DeviceTracerImpl : public DeviceTracer, // tracing::TraceCollector interface: virtual std::unique_ptr<Handle> CreateAnnotationHandle( - absl::string_view name_part1, absl::string_view name_part2) const { + StringPiece name_part1, StringPiece name_part2) const { struct Impl : public tracing::TraceCollector::Handle { string annotation; explicit Impl(string &&name_scope) : annotation(name_scope) { @@ -316,8 +315,7 @@ class DeviceTracerImpl : public DeviceTracer, new Impl{ConcatenateNames(name_part1, name_part2)}); } - virtual std::unique_ptr<Handle> CreateActivityHandle(absl::string_view, - absl::string_view, + virtual std::unique_ptr<Handle> CreateActivityHandle(StringPiece, StringPiece, bool) const { // We don't do anything with 'Activities' yet. return nullptr; diff --git a/tensorflow/core/platform/default/fingerprint.h b/tensorflow/core/platform/default/fingerprint.h index 11af54eac1c..f901befc16b 100644 --- a/tensorflow/core/platform/default/fingerprint.h +++ b/tensorflow/core/platform/default/fingerprint.h @@ -18,15 +18,15 @@ limitations under the License. #include <farmhash.h> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { -inline uint64 Fingerprint64(absl::string_view s) { +inline uint64 Fingerprint64(StringPiece s) { return ::util::Fingerprint64(s.data(), s.size()); } -inline Fprint128 Fingerprint128(absl::string_view s) { +inline Fprint128 Fingerprint128(StringPiece s) { const auto fingerprint = ::util::Fingerprint128(s.data(), s.size()); return {::util::Uint128Low64(fingerprint), ::util::Uint128High64(fingerprint)}; diff --git a/tensorflow/core/platform/default/human_readable_json.cc b/tensorflow/core/platform/default/human_readable_json.cc index 6cf55c5314b..9f97c8272c1 100644 --- a/tensorflow/core/platform/default/human_readable_json.cc +++ b/tensorflow/core/platform/default/human_readable_json.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/platform/human_readable_json.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -31,11 +30,12 @@ Status ProtoToHumanReadableJson(const ::google::protobuf::Message& proto, auto status = google::protobuf::util::MessageToJsonString(proto, result); if (!status.ok()) { - // Convert error_msg google::protobuf::StringPiece to absl::string_view. + // Convert error_msg google::protobuf::StringPiece to + // tensorflow::StringPiece. auto error_msg = status.error_message(); - return errors::Internal(strings::StrCat( - "Could not convert proto to JSON string: ", - absl::string_view(error_msg.data(), error_msg.length()))); + return errors::Internal( + strings::StrCat("Could not convert proto to JSON string: ", + StringPiece(error_msg.data(), error_msg.length()))); } return Status::OK(); #endif @@ -49,11 +49,12 @@ Status HumanReadableJsonToProto(const string& str, proto->Clear(); auto status = google::protobuf::util::JsonStringToMessage(str, proto); if (!status.ok()) { - // Convert error_msg google::protobuf::StringPiece to absl::string_view. + // Convert error_msg google::protobuf::StringPiece to + // tensorflow::StringPiece. auto error_msg = status.error_message(); - return errors::Internal(strings::StrCat( - "Could not convert JSON string to proto: ", - absl::string_view(error_msg.data(), error_msg.length()))); + return errors::Internal( + strings::StrCat("Could not convert JSON string to proto: ", + StringPiece(error_msg.data(), error_msg.length()))); } return Status::OK(); #endif diff --git a/tensorflow/core/platform/default/string_coding.h b/tensorflow/core/platform/default/string_coding.h index d7ee5f11878..70b8ab01444 100644 --- a/tensorflow/core/platform/default/string_coding.h +++ b/tensorflow/core/platform/default/string_coding.h @@ -18,7 +18,6 @@ limitations under the License. // IWYU pragma: private, include "third_party/tensorflow/core/platform/tensor_coding.h" // IWYU pragma: friend third_party/tensorflow/core/platform/tensor_coding.h -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/protobuf.h" @@ -87,7 +86,7 @@ class StringListDecoder { } private: - absl::string_view reader_; + StringPiece reader_; }; std::unique_ptr<StringListEncoder> NewStringListEncoder(string* out); diff --git a/tensorflow/core/platform/default/test_benchmark.cc b/tensorflow/core/platform/default/test_benchmark.cc index 4f872542bb3..dedab42bd73 100644 --- a/tensorflow/core/platform/default/test_benchmark.cc +++ b/tensorflow/core/platform/default/test_benchmark.cc @@ -20,7 +20,6 @@ limitations under the License. #include <algorithm> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/logging.h" @@ -118,7 +117,7 @@ void Benchmark::Run(const char* pattern) { // specified by clients, but we keep this here to match the internal // Google implementation, should we ever enable user-specified // pattern specification. - if (absl::string_view(pattern) == "all") { + if (StringPiece(pattern) == "all") { pattern = ".*"; } diff --git a/tensorflow/core/platform/env.cc b/tensorflow/core/platform/env.cc index 39051f885e1..afc4201e538 100644 --- a/tensorflow/core/platform/env.cc +++ b/tensorflow/core/platform/env.cc @@ -17,7 +17,6 @@ limitations under the License. #include <deque> #include <utility> #include <vector> -#include "absl/strings/string_view.h" #if defined(__APPLE__) #include <mach-o/dyld.h> #endif @@ -91,7 +90,7 @@ Status FileSystemRegistryImpl::GetRegisteredFileSystemSchemes( Env::Env() : file_system_registry_(new FileSystemRegistryImpl) {} Status Env::GetFileSystemForFile(const string& fname, FileSystem** result) { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(fname, &scheme, &host, &path); FileSystem* file_system = file_system_registry_->Lookup(string(scheme)); if (!file_system) { @@ -165,7 +164,7 @@ bool Env::FilesExist(const std::vector<string>& files, std::vector<Status>* status) { std::unordered_map<string, std::vector<string>> files_per_fs; for (const auto& file : files) { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(file, &scheme, &host, &path); files_per_fs[string(scheme)].push_back(file); } @@ -390,7 +389,7 @@ Status ReadFileToString(Env* env, const string& fname, string* data) { } gtl::STLStringResizeUninitialized(data, file_size); char* p = gtl::string_as_array(data); - absl::string_view result; + StringPiece result; s = file->Read(0, file_size, &result, p); if (!s.ok()) { data->clear(); @@ -407,7 +406,7 @@ Status ReadFileToString(Env* env, const string& fname, string* data) { } Status WriteStringToFile(Env* env, const string& fname, - const absl::string_view& data) { + const StringPiece& data) { std::unique_ptr<WritableFile> file; Status s = env->NewWritableFile(fname, &file); if (!s.ok()) { @@ -432,7 +431,7 @@ Status FileSystemCopyFile(FileSystem* src_fs, const string& src, std::unique_ptr<char[]> scratch(new char[kCopyFileBufferSize]); Status s = Status::OK(); while (s.ok()) { - absl::string_view result; + StringPiece result; s = src_file->Read(offset, kCopyFileBufferSize, &result, scratch.get()); if (!(s.ok() || s.code() == error::OUT_OF_RANGE)) { return s; @@ -458,7 +457,7 @@ class FileStream : public ::tensorflow::protobuf::io::ZeroCopyInputStream { Status status() const { return status_; } bool Next(const void** data, int* size) override { - absl::string_view result; + StringPiece result; Status s = file_->Read(pos_, kBufSize, &result, scratch_); if (result.empty()) { status_ = s; diff --git a/tensorflow/core/platform/env.h b/tensorflow/core/platform/env.h index 508da1ea0bc..5732271f150 100644 --- a/tensorflow/core/platform/env.h +++ b/tensorflow/core/platform/env.h @@ -21,9 +21,9 @@ limitations under the License. #include <string> #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #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/env_time.h" #include "tensorflow/core/platform/file_system.h" #include "tensorflow/core/platform/macros.h" @@ -408,7 +408,7 @@ Status ReadFileToString(Env* env, const string& fname, string* data); /// A utility routine: write contents of `data` to file named `fname` /// (overwriting existing contents, if any). Status WriteStringToFile(Env* env, const string& fname, - const absl::string_view& data); + const StringPiece& data); /// Write binary representation of "proto" to the named file. Status WriteBinaryProto(Env* env, const string& fname, diff --git a/tensorflow/core/platform/env_test.cc b/tensorflow/core/platform/env_test.cc index d37a722b5fe..2e32abdffb1 100644 --- a/tensorflow/core/platform/env_test.cc +++ b/tensorflow/core/platform/env_test.cc @@ -17,10 +17,10 @@ limitations under the License. #include <sys/stat.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -75,7 +75,7 @@ TEST_F(DefaultEnvTest, IncompleteReadOutOfRange) { TF_EXPECT_OK(env_->NewRandomAccessFile(filename, &f)); // Reading past EOF should give an OUT_OF_RANGE error - absl::string_view result; + StringPiece result; char scratch[3]; EXPECT_EQ(error::OUT_OF_RANGE, f->Read(0, 3, &result, scratch).code()); EXPECT_EQ(input, result); @@ -280,7 +280,7 @@ TEST_F(DefaultEnvTest, SleepForMicroseconds) { class TmpDirFileSystem : public NullFileSystem { public: Status FileExists(const string& dir) override { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(dir, &scheme, &host, &path); if (path.empty()) return errors::NotFound(dir, " not found"); // The special "flushed" file exists only if the filesystem's caches have @@ -296,7 +296,7 @@ class TmpDirFileSystem : public NullFileSystem { } Status CreateDir(const string& dir) override { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(dir, &scheme, &host, &path); if (scheme != "tmpdirfs") { return errors::FailedPrecondition("scheme must be tmpdirfs"); @@ -359,7 +359,7 @@ TEST_F(DefaultEnvTest, LocalTempFilename) { // Read from the temporary file and check content. std::unique_ptr<RandomAccessFile> file_to_read; TF_CHECK_OK(env->NewRandomAccessFile(filename, &file_to_read)); - absl::string_view content; + StringPiece content; char scratch[1024]; CHECK_EQ(error::OUT_OF_RANGE, file_to_read->Read(0 /* offset */, 1024 /* n */, &content, scratch) diff --git a/tensorflow/core/platform/file_system.cc b/tensorflow/core/platform/file_system.cc index 780cdad39fd..3ab542a5d88 100644 --- a/tensorflow/core/platform/file_system.cc +++ b/tensorflow/core/platform/file_system.cc @@ -17,7 +17,6 @@ limitations under the License. #include <algorithm> #include <deque> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -137,9 +136,9 @@ Status FileSystem::DeleteRecursively(const string& dirname, } Status FileSystem::RecursivelyCreateDir(const string& dirname) { - absl::string_view scheme, host, remaining_dir; + StringPiece scheme, host, remaining_dir; io::ParseURI(dirname, &scheme, &host, &remaining_dir); - std::vector<absl::string_view> sub_dirs; + std::vector<StringPiece> sub_dirs; while (!remaining_dir.empty()) { Status status = FileExists(io::CreateURI(scheme, host, remaining_dir)); if (status.ok()) { @@ -160,7 +159,7 @@ Status FileSystem::RecursivelyCreateDir(const string& dirname) { // Now create the directories. string built_path(remaining_dir); - for (const absl::string_view sub_dir : sub_dirs) { + for (const StringPiece sub_dir : sub_dirs) { built_path = io::JoinPath(built_path, sub_dir); Status status = CreateDir(io::CreateURI(scheme, host, built_path)); if (!status.ok() && status.code() != tensorflow::error::ALREADY_EXISTS) { diff --git a/tensorflow/core/platform/file_system.h b/tensorflow/core/platform/file_system.h index e57454b71b9..156af6cdeaa 100644 --- a/tensorflow/core/platform/file_system.h +++ b/tensorflow/core/platform/file_system.h @@ -21,9 +21,9 @@ limitations under the License. #include <string> #include <unordered_map> #include <vector> -#include "absl/strings/string_view.h" #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" @@ -236,7 +236,7 @@ class RandomAccessFile { /// because of EOF. /// /// Safe for concurrent use by multiple threads. - virtual Status Read(uint64 offset, size_t n, absl::string_view* result, + virtual Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const = 0; private: @@ -253,7 +253,7 @@ class WritableFile { virtual ~WritableFile(); /// \brief Append 'data' to the file. - virtual Status Append(absl::string_view data) = 0; + virtual Status Append(StringPiece data) = 0; // TODO(ebrevdo): Remove this ifdef when absl is updated. #if defined(PLATFORM_GOOGLE) diff --git a/tensorflow/core/platform/file_system_test.cc b/tensorflow/core/platform/file_system_test.cc index 5acf71dc6db..a637d42a921 100644 --- a/tensorflow/core/platform/file_system_test.cc +++ b/tensorflow/core/platform/file_system_test.cc @@ -17,7 +17,6 @@ limitations under the License. #include <sys/stat.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -121,7 +120,7 @@ class InterPlanetaryFileSystem : public NullFileSystem { } void ParsePath(const string& name, string* parsed_path) { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(name, &scheme, &host, &path); ASSERT_EQ(scheme, "ipfs"); ASSERT_EQ(host, "solarsystem"); @@ -157,10 +156,10 @@ string Match(InterPlanetaryFileSystem* ipfs, const string& suffix_pattern) { if (!s.ok()) { return s.ToString(); } else { - std::vector<absl::string_view> trimmed_results; + std::vector<StringPiece> trimmed_results; std::sort(results.begin(), results.end()); for (const string& result : results) { - absl::string_view trimmed_result(result); + StringPiece trimmed_result(result); EXPECT_TRUE(str_util::ConsumePrefix(&trimmed_result, strings::StrCat(kPrefix, "/"))); trimmed_results.push_back(trimmed_result); diff --git a/tensorflow/core/platform/fingerprint.h b/tensorflow/core/platform/fingerprint.h index 71280fbd1db..720dc4c3d6b 100644 --- a/tensorflow/core/platform/fingerprint.h +++ b/tensorflow/core/platform/fingerprint.h @@ -16,7 +16,7 @@ limitations under the License. #ifndef TENSORFLOW_CORE_PLATFORM_FINGERPRINT_H_ #define TENSORFLOW_CORE_PLATFORM_FINGERPRINT_H_ -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -39,10 +39,10 @@ struct Fprint128Hasher { // This is a portable fingerprint interface for strings that will never change. // However, it is not suitable for cryptography. -uint64 Fingerprint64(absl::string_view s); +uint64 Fingerprint64(StringPiece s); // 128-bit variant of Fingerprint64 above (same properties and caveats apply). -Fprint128 Fingerprint128(absl::string_view s); +Fprint128 Fingerprint128(StringPiece s); namespace internal { // Mixes some of the bits that got propagated to the high bits back into the diff --git a/tensorflow/core/platform/hadoop/BUILD b/tensorflow/core/platform/hadoop/BUILD index 6c23f5a61e7..7c38c399bd7 100644 --- a/tensorflow/core/platform/hadoop/BUILD +++ b/tensorflow/core/platform/hadoop/BUILD @@ -20,7 +20,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//third_party/hadoop:hdfs", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -60,6 +59,5 @@ tf_cc_test( "//tensorflow/core:lib_internal", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/platform/hadoop/hadoop_file_system.cc b/tensorflow/core/platform/hadoop/hadoop_file_system.cc index 48b272d2ba9..eb35531e9f8 100644 --- a/tensorflow/core/platform/hadoop/hadoop_file_system.cc +++ b/tensorflow/core/platform/hadoop/hadoop_file_system.cc @@ -17,7 +17,6 @@ limitations under the License. #include <errno.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -140,10 +139,10 @@ HadoopFileSystem::~HadoopFileSystem() {} // We rely on HDFS connection caching here. The HDFS client calls // org.apache.hadoop.fs.FileSystem.get(), which caches the connection // internally. -Status HadoopFileSystem::Connect(absl::string_view fname, hdfsFS* fs) { +Status HadoopFileSystem::Connect(StringPiece fname, hdfsFS* fs) { TF_RETURN_IF_ERROR(hdfs_->status()); - absl::string_view scheme, namenode, path; + StringPiece scheme, namenode, path; io::ParseURI(fname, &scheme, &namenode, &path); const string nn(namenode); @@ -153,7 +152,7 @@ Status HadoopFileSystem::Connect(absl::string_view fname, hdfsFS* fs) { } else if (scheme == "viewfs") { char* defaultFS = nullptr; hdfs_->hdfsConfGetStr("fs.defaultFS", &defaultFS); - absl::string_view defaultScheme, defaultCluster, defaultPath; + StringPiece defaultScheme, defaultCluster, defaultPath; io::ParseURI(defaultFS, &defaultScheme, &defaultCluster, &defaultPath); if (scheme != defaultScheme || namenode != defaultCluster) { @@ -182,7 +181,7 @@ Status HadoopFileSystem::Connect(absl::string_view fname, hdfsFS* fs) { } string HadoopFileSystem::TranslateName(const string& name) const { - absl::string_view scheme, namenode, path; + StringPiece scheme, namenode, path; io::ParseURI(name, &scheme, &namenode, &path); return string(path); } @@ -204,7 +203,7 @@ class HDFSRandomAccessFile : public RandomAccessFile { } } - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { Status s; char* dst = scratch; @@ -243,7 +242,7 @@ class HDFSRandomAccessFile : public RandomAccessFile { s = IOError(filename_, errno); } } - *result = absl::string_view(scratch, dst - scratch); + *result = StringPiece(scratch, dst - scratch); return s; } @@ -283,7 +282,7 @@ class HDFSWritableFile : public WritableFile { } } - Status Append(absl::string_view 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/hadoop/hadoop_file_system.h b/tensorflow/core/platform/hadoop/hadoop_file_system.h index 3655ee10765..6af7a698ffe 100644 --- a/tensorflow/core/platform/hadoop/hadoop_file_system.h +++ b/tensorflow/core/platform/hadoop/hadoop_file_system.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_PLATFORM_HADOOP_HADOOP_FILE_SYSTEM_H_ #define TENSORFLOW_CORE_PLATFORM_HADOOP_HADOOP_FILE_SYSTEM_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/env.h" extern "C" { @@ -68,7 +67,7 @@ class HadoopFileSystem : public FileSystem { string TranslateName(const string& name) const override; private: - Status Connect(absl::string_view fname, hdfsFS* fs); + Status Connect(StringPiece fname, hdfsFS* fs); LibHDFS* hdfs_; }; diff --git a/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc b/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc index d3659ce2483..b207d347497 100644 --- a/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc +++ b/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/platform/hadoop/hadoop_file_system.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/io/path.h" @@ -55,7 +54,7 @@ class HadoopFileSystemTest : public ::testing::Test { TF_RETURN_IF_ERROR(hdfs.GetFileSize(fname, &file_size)); content->resize(file_size); - absl::string_view result; + StringPiece result; TF_RETURN_IF_ERROR( reader->Read(0, file_size, &result, gtl::string_as_array(content))); if (file_size != result.size()) { @@ -78,7 +77,7 @@ TEST_F(HadoopFileSystemTest, RandomAccessFile) { string got; got.resize(content.size()); - absl::string_view result; + StringPiece result; TF_EXPECT_OK( reader->Read(0, content.size(), &result, gtl::string_as_array(&got))); EXPECT_EQ(content.size(), result.size()); @@ -214,7 +213,7 @@ TEST_F(HadoopFileSystemTest, WriteWhileReading) { string got; got.resize(content1.size()); - absl::string_view result; + StringPiece result; TF_EXPECT_OK( reader->Read(0, content1.size(), &result, gtl::string_as_array(&got))); EXPECT_EQ(content1, result); diff --git a/tensorflow/core/platform/posix/posix_file_system.cc b/tensorflow/core/platform/posix/posix_file_system.cc index 2f8526c9b38..c7afab9583c 100644 --- a/tensorflow/core/platform/posix/posix_file_system.cc +++ b/tensorflow/core/platform/posix/posix_file_system.cc @@ -18,7 +18,6 @@ limitations under the License. #include <fcntl.h> #include <stdio.h> #include <sys/mman.h> -#include "absl/strings/string_view.h" #if !defined(__APPLE__) #include <sys/sendfile.h> #endif @@ -53,7 +52,7 @@ class PosixRandomAccessFile : public RandomAccessFile { : filename_(fname), fd_(fd) {} ~PosixRandomAccessFile() override { close(fd_); } - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { Status s; char* dst = scratch; @@ -71,7 +70,7 @@ class PosixRandomAccessFile : public RandomAccessFile { s = IOError(filename_, errno); } } - *result = absl::string_view(scratch, dst - scratch); + *result = StringPiece(scratch, dst - scratch); return s; } }; @@ -92,7 +91,7 @@ class PosixWritableFile : public WritableFile { } } - Status Append(absl::string_view 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); @@ -218,7 +217,7 @@ Status PosixFileSystem::GetChildren(const string& dir, } struct dirent* entry; while ((entry = readdir(d)) != nullptr) { - absl::string_view basename = entry->d_name; + StringPiece basename = entry->d_name; if ((basename != ".") && (basename != "..")) { result->push_back(entry->d_name); } diff --git a/tensorflow/core/platform/posix/posix_file_system.h b/tensorflow/core/platform/posix/posix_file_system.h index 78e403859ea..752eccea66b 100644 --- a/tensorflow/core/platform/posix/posix_file_system.h +++ b/tensorflow/core/platform/posix/posix_file_system.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_PLATFORM_POSIX_POSIX_FILE_SYSTEM_H_ #define TENSORFLOW_CORE_PLATFORM_POSIX_POSIX_FILE_SYSTEM_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/platform/env.h" @@ -69,7 +68,7 @@ Status IOError(const string& context, int err_number); class LocalPosixFileSystem : public PosixFileSystem { public: string TranslateName(const string& name) const override { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(name, &scheme, &host, &path); return string(path); } diff --git a/tensorflow/core/platform/s3/BUILD b/tensorflow/core/platform/s3/BUILD index f7a0d40083f..41184b6fd9e 100644 --- a/tensorflow/core/platform/s3/BUILD +++ b/tensorflow/core/platform/s3/BUILD @@ -34,7 +34,6 @@ tf_cc_binary( deps = [ "//tensorflow/core:framework_headers_lib", "@aws", - "@com_google_absl//absl/strings", "@curl", "@protobuf_archive//:protobuf_headers", ], diff --git a/tensorflow/core/platform/s3/s3_file_system.cc b/tensorflow/core/platform/s3/s3_file_system.cc index ed05b2171cc..e0b8e377453 100644 --- a/tensorflow/core/platform/s3/s3_file_system.cc +++ b/tensorflow/core/platform/s3/s3_file_system.cc @@ -13,8 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "tensorflow/core/platform/s3/s3_file_system.h" - -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/file_system_helper.h" @@ -146,7 +144,7 @@ Status ParseS3Path(const string& fname, bool empty_object_ok, string* bucket, if (!bucket || !object) { return errors::Internal("bucket and object cannot be null."); } - absl::string_view scheme, bucketp, objectp; + StringPiece scheme, bucketp, objectp; io::ParseURI(fname, &scheme, &bucketp, &objectp); if (scheme != "s3") { return errors::InvalidArgument("S3 path doesn't start with 's3://': ", @@ -172,7 +170,7 @@ class S3RandomAccessFile : public RandomAccessFile { std::shared_ptr<Aws::S3::S3Client> s3_client) : bucket_(bucket), object_(object), s3_client_(s3_client) {} - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { Aws::S3::Model::GetObjectRequest getObjectRequest; getObjectRequest.WithBucket(bucket_.c_str()).WithKey(object_.c_str()); @@ -184,13 +182,13 @@ class S3RandomAccessFile : public RandomAccessFile { auto getObjectOutcome = this->s3_client_->GetObject(getObjectRequest); if (!getObjectOutcome.IsSuccess()) { n = 0; - *result = absl::string_view(scratch, n); + *result = StringPiece(scratch, n); return Status(error::OUT_OF_RANGE, "Read less bytes than requested"); } n = getObjectOutcome.GetResult().GetContentLength(); getObjectOutcome.GetResult().GetBody().read(scratch, n); - *result = absl::string_view(scratch, n); + *result = StringPiece(scratch, n); return Status::OK(); } @@ -213,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(absl::string_view data) override { + Status Append(StringPiece data) override { if (!outfile_) { return errors::FailedPrecondition( "The internal temporary file is not writable."); @@ -341,7 +339,7 @@ Status S3FileSystem::NewAppendableFile(const string& fname, std::unique_ptr<char[]> buffer(new char[kS3ReadAppendableFileBufferSize]); Status status; uint64 offset = 0; - absl::string_view read_chunk; + StringPiece read_chunk; string bucket, object; TF_RETURN_IF_ERROR(ParseS3Path(fname, false, &bucket, &object)); @@ -374,7 +372,7 @@ Status S3FileSystem::NewReadOnlyMemoryRegionFromFile( std::unique_ptr<RandomAccessFile> file; TF_RETURN_IF_ERROR(NewRandomAccessFile(fname, &file)); - absl::string_view piece; + StringPiece piece; TF_RETURN_IF_ERROR(file->Read(0, size, &piece, data.get())); result->reset(new S3ReadOnlyMemoryRegion(std::move(data), size)); diff --git a/tensorflow/core/platform/tensor_coding.cc b/tensorflow/core/platform/tensor_coding.cc index 2fbf9f6ee3f..84601de39a6 100644 --- a/tensorflow/core/platform/tensor_coding.cc +++ b/tensorflow/core/platform/tensor_coding.cc @@ -17,14 +17,13 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/coding.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { namespace port { -void AssignRefCounted(absl::string_view src, core::RefCounted* obj, - string* out) { +void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out) { out->assign(src.data(), src.size()); } @@ -40,7 +39,7 @@ void EncodeStringList(const string* strings, int64 n, string* out) { bool DecodeStringList(const string& src, string* strings, int64 n) { std::vector<uint32> sizes(n); - absl::string_view reader(src); + StringPiece reader(src); int64 tot = 0; for (auto& v : sizes) { if (!core::GetVarint32(&reader, &v)) return false; diff --git a/tensorflow/core/platform/tensor_coding.h b/tensorflow/core/platform/tensor_coding.h index 6987de56b69..6c6d75830de 100644 --- a/tensorflow/core/platform/tensor_coding.h +++ b/tensorflow/core/platform/tensor_coding.h @@ -18,8 +18,8 @@ limitations under the License. #define TENSORFLOW_PLATFORM_TENSOR_CODING_H_ #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/refcount.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/platform.h" #include "tensorflow/core/platform/types.h" @@ -35,8 +35,7 @@ namespace port { // 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(absl::string_view src, core::RefCounted* obj, - string* out); +void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out); // Copy contents of src to dst[0,src.size()-1]. inline void CopyToArray(const string& src, char* dst) { diff --git a/tensorflow/core/platform/tracing.cc b/tensorflow/core/platform/tracing.cc index c1678a2dd91..c0386c0a3fc 100644 --- a/tensorflow/core/platform/tracing.cc +++ b/tensorflow/core/platform/tracing.cc @@ -20,7 +20,6 @@ limitations under the License. #include <map> #include <string> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -58,12 +57,11 @@ uint64 GetUniqueArg() { return unique_arg.fetch_add(1, std::memory_order_relaxed); } -uint64 GetArgForName(absl::string_view name) { +uint64 GetArgForName(StringPiece name) { return Hash64(name.data(), name.size()); } -string TraceCollector::ConcatenateNames(absl::string_view first, - absl::string_view second) { +string TraceCollector::ConcatenateNames(StringPiece first, StringPiece second) { std::string result; bool has_two_parts = !first.empty() && !second.empty(); result.reserve(first.size() + second.size() + diff --git a/tensorflow/core/platform/tracing.h b/tensorflow/core/platform/tracing.h index 8c0d8666a6d..aefbe64425a 100644 --- a/tensorflow/core/platform/tracing.h +++ b/tensorflow/core/platform/tracing.h @@ -23,7 +23,7 @@ limitations under the License. #include <map> #include <memory> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/mutex.h" @@ -82,7 +82,7 @@ inline const EventCollector* GetEventCollector(EventCategory category) { uint64 GetUniqueArg(); // Returns an id for name to pass to RecordEvent/ScopedRegion. -uint64 GetArgForName(absl::string_view name); +uint64 GetArgForName(StringPiece name); // Records an atomic event through the currently registered EventCollector. inline void RecordEvent(EventCategory category, uint64 arg) { @@ -121,7 +121,7 @@ class ScopedRegion { // Same as ScopedRegion(category, GetArgForName(name)), but faster if // EventCollector::IsEnaled() returns false. - ScopedRegion(EventCategory category, absl::string_view name) + ScopedRegion(EventCategory category, StringPiece name) : collector_(GetEventCollector(category)) { if (collector_) { collector_->StartRegion(GetArgForName(name)); @@ -150,9 +150,9 @@ class TraceCollector { virtual ~TraceCollector() {} virtual std::unique_ptr<Handle> CreateAnnotationHandle( - absl::string_view name_part1, absl::string_view name_part2) const = 0; + StringPiece name_part1, StringPiece name_part2) const = 0; virtual std::unique_ptr<Handle> CreateActivityHandle( - absl::string_view name_part1, absl::string_view name_part2, + StringPiece name_part1, StringPiece name_part2, bool is_expensive) const = 0; // Returns true if this annotation tracing is enabled for any op. @@ -163,8 +163,7 @@ class TraceCollector { virtual bool IsEnabledForActivities(bool is_expensive) const = 0; protected: - static string ConcatenateNames(absl::string_view first, - absl::string_view second); + static string ConcatenateNames(StringPiece first, StringPiece second); private: friend void SetTraceCollector(const TraceCollector*); @@ -186,14 +185,14 @@ const TraceCollector* GetTraceCollector(); // This will add 'my kernels' to both kernels in the profiler UI class ScopedAnnotation { public: - explicit ScopedAnnotation(absl::string_view name) - : ScopedAnnotation(name, absl::string_view()) {} + explicit ScopedAnnotation(StringPiece name) + : ScopedAnnotation(name, StringPiece()) {} // If tracing is enabled, add a name scope of // "<name_part1>:<name_part2>". This can be cheaper than the // single-argument constructor because the concatenation of the // label string is only done if tracing is enabled. - ScopedAnnotation(absl::string_view name_part1, absl::string_view name_part2) + ScopedAnnotation(StringPiece name_part1, StringPiece name_part2) : handle_([&] { auto trace_collector = GetTraceCollector(); return trace_collector ? trace_collector->CreateAnnotationHandle( @@ -212,14 +211,14 @@ class ScopedAnnotation { // the object is destroyed. class ScopedActivity { public: - explicit ScopedActivity(absl::string_view name, bool is_expensive = true) - : ScopedActivity(name, absl::string_view(), is_expensive) {} + explicit ScopedActivity(StringPiece name, bool is_expensive = true) + : ScopedActivity(name, StringPiece(), is_expensive) {} // If tracing is enabled, set up an activity with a label of // "<name_part1>:<name_part2>". This can be cheaper than the // single-argument constructor because the concatenation of the // label string is only done if tracing is enabled. - ScopedActivity(absl::string_view name_part1, absl::string_view name_part2, + ScopedActivity(StringPiece name_part1, StringPiece name_part2, bool is_expensive = true) : handle_([&] { auto trace_collector = GetTraceCollector(); diff --git a/tensorflow/core/platform/windows/windows_file_system.cc b/tensorflow/core/platform/windows/windows_file_system.cc index 8d180272fec..6cf79634d7a 100644 --- a/tensorflow/core/platform/windows/windows_file_system.cc +++ b/tensorflow/core/platform/windows/windows_file_system.cc @@ -25,7 +25,6 @@ limitations under the License. #include <sys/types.h> #include <time.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/error_codes.pb.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/env.h" @@ -113,7 +112,7 @@ class WindowsRandomAccessFile : public RandomAccessFile { } } - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { Status s; char* dst = scratch; @@ -131,7 +130,7 @@ class WindowsRandomAccessFile : public RandomAccessFile { s = IOError(filename_, errno); } } - *result = absl::string_view(scratch, dst - scratch); + *result = StringPiece(scratch, dst - scratch); return s; } }; @@ -151,7 +150,7 @@ class WindowsWritableFile : public WritableFile { } } - Status Append(absl::string_view data) override { + Status Append(StringPiece data) override { DWORD bytes_written = 0; DWORD data_size = static_cast<DWORD>(data.size()); BOOL write_result = @@ -414,7 +413,7 @@ Status WindowsFileSystem::GetChildren(const string& dir, do { string file_name = WideCharToUtf8(find_data.cFileName); - const absl::string_view basename = file_name; + const StringPiece basename = file_name; if (basename != "." && basename != "..") { result->push_back(file_name); } diff --git a/tensorflow/core/platform/windows/windows_file_system.h b/tensorflow/core/platform/windows/windows_file_system.h index 7ba471eec4b..1f4c535f241 100644 --- a/tensorflow/core/platform/windows/windows_file_system.h +++ b/tensorflow/core/platform/windows/windows_file_system.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_PLATFORM_WINDOWS_WINDOWS_FILE_SYSTEM_H_ #define TENSORFLOW_CORE_PLATFORM_WINDOWS_WINDOWS_FILE_SYSTEM_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/platform/file_system.h" @@ -70,7 +69,7 @@ class WindowsFileSystem : public FileSystem { class LocalWinFileSystem : public WindowsFileSystem { public: string TranslateName(const string& name) const override { - absl::string_view scheme, host, path; + StringPiece scheme, host, path; io::ParseURI(name, &scheme, &host, &path); return string(path); } diff --git a/tensorflow/core/profiler/internal/BUILD b/tensorflow/core/profiler/internal/BUILD index c0afedabf9d..8dcfde9a2ad 100644 --- a/tensorflow/core/profiler/internal/BUILD +++ b/tensorflow/core/profiler/internal/BUILD @@ -254,7 +254,6 @@ cc_library( "//tensorflow/core:protos_all_cc", "//tensorflow/core:regexp_internal", "//tensorflow/core/profiler:tfprof_options", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/profiler/internal/tfprof_utils.cc b/tensorflow/core/profiler/internal/tfprof_utils.cc index 6ae1c1533ae..7712ebd926f 100644 --- a/tensorflow/core/profiler/internal/tfprof_utils.cc +++ b/tensorflow/core/profiler/internal/tfprof_utils.cc @@ -20,7 +20,6 @@ limitations under the License. #include <memory> #include <set> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -92,12 +91,12 @@ tensorflow::Status ReturnError(const std::vector<string>& pieces, int idx) { strings::StrCat("Invalid option '", pieces[idx], "' value: '", val, "'")); } -bool CaseEqual(absl::string_view s1, absl::string_view s2) { +bool CaseEqual(StringPiece s1, StringPiece s2) { if (s1.size() != s2.size()) return false; return str_util::Lowercase(s1) == str_util::Lowercase(s2); } -bool StringToBool(absl::string_view str, bool* value) { +bool StringToBool(StringPiece str, bool* value) { CHECK(value != nullptr) << "NULL output boolean given."; if (CaseEqual(str, "true") || CaseEqual(str, "t") || CaseEqual(str, "yes") || CaseEqual(str, "y") || CaseEqual(str, "1")) { diff --git a/tensorflow/core/util/command_line_flags.cc b/tensorflow/core/util/command_line_flags.cc index e253b3fae1a..f1196fdfec2 100644 --- a/tensorflow/core/util/command_line_flags.cc +++ b/tensorflow/core/util/command_line_flags.cc @@ -17,7 +17,7 @@ limitations under the License. #include <string> #include <vector> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" @@ -26,7 +26,7 @@ limitations under the License. namespace tensorflow { namespace { -bool ParseStringFlag(absl::string_view arg, absl::string_view flag, +bool ParseStringFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(string)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; @@ -40,7 +40,7 @@ bool ParseStringFlag(absl::string_view arg, absl::string_view flag, return false; } -bool ParseInt32Flag(absl::string_view arg, absl::string_view flag, +bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(int32)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; @@ -62,7 +62,7 @@ bool ParseInt32Flag(absl::string_view arg, absl::string_view flag, return false; } -bool ParseInt64Flag(absl::string_view arg, absl::string_view flag, +bool ParseInt64Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(int64)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; @@ -84,7 +84,7 @@ bool ParseInt64Flag(absl::string_view arg, absl::string_view flag, return false; } -bool ParseBoolFlag(absl::string_view arg, absl::string_view flag, +bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(bool)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; @@ -112,7 +112,7 @@ bool ParseBoolFlag(absl::string_view arg, absl::string_view flag, return false; } -bool ParseFloatFlag(absl::string_view arg, absl::string_view flag, +bool ParseFloatFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(float)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; diff --git a/tensorflow/core/util/device_name_utils.cc b/tensorflow/core/util/device_name_utils.cc index 33167d76620..8c24076aa9c 100644 --- a/tensorflow/core/util/device_name_utils.cc +++ b/tensorflow/core/util/device_name_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/util/device_name_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -30,7 +29,7 @@ static bool IsAlpha(char c) { static bool IsAlphaNum(char c) { return IsAlpha(c) || (c >= '0' && c <= '9'); } // Returns true iff "in" is a valid job name. -static bool IsJobName(absl::string_view in) { +static bool IsJobName(StringPiece in) { if (in.empty()) return false; if (!IsAlpha(in[0])) return false; for (size_t i = 1; i < in.size(); ++i) { @@ -40,7 +39,7 @@ static bool IsJobName(absl::string_view in) { } // Returns true and fills in "*job" iff "*in" starts with a job name. -static bool ConsumeJobName(absl::string_view* in, string* job) { +static bool ConsumeJobName(StringPiece* in, string* job) { if (in->empty()) return false; if (!IsAlpha((*in)[0])) return false; size_t i = 1; @@ -58,7 +57,7 @@ static bool ConsumeJobName(absl::string_view* in, string* job) { // Returns true and fills in "*device_type" iff "*in" starts with a device type // name. -static bool ConsumeDeviceType(absl::string_view* in, string* device_type) { +static bool ConsumeDeviceType(StringPiece* in, string* device_type) { if (in->empty()) return false; if (!IsAlpha((*in)[0])) return false; size_t i = 1; @@ -76,7 +75,7 @@ static bool ConsumeDeviceType(absl::string_view* in, string* device_type) { // Returns true and fills in "*val" iff "*in" starts with a decimal // number. -static bool ConsumeNumber(absl::string_view* in, int* val) { +static bool ConsumeNumber(StringPiece* in, int* val) { uint64 tmp; if (str_util::ConsumeLeadingDigits(in, &tmp)) { *val = tmp; @@ -112,7 +111,7 @@ string LegacyName(const string& job, int replica, int task, const string& type, } } // anonymous namespace -bool DeviceNameUtils::ParseFullName(absl::string_view fullname, ParsedName* p) { +bool DeviceNameUtils::ParseFullName(StringPiece fullname, ParsedName* p) { p->Clear(); if (fullname == "/") { return true; @@ -214,8 +213,8 @@ void CompleteName(const DeviceNameUtils::ParsedName& parsed_basename, } // namespace /* static */ -Status DeviceNameUtils::CanonicalizeDeviceName(absl::string_view fullname, - absl::string_view basename, +Status DeviceNameUtils::CanonicalizeDeviceName(StringPiece fullname, + StringPiece basename, string* canonical_name) { *canonical_name = ""; ParsedName parsed_basename; @@ -391,8 +390,7 @@ bool DeviceNameUtils::IsSameAddressSpace(const ParsedName& a, } /* static */ -bool DeviceNameUtils::IsSameAddressSpace(absl::string_view src, - absl::string_view dst) { +bool DeviceNameUtils::IsSameAddressSpace(StringPiece src, StringPiece dst) { ParsedName x; ParsedName y; return ParseFullName(src, &x) && ParseFullName(dst, &y) && @@ -400,27 +398,27 @@ bool DeviceNameUtils::IsSameAddressSpace(absl::string_view src, } /* static */ -string DeviceNameUtils::LocalName(absl::string_view type, int id) { +string DeviceNameUtils::LocalName(StringPiece type, int id) { return strings::StrCat("/device:", type, ":", id); } namespace { // Returns the legacy local device name given its "type" and "id" (which is // '/device:type:id'). -string LegacyLocalName(absl::string_view type, int id) { +string LegacyLocalName(StringPiece type, int id) { return strings::StrCat(type, ":", id); } } // anonymous namespace /* static */ -string DeviceNameUtils::LocalName(absl::string_view fullname) { +string DeviceNameUtils::LocalName(StringPiece fullname) { ParsedName x; CHECK(ParseFullName(fullname, &x)) << fullname; return LocalName(x.type, x.id); } /* static */ -bool DeviceNameUtils::ParseLocalName(absl::string_view name, ParsedName* p) { +bool DeviceNameUtils::ParseLocalName(StringPiece name, ParsedName* p) { if (!ConsumeDeviceType(&name, &p->type)) { return false; } @@ -436,7 +434,7 @@ bool DeviceNameUtils::ParseLocalName(absl::string_view name, ParsedName* p) { } /* static */ -bool DeviceNameUtils::SplitDeviceName(absl::string_view name, string* task, +bool DeviceNameUtils::SplitDeviceName(StringPiece name, string* task, string* device) { ParsedName pn; if (ParseFullName(name, &pn) && pn.has_type && pn.has_id) { diff --git a/tensorflow/core/util/device_name_utils.h b/tensorflow/core/util/device_name_utils.h index 21074223a2c..3f0bc605623 100644 --- a/tensorflow/core/util/device_name_utils.h +++ b/tensorflow/core/util/device_name_utils.h @@ -18,8 +18,8 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { @@ -86,15 +86,15 @@ class DeviceNameUtils { int id = 0; }; // Parses "fullname" into "*parsed". Returns true iff succeeds. - static bool ParseFullName(absl::string_view fullname, ParsedName* parsed); + static bool ParseFullName(StringPiece fullname, ParsedName* parsed); // Canonicalizes "fullname" into "*canonical_name". Uses a fully specified // basename to fill in fields that are missing. Accepts both legacy, newer // and local versions of the device spec. Returns the newer version of the // device spec. If we were unable to interpret / parse "fullname" returns // an error and *canonical_name is set to "". - static Status CanonicalizeDeviceName(absl::string_view fullname, - absl::string_view basename, + static Status CanonicalizeDeviceName(StringPiece fullname, + StringPiece basename, string* canonical_name); // Returns true if "name" specifies any non-trivial constraint on the device. @@ -133,20 +133,20 @@ class DeviceNameUtils { // Returns true iff devices identified by 'src' and 'dst' are in the // same address space. - static bool IsSameAddressSpace(absl::string_view src, absl::string_view dst); + static bool IsSameAddressSpace(StringPiece src, StringPiece dst); static bool IsSameAddressSpace(const ParsedName& src, const ParsedName& dst); // Returns the local device given its "type" and "id". - static string LocalName(absl::string_view type, int id); + static string LocalName(StringPiece type, int id); // Returns a short local device name (cpu:0, gpu:1, etc) based on // the given fullname. - static string LocalName(absl::string_view fullname); + static string LocalName(StringPiece fullname); // If "name" is a valid local device name (cpu:0, gpu:1, etc.), // fills in parsed.type and parsed.id accordingly. Returns true iff // succeeds. - static bool ParseLocalName(absl::string_view name, ParsedName* parsed); + static bool ParseLocalName(StringPiece name, ParsedName* parsed); // Splits a fully-qualified device name into a task identifier and a // relative device identifier. It first parses "name" using @@ -155,8 +155,7 @@ class DeviceNameUtils { // component into *device. This function will still return true if // the task component is empty, but it requires the relative device // component to be fully specified. - static bool SplitDeviceName(absl::string_view name, string* task, - string* device); + static bool SplitDeviceName(StringPiece name, string* task, string* device); static string ParsedNameToString(const ParsedName& pn); diff --git a/tensorflow/core/util/device_name_utils_test.cc b/tensorflow/core/util/device_name_utils_test.cc index 11c8171f27e..dafb3b20b9e 100644 --- a/tensorflow/core/util/device_name_utils_test.cc +++ b/tensorflow/core/util/device_name_utils_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/util/device_name_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -279,7 +278,7 @@ TEST(DeviceNameUtilsTest, Basic) { } } -static bool IsCSHelper(absl::string_view pattern, absl::string_view actual) { +static bool IsCSHelper(StringPiece pattern, StringPiece actual) { DeviceNameUtils::ParsedName p, a; EXPECT_TRUE(DeviceNameUtils::ParseFullName(pattern, &p)); EXPECT_TRUE(DeviceNameUtils::ParseFullName(actual, &a)); @@ -304,7 +303,7 @@ TEST(DeviceNameUtilsTest, IsCompleteSpecification) { IsCSHelper("/gpu:*", "/job:worker/replica:1/task:2/device:GPU:3")); } -static bool IsSpecHelper(absl::string_view pattern, absl::string_view actual) { +static bool IsSpecHelper(StringPiece pattern, StringPiece actual) { DeviceNameUtils::ParsedName p, a; EXPECT_TRUE(DeviceNameUtils::ParseFullName(pattern, &p)); EXPECT_TRUE(DeviceNameUtils::ParseFullName(actual, &a)); diff --git a/tensorflow/core/util/env_var.cc b/tensorflow/core/util/env_var.cc index 1753d22417d..2604a5d66a5 100644 --- a/tensorflow/core/util/env_var.cc +++ b/tensorflow/core/util/env_var.cc @@ -17,7 +17,6 @@ limitations under the License. #include <stdlib.h> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -26,7 +25,7 @@ limitations under the License. namespace tensorflow { -Status ReadBoolFromEnvVar(absl::string_view env_var_name, bool default_val, +Status ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val, bool* value) { *value = default_val; const char* tf_env_var_val = getenv(string(env_var_name).c_str()); @@ -46,7 +45,7 @@ Status ReadBoolFromEnvVar(absl::string_view env_var_name, bool default_val, tf_env_var_val, ". Use the default value: ", default_val)); } -Status ReadInt64FromEnvVar(absl::string_view env_var_name, int64 default_val, +Status ReadInt64FromEnvVar(StringPiece env_var_name, int64 default_val, int64* value) { *value = default_val; const char* tf_env_var_val = getenv(string(env_var_name).c_str()); @@ -61,8 +60,8 @@ Status ReadInt64FromEnvVar(absl::string_view env_var_name, int64 default_val, tf_env_var_val, ". Use the default value: ", default_val)); } -Status ReadStringFromEnvVar(absl::string_view env_var_name, - absl::string_view default_val, string* value) { +Status ReadStringFromEnvVar(StringPiece env_var_name, StringPiece default_val, + string* value) { const char* tf_env_var_val = getenv(string(env_var_name).c_str()); if (tf_env_var_val != nullptr) { *value = tf_env_var_val; diff --git a/tensorflow/core/util/env_var.h b/tensorflow/core/util/env_var.h index 89c591844fc..724ca357291 100644 --- a/tensorflow/core/util/env_var.h +++ b/tensorflow/core/util/env_var.h @@ -16,8 +16,8 @@ limitations under the License. #ifndef TENSORFLOW_CORE_UTIL_ENV_VAR_H_ #define TENSORFLOW_CORE_UTIL_ENV_VAR_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { @@ -27,19 +27,19 @@ namespace tensorflow { // case insensitive "false" is interpreted as false. A string "1" or a case // insensitive "true" is interpreted as true. Otherwise, an error status is // returned. -Status ReadBoolFromEnvVar(absl::string_view env_var_name, bool default_val, +Status ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val, bool* value); // Returns an int64 into "value" from the environmental variable "env_var_name". // If it is unset, the default value is used. // If the string cannot be parsed into int64, an error status is returned. -Status ReadInt64FromEnvVar(absl::string_view env_var_name, int64 default_val, +Status ReadInt64FromEnvVar(StringPiece env_var_name, int64 default_val, int64* value); // Returns a string into "value" from the environmental variable "env_var_name". // If it is unset, the default value is used. -Status ReadStringFromEnvVar(absl::string_view env_var_name, - absl::string_view default_val, string* value); +Status ReadStringFromEnvVar(StringPiece env_var_name, StringPiece default_val, + string* value); } // namespace tensorflow diff --git a/tensorflow/core/util/events_writer.cc b/tensorflow/core/util/events_writer.cc index a0605a758d5..aaaba913a7a 100644 --- a/tensorflow/core/util/events_writer.cc +++ b/tensorflow/core/util/events_writer.cc @@ -17,7 +17,6 @@ limitations under the License. #include <stddef.h> // for NULL -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/io/path.h" @@ -103,7 +102,7 @@ string EventsWriter::FileName() { return filename_; } -void EventsWriter::WriteSerializedEvent(absl::string_view event_str) { +void EventsWriter::WriteSerializedEvent(StringPiece event_str) { if (recordio_writer_ == nullptr) { if (!InitIfNeeded().ok()) { LOG(ERROR) << "Write failed because file could not be opened."; diff --git a/tensorflow/core/util/events_writer.h b/tensorflow/core/util/events_writer.h index 9a60ba59fc7..d5952c3cbdf 100644 --- a/tensorflow/core/util/events_writer.h +++ b/tensorflow/core/util/events_writer.h @@ -19,7 +19,6 @@ limitations under the License. #include <memory> #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/io/record_writer.h" #include "tensorflow/core/platform/env.h" @@ -67,7 +66,7 @@ class EventsWriter { // Append "event_str", a serialized Event, to the file. // Note that this function does NOT check that de-serializing event_str // results in a valid Event proto. The tensorflow:: bit makes SWIG happy. - void WriteSerializedEvent(absl::string_view event_str); + void WriteSerializedEvent(tensorflow::StringPiece event_str); // EventWriter automatically flushes and closes on destruction, but // these two methods are provided for users who want to write to disk sooner diff --git a/tensorflow/core/util/example_proto_fast_parsing.cc b/tensorflow/core/util/example_proto_fast_parsing.cc index 3f77843518d..e52d55e2ffe 100644 --- a/tensorflow/core/util/example_proto_fast_parsing.cc +++ b/tensorflow/core/util/example_proto_fast_parsing.cc @@ -16,7 +16,6 @@ limitations under the License. #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/example/example.pb.h" #include "tensorflow/core/example/feature.pb_text.h" #include "tensorflow/core/framework/numeric_op.h" @@ -67,7 +66,7 @@ namespace parsed { class Feature { public: Feature() {} - explicit Feature(absl::string_view serialized) : serialized_(serialized) {} + explicit Feature(StringPiece serialized) : serialized_(serialized) {} Status ParseDataType(DataType* dtype) { DCHECK(dtype != nullptr); @@ -224,14 +223,14 @@ class Feature { return true; } - absl::string_view GetSerialized() const { return serialized_; } + StringPiece GetSerialized() const { return serialized_; } private: // TODO(lew): Pair of uint8* would be more natural. - absl::string_view serialized_; + StringPiece serialized_; }; -using FeatureMapEntry = std::pair<absl::string_view, Feature>; +using FeatureMapEntry = std::pair<StringPiece, Feature>; using Example = std::vector<FeatureMapEntry>; } // namespace parsed @@ -261,14 +260,13 @@ inline bool SkipExtraneousTag(protobuf::io::CodedInputStream* stream) { return false; // unrecognized tag type } -bool ParseString(protobuf::io::CodedInputStream* stream, - absl::string_view* result) { +bool ParseString(protobuf::io::CodedInputStream* stream, StringPiece* result) { DCHECK(stream != nullptr); DCHECK(result != nullptr); uint32 length; if (!stream->ReadVarint32(&length)) return false; if (length == 0) { - *result = absl::string_view(nullptr, 0); + *result = StringPiece(nullptr, 0); return true; } const void* stream_alias; @@ -277,7 +275,7 @@ bool ParseString(protobuf::io::CodedInputStream* stream, return false; } if (static_cast<uint32>(stream_size) < length) return false; - *result = absl::string_view(static_cast<const char*>(stream_alias), length); + *result = StringPiece(static_cast<const char*>(stream_alias), length); stream->Skip(length); return true; } @@ -292,7 +290,7 @@ bool ParseFeatureMapEntry(protobuf::io::CodedInputStream* stream, if (!stream->ExpectTag(kDelimitedTag(1))) return false; if (!ParseString(stream, &feature_map_entry->first)) return false; if (!stream->ExpectTag(kDelimitedTag(2))) return false; - absl::string_view feature_string_piece; + StringPiece feature_string_piece; if (!ParseString(stream, &feature_string_piece)) return false; feature_map_entry->second = parsed::Feature(feature_string_piece); if (!stream->ExpectAtEnd()) return false; @@ -334,7 +332,7 @@ bool ParseExample(protobuf::io::CodedInputStream* stream, return true; } -bool ParseExample(absl::string_view serialized, parsed::Example* example) { +bool ParseExample(StringPiece serialized, parsed::Example* example) { DCHECK(example != nullptr); protobuf::io::CodedInputStream stream( reinterpret_cast<const uint8*>(serialized.data()), serialized.size()); @@ -441,7 +439,7 @@ struct SparseBuffer { }; struct SeededHasher { - uint64 operator()(absl::string_view s) const { + uint64 operator()(StringPiece s) const { return Hash64(s.data(), s.size(), seed); } uint64 seed{0xDECAFCAFFE}; @@ -469,7 +467,7 @@ class LimitedArraySlice { T* end_; }; -void LogDenseFeatureDataLoss(absl::string_view feature_name) { +void LogDenseFeatureDataLoss(StringPiece feature_name) { LOG(WARNING) << "Data loss! Feature '" << feature_name << "' is present in multiple concatenated " "tf.Examples. Ignoring all but last one."; @@ -480,7 +478,7 @@ void LogDenseFeatureDataLoss(absl::string_view feature_name) { duplicated_dense_feature->GetCell()->IncrementBy(1); } -void LogSparseFeatureDataLoss(absl::string_view feature_name) { +void LogSparseFeatureDataLoss(StringPiece feature_name) { LOG(WARNING) << "Data loss! Feature '" << feature_name << "' is present in multiple concatenated " "tf.Examples. Ignoring all but last one."; @@ -525,7 +523,7 @@ Status FastParseSerializedExample( parsed::FeatureMapEntry& name_and_feature = parsed_example[parsed_example_size - i - 1]; - const absl::string_view feature_name = name_and_feature.first; + const StringPiece feature_name = name_and_feature.first; parsed::Feature& feature = name_and_feature.second; std::pair<size_t, Type> d_and_type; @@ -544,7 +542,7 @@ Status FastParseSerializedExample( if (feature_name != config_feature_name) continue; } - auto example_error = [&](absl::string_view suffix) { + auto example_error = [&](StringPiece suffix) { return errors::InvalidArgument("Name: ", example_name, ", Key: ", feature_name, ", Index: ", example_index, ". ", suffix); @@ -587,7 +585,7 @@ Status FastParseSerializedExample( const std::size_t offset = example_index * num_elements; - auto shape_error = [&](size_t size, absl::string_view type_str) { + auto shape_error = [&](size_t size, StringPiece type_str) { return example_error(strings::StrCat( "Number of ", type_str, " values != expected. " @@ -639,7 +637,7 @@ Status FastParseSerializedExample( "Expected type: ", DataTypeString(config.dense[d].dtype))); } - auto shape_error = [&](size_t size, absl::string_view type_str) { + auto shape_error = [&](size_t size, StringPiece type_str) { return example_error(strings::StrCat( "Number of ", type_str, " values is not a multiple of stride length. Saw ", size, @@ -1277,7 +1275,7 @@ Status FastParseSingleExample(const Config& config, const string& serialized, parsed::FeatureMapEntry& name_and_feature = parsed_example[parsed_example_size - i - 1]; - const absl::string_view feature_name = name_and_feature.first; + const StringPiece feature_name = name_and_feature.first; parsed::Feature& feature = name_and_feature.second; std::pair<size_t, Type> d_and_type; @@ -1296,7 +1294,7 @@ Status FastParseSingleExample(const Config& config, const string& serialized, if (feature_name != config_feature_name) continue; } - auto example_error = [feature_name](absl::string_view suffix) { + auto example_error = [feature_name](StringPiece suffix) { return errors::InvalidArgument("Key: ", feature_name, ". ", suffix); }; @@ -1729,8 +1727,8 @@ Status FastParseSequenceExample( DCHECK(context_result != nullptr); DCHECK(feature_list_result != nullptr); DCHECK(dense_feature_lengths != nullptr); - std::map<absl::string_view, bool> context_is_sparse; - std::map<absl::string_view, std::pair<DataType, size_t>> + std::map<StringPiece, bool> context_is_sparse; + std::map<StringPiece, std::pair<DataType, size_t>> context_feature_type_and_lengths; if (!example_names.empty() && example_names.size() != num_examples) { return errors::InvalidArgument( @@ -1761,8 +1759,8 @@ Status FastParseSequenceExample( } context_is_sparse[c.feature_name] = false; } - std::map<absl::string_view, bool> sequence_is_sparse; - std::map<absl::string_view, std::pair<DataType, size_t>> + std::map<StringPiece, bool> sequence_is_sparse; + std::map<StringPiece, std::pair<DataType, size_t>> sequence_feature_type_and_lengths; for (auto& c : feature_list_config.sparse) { TF_RETURN_IF_ERROR(CheckConfigDataType(c.dtype)); @@ -1781,10 +1779,10 @@ Status FastParseSequenceExample( sequence_is_sparse[c.feature_name] = false; } - std::vector<std::map<absl::string_view, absl::string_view>> - all_context_features(num_examples); - std::vector<std::map<absl::string_view, absl::string_view>> - all_sequence_features(num_examples); + std::vector<std::map<StringPiece, StringPiece>> all_context_features( + num_examples); + std::vector<std::map<StringPiece, StringPiece>> all_sequence_features( + num_examples); const string kUnknown = "<unknown>"; for (int d = 0; d < num_examples; d++) { const string& example = serialized[d]; @@ -1800,8 +1798,8 @@ Status FastParseSequenceExample( // Extract pointers to all features within this serialized example. while (!stream.ExpectAtEnd()) { - std::map<absl::string_view, absl::string_view>* features = nullptr; - const std::map<absl::string_view, std::pair<DataType, size_t>>* config = + std::map<StringPiece, StringPiece>* features = nullptr; + const std::map<StringPiece, std::pair<DataType, size_t>>* config = nullptr; if (stream.ExpectTag(kDelimitedTag(1))) { // Context @@ -1823,7 +1821,7 @@ Status FastParseSequenceExample( } auto limit = stream.PushLimit(length); while (!stream.ExpectAtEnd()) { - absl::string_view key, value; + StringPiece key, value; uint32 length; if (!stream.ExpectTag(kDelimitedTag(1)) || !stream.ReadVarint32(&length)) { diff --git a/tensorflow/core/util/memmapped_file_system.cc b/tensorflow/core/util/memmapped_file_system.cc index 35f0062556c..d3439cbc938 100644 --- a/tensorflow/core/util/memmapped_file_system.cc +++ b/tensorflow/core/util/memmapped_file_system.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/util/memmapped_file_system.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/protobuf.h" @@ -57,16 +56,16 @@ class RandomAccessFileFromMemmapped : public RandomAccessFile { ~RandomAccessFileFromMemmapped() override = default; - Status Read(uint64 offset, size_t to_read, absl::string_view* result, + Status Read(uint64 offset, size_t to_read, StringPiece* result, char* scratch) const override { if (offset >= length_) { - *result = absl::string_view(scratch, 0); + *result = StringPiece(scratch, 0); return Status(error::OUT_OF_RANGE, "Read after file end"); } const uint64 region_left = std::min(length_ - offset, static_cast<uint64>(to_read)); - *result = absl::string_view(reinterpret_cast<const char*>(data_) + offset, - region_left); + *result = + StringPiece(reinterpret_cast<const char*>(data_) + offset, region_left); return (region_left == to_read) ? Status::OK() : Status(error::OUT_OF_RANGE, "Read less bytes than requested"); diff --git a/tensorflow/core/util/memmapped_file_system_test.cc b/tensorflow/core/util/memmapped_file_system_test.cc index b5608ed6ccb..504d2d353f8 100644 --- a/tensorflow/core/util/memmapped_file_system_test.cc +++ b/tensorflow/core/util/memmapped_file_system_test.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/util/memmapped_file_system.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/framework/versions.pb.h" #include "tensorflow/core/graph/graph_def_builder.h" @@ -87,8 +86,8 @@ TEST(MemmappedFileSystemTest, SimpleTest) { // The memory region can be bigger but not less than Tensor size. ASSERT_GE(memory_region->length(), test_tensor.TotalBytes()); EXPECT_EQ(test_tensor.tensor_data(), - absl::string_view(static_cast<const char*>(memory_region->data()), - test_tensor.TotalBytes())); + StringPiece(static_cast<const char*>(memory_region->data()), + test_tensor.TotalBytes())); // Check that GetFileSize works. uint64 file_size = 0; TF_ASSERT_OK(memmapped_env.GetFileSize(kTensor2FileName, &file_size)); diff --git a/tensorflow/core/util/memmapped_file_system_writer.cc b/tensorflow/core/util/memmapped_file_system_writer.cc index a312a0d4d36..9556ee385f6 100644 --- a/tensorflow/core/util/memmapped_file_system_writer.cc +++ b/tensorflow/core/util/memmapped_file_system_writer.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/util/memmapped_file_system_writer.h" #include <algorithm> -#include "absl/strings/string_view.h" namespace tensorflow { @@ -81,7 +80,7 @@ Status MemmappedFileSystemWriter::SaveProtobuf( namespace { -absl::string_view EncodeUint64LittleEndian(uint64 val, char* output_buffer) { +StringPiece EncodeUint64LittleEndian(uint64 val, char* output_buffer) { for (unsigned int i = 0; i < sizeof(uint64); ++i) { output_buffer[i] = (val >> i * 8); } @@ -117,7 +116,7 @@ Status MemmappedFileSystemWriter::AdjustAlignment(uint64 alignment) { static constexpr uint64 kFillerBufferSize = 16; const char kFillerBuffer[kFillerBufferSize] = {}; for (uint64 rest = to_write_for_alignment; rest > 0;) { - absl::string_view sp(kFillerBuffer, std::min(rest, kFillerBufferSize)); + StringPiece sp(kFillerBuffer, std::min(rest, kFillerBufferSize)); TF_RETURN_IF_ERROR(output_file_->Append(sp)); rest -= sp.size(); output_file_offset_ += sp.size(); diff --git a/tensorflow/core/util/mirror_pad_mode.cc b/tensorflow/core/util/mirror_pad_mode.cc index 629a0b2de79..433d8aad55e 100644 --- a/tensorflow/core/util/mirror_pad_mode.cc +++ b/tensorflow/core/util/mirror_pad_mode.cc @@ -15,14 +15,13 @@ limitations under the License. #include "tensorflow/core/util/mirror_pad_mode.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/lib/core/errors.h" namespace tensorflow { -Status GetNodeAttr(const NodeDef& node_def, absl::string_view attr_name, +Status GetNodeAttr(const NodeDef& node_def, StringPiece attr_name, MirrorPadMode* value) { string str_value; TF_RETURN_IF_ERROR(GetNodeAttr(node_def, attr_name, &str_value)); diff --git a/tensorflow/core/util/mirror_pad_mode.h b/tensorflow/core/util/mirror_pad_mode.h index 026fd62503e..ceee9b06b03 100644 --- a/tensorflow/core/util/mirror_pad_mode.h +++ b/tensorflow/core/util/mirror_pad_mode.h @@ -21,7 +21,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" namespace tensorflow { @@ -45,7 +44,7 @@ string GetMirrorPadModeAttrString(); class NodeDef; // Specialization to parse an attribute directly into a MirrorPadMode enum. -Status GetNodeAttr(const NodeDef& node_def, absl::string_view attr_name, +Status GetNodeAttr(const NodeDef& node_def, StringPiece attr_name, MirrorPadMode* value); } // end namespace tensorflow diff --git a/tensorflow/core/util/padding.cc b/tensorflow/core/util/padding.cc index 1941d394c3d..117de5ee4bd 100644 --- a/tensorflow/core/util/padding.cc +++ b/tensorflow/core/util/padding.cc @@ -15,14 +15,13 @@ limitations under the License. #include "tensorflow/core/util/padding.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/lib/core/errors.h" namespace tensorflow { -Status GetNodeAttr(const NodeDef& node_def, absl::string_view attr_name, +Status GetNodeAttr(const NodeDef& node_def, StringPiece attr_name, Padding* value) { string str_value; TF_RETURN_IF_ERROR(GetNodeAttr(node_def, attr_name, &str_value)); diff --git a/tensorflow/core/util/padding.h b/tensorflow/core/util/padding.h index 4f94a8c4e46..76f9b4dd9a9 100644 --- a/tensorflow/core/util/padding.h +++ b/tensorflow/core/util/padding.h @@ -21,7 +21,6 @@ limitations under the License. #include <string> -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status.h" namespace tensorflow { @@ -46,7 +45,7 @@ enum Padding { string GetPaddingAttrString(); // Specialization to parse an attribute directly into a Padding enum. -Status GetNodeAttr(const NodeDef& node_def, absl::string_view attr_name, +Status GetNodeAttr(const NodeDef& node_def, StringPiece attr_name, Padding* value); } // end namespace tensorflow diff --git a/tensorflow/core/util/reporter_test.cc b/tensorflow/core/util/reporter_test.cc index 3d026f92383..0972b86ea5f 100644 --- a/tensorflow/core/util/reporter_test.cc +++ b/tensorflow/core/util/reporter_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include "tensorflow/core/util/reporter.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -29,7 +28,7 @@ namespace tensorflow { namespace { // Tests of all the error paths in log_reader.cc follow: -static void ExpectHasSubstr(absl::string_view s, absl::string_view expected) { +static void ExpectHasSubstr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << s << " does not contain " << expected; } diff --git a/tensorflow/core/util/saved_tensor_slice_util.cc b/tensorflow/core/util/saved_tensor_slice_util.cc index 9b753fca6e5..2040eac7e5b 100644 --- a/tensorflow/core/util/saved_tensor_slice_util.cc +++ b/tensorflow/core/util/saved_tensor_slice_util.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/core/util/saved_tensor_slice_util.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/ordered_code.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -45,7 +44,7 @@ string EncodeTensorNameSlice(const string& name, const TensorSlice& slice) { Status DecodeTensorNameSlice(const string& code, string* name, tensorflow::TensorSlice* slice) { - absl::string_view src(code); + StringPiece src(code); uint64 x; if (!tensorflow::strings::OrderedCode::ReadNumIncreasing(&src, &x)) { return errors::Internal("Failed to parse the leading number: src = ", src); diff --git a/tensorflow/core/util/semver_test.cc b/tensorflow/core/util/semver_test.cc index 667e7464443..fdc34fa58bd 100644 --- a/tensorflow/core/util/semver_test.cc +++ b/tensorflow/core/util/semver_test.cc @@ -13,10 +13,10 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/public/version.h" #include <string> +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" @@ -32,14 +32,14 @@ bool IsDotOrIdentifierChar(char c) { return false; } -bool ConsumeDotSeparatedIdentifiers(absl::string_view* s, const string& prefix, - absl::string_view* val) { +bool ConsumeDotSeparatedIdentifiers(StringPiece* s, const string& prefix, + StringPiece* val) { if (!str_util::ConsumePrefix(s, prefix)) return false; size_t i; for (i = 0; i < s->size() && IsDotOrIdentifierChar((*s)[i]); ++i) { // Intentionally empty } - *val = absl::string_view(s->data(), i); + *val = StringPiece(s->data(), i); s->remove_prefix(i); return i > 0; } @@ -50,8 +50,8 @@ TEST(SemverTest, VersionStringFollowsSemver) { // free to refine further (for example, check for leading 0s in numbers), but // avoid adding dependencies. uint64 major, minor, patch; - absl::string_view prerelease, metadata; - absl::string_view semver(TF_VERSION_STRING); + StringPiece prerelease, metadata; + StringPiece semver(TF_VERSION_STRING); ASSERT_TRUE(str_util::ConsumeLeadingDigits(&semver, &major)); ASSERT_TRUE(str_util::ConsumePrefix(&semver, ".")); diff --git a/tensorflow/core/util/tensor_bundle/BUILD b/tensorflow/core/util/tensor_bundle/BUILD index dfb6492f058..f40ec9b7522 100644 --- a/tensorflow/core/util/tensor_bundle/BUILD +++ b/tensorflow/core/util/tensor_bundle/BUILD @@ -45,7 +45,6 @@ cc_library( "//tensorflow/core:lib_internal", "//tensorflow/core:proto_text", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -59,10 +58,7 @@ cc_library( name = "naming", srcs = ["naming.cc"], hdrs = ["naming.h"], - deps = [ - "//tensorflow/core:lib", - "@com_google_absl//absl/strings", - ], + deps = ["//tensorflow/core:lib"], ) tf_cc_test( @@ -82,6 +78,5 @@ tf_cc_test( "//tensorflow/core:tensor_testutil", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/core/util/tensor_bundle/naming.cc b/tensorflow/core/util/tensor_bundle/naming.cc index fa6ce785b9c..db3d7ec3acc 100644 --- a/tensorflow/core/util/tensor_bundle/naming.cc +++ b/tensorflow/core/util/tensor_bundle/naming.cc @@ -15,19 +15,17 @@ limitations under the License. #include "tensorflow/core/util/tensor_bundle/naming.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { -string MetaFilename(absl::string_view prefix) { +string MetaFilename(StringPiece prefix) { return strings::Printf("%.*s.index", static_cast<int>(prefix.size()), prefix.data()); } -string DataFilename(absl::string_view prefix, int32 shard_id, - int32 num_shards) { +string DataFilename(StringPiece prefix, int32 shard_id, int32 num_shards) { DCHECK_GT(num_shards, 0); DCHECK_LT(shard_id, num_shards); return strings::Printf("%.*s.data-%05d-of-%05d", diff --git a/tensorflow/core/util/tensor_bundle/naming.h b/tensorflow/core/util/tensor_bundle/naming.h index 53c44ec3750..7b101971a8b 100644 --- a/tensorflow/core/util/tensor_bundle/naming.h +++ b/tensorflow/core/util/tensor_bundle/naming.h @@ -34,13 +34,13 @@ limitations under the License. #ifndef TENSORFLOW_CORE_UTIL_TENSOR_BUNDLE_NAMING_H_ #define TENSORFLOW_CORE_UTIL_TENSOR_BUNDLE_NAMING_H_ -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" namespace tensorflow { -string MetaFilename(absl::string_view prefix); -string DataFilename(absl::string_view prefix, int32 shard_id, int32 num_shards); +string MetaFilename(StringPiece prefix); +string DataFilename(StringPiece prefix, int32 shard_id, int32 num_shards); } // namespace tensorflow diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc index 5a14ac5f605..2dcb57a1f9b 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc @@ -21,7 +21,6 @@ limitations under the License. #include <memory> #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor_shape.pb_text.h" @@ -198,7 +197,7 @@ string* GetStringBackingBuffer(const Tensor& val) { return const_cast<string*>(val.flat<string>().data()); } -Status ParseEntryProto(absl::string_view key, absl::string_view value, +Status ParseEntryProto(StringPiece key, StringPiece value, protobuf::MessageLite* out) { if (!out->ParseFromArray(value.data(), value.size())) { return errors::DataLoss("Entry for key ", key, " not parseable."); @@ -217,7 +216,7 @@ Status WriteTensor(const Tensor& val, FileOutputBuffer* out, *bytes_written = val.TotalBytes(); char* buf = GetBackingBuffer(val); VLOG(1) << "Appending " << *bytes_written << " bytes to file"; - return out->Append(absl::string_view(buf, *bytes_written)); + return out->Append(StringPiece(buf, *bytes_written)); } // Serializes string tensor "val". "bytes_written" is treated in the same @@ -261,7 +260,7 @@ Status WriteStringTensor(const Tensor& val, FileOutputBuffer* out, // Writes the length checksum. const uint32 length_checksum = crc32c::Mask(*crc32c); - TF_RETURN_IF_ERROR(out->Append(absl::string_view( + TF_RETURN_IF_ERROR(out->Append(StringPiece( reinterpret_cast<const char*>(&length_checksum), sizeof(uint32)))); *crc32c = crc32c::Extend( *crc32c, reinterpret_cast<const char*>(&length_checksum), sizeof(uint32)); @@ -314,7 +313,7 @@ Status WriteVariantTensor(const Tensor& val, FileOutputBuffer* out, // Write the checksum. const uint32 length_checksum = crc32c::Mask(*crc32c); - TF_RETURN_IF_ERROR(out->Append(absl::string_view( + TF_RETURN_IF_ERROR(out->Append(StringPiece( reinterpret_cast<const char*>(&length_checksum), sizeof(uint32)))); *crc32c = crc32c::Extend(*crc32c, reinterpret_cast<const char*>(&length_checksum), @@ -386,8 +385,7 @@ Status PadAlignment(FileOutputBuffer* out, int alignment, int64* size) { } // namespace -BundleWriter::BundleWriter(Env* env, absl::string_view prefix, - const Options& options) +BundleWriter::BundleWriter(Env* env, StringPiece prefix, const Options& options) : env_(env), options_(options), prefix_(prefix), @@ -411,7 +409,7 @@ BundleWriter::BundleWriter(Env* env, absl::string_view prefix, VLOG(1) << "Writing to file " << tmp_data_path_; } -Status BundleWriter::Add(absl::string_view key, const Tensor& val) { +Status BundleWriter::Add(StringPiece key, const Tensor& val) { if (!status_.ok()) return status_; CHECK_NE(key, kHeaderEntryKey); const string key_string(key); @@ -448,7 +446,7 @@ Status BundleWriter::Add(absl::string_view key, const Tensor& val) { return status_; } -Status BundleWriter::AddSlice(absl::string_view full_tensor_key, +Status BundleWriter::AddSlice(StringPiece full_tensor_key, const TensorShape& full_tensor_shape, const TensorSlice& slice_spec, const Tensor& slice_tensor) { @@ -565,7 +563,7 @@ struct MergeState { // Merges entries of "prefix" into the accumulator state "merge". // Returns OK iff the merge succeeds. -static Status MergeOneBundle(Env* env, absl::string_view prefix, +static Status MergeOneBundle(Env* env, StringPiece prefix, MergeState* merge_state) { VLOG(1) << "Merging bundle:" << prefix; const string filename = MetaFilename(prefix); @@ -665,7 +663,7 @@ static Status MergeOneBundle(Env* env, absl::string_view prefix, } Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, - absl::string_view merged_prefix) { + StringPiece merged_prefix) { // Merges all metadata tables. // TODO(zhifengc): KeyValue sorter if it becomes too big. MergeState merge; @@ -715,7 +713,7 @@ Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, // Interface for reading a tensor bundle. -BundleReader::BundleReader(Env* env, absl::string_view prefix) +BundleReader::BundleReader(Env* env, StringPiece prefix) : env_(env), prefix_(prefix), metadata_(nullptr), @@ -774,7 +772,7 @@ BundleReader::~BundleReader() { gtl::STLDeleteValues(&tensor_slices_); } -Status BundleReader::GetBundleEntryProto(absl::string_view key, +Status BundleReader::GetBundleEntryProto(StringPiece key, BundleEntryProto* entry) { entry->Clear(); TF_CHECK_OK(status_); @@ -843,7 +841,7 @@ Status BundleReader::GetValue(const BundleEntryProto& entry, Tensor* val) { char* backing_buffer = const_cast<char*>((ret->tensor_data().data())); size_t unused_bytes_read; if (entry.size() > kBufferSize) { - absl::string_view sp; + StringPiece sp; TF_RETURN_IF_ERROR(buffered_file->file()->Read( entry.offset(), entry.size(), &sp, backing_buffer)); if (sp.data() != backing_buffer) { @@ -878,7 +876,7 @@ Status BundleReader::GetValue(const BundleEntryProto& entry, Tensor* val) { return Status::OK(); } -Status BundleReader::Lookup(absl::string_view key, Tensor* val) { +Status BundleReader::Lookup(StringPiece key, Tensor* val) { CHECK(val != nullptr); BundleEntryProto entry; TF_RETURN_IF_ERROR(GetBundleEntryProto(key, &entry)); @@ -910,7 +908,7 @@ Status BundleReader::ReadCurrent(Tensor* val) { } } -Status BundleReader::LookupTensorSlices(absl::string_view key, +Status BundleReader::LookupTensorSlices(StringPiece key, std::vector<TensorSlice>* slices) { slices->clear(); BundleEntryProto entry; @@ -922,7 +920,7 @@ Status BundleReader::LookupTensorSlices(absl::string_view key, return Status::OK(); } -Status BundleReader::LookupSlice(absl::string_view full_tensor_key, +Status BundleReader::LookupSlice(StringPiece full_tensor_key, const TensorSlice& slice_spec, Tensor* val) { CHECK(val != nullptr); BundleEntryProto entry; @@ -930,7 +928,7 @@ Status BundleReader::LookupSlice(absl::string_view full_tensor_key, return GetSliceValue(full_tensor_key, entry, slice_spec, val); } -Status BundleReader::GetSliceValue(absl::string_view full_tensor_key, +Status BundleReader::GetSliceValue(StringPiece full_tensor_key, const BundleEntryProto& full_tensor_entry, const TensorSlice& slice_spec, Tensor* val) { using checkpoint::RegisterTensorSlice; @@ -1044,12 +1042,12 @@ Status BundleReader::GetSliceValue(absl::string_view full_tensor_key, return Status::OK(); } -bool BundleReader::Contains(absl::string_view key) { +bool BundleReader::Contains(StringPiece key) { Seek(key); return Valid() && (this->key() == key); } -Status BundleReader::LookupDtypeAndShape(absl::string_view key, DataType* dtype, +Status BundleReader::LookupDtypeAndShape(StringPiece key, DataType* dtype, TensorShape* shape) { BundleEntryProto entry; TF_RETURN_IF_ERROR(GetBundleEntryProto(key, &entry)); @@ -1058,8 +1056,7 @@ Status BundleReader::LookupDtypeAndShape(absl::string_view key, DataType* dtype, return Status::OK(); } -Status BundleReader::LookupTensorShape(absl::string_view key, - TensorShape* shape) { +Status BundleReader::LookupTensorShape(StringPiece key, TensorShape* shape) { DataType ignored; return LookupDtypeAndShape(key, &ignored, shape); } @@ -1083,7 +1080,7 @@ string BundleReader::DebugString() { FileOutputBuffer::~FileOutputBuffer() { delete file_; } -Status FileOutputBuffer::Append(absl::string_view data) { +Status FileOutputBuffer::Append(StringPiece data) { // In the below, it is critical to calculate the checksum on the actually // copied bytes, not the source bytes. This is because "data" typically // points to tensor buffers, which may be concurrently written. @@ -1120,8 +1117,7 @@ Status FileOutputBuffer::Close() { Status FileOutputBuffer::FlushBuffer() { if (position_ > 0) { - TF_RETURN_IF_ERROR( - file_->Append(absl::string_view(&buffer_[0], position_))); + TF_RETURN_IF_ERROR(file_->Append(StringPiece(&buffer_[0], position_))); position_ = 0; } return Status::OK(); diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle.h b/tensorflow/core/util/tensor_bundle/tensor_bundle.h index f9a628fc33f..3a2ffbb4952 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle.h +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle.h @@ -61,7 +61,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_UTIL_TENSOR_BUNDLE_TENSOR_BUNDLE_H_ #define TENSORFLOW_CORE_UTIL_TENSOR_BUNDLE_TENSOR_BUNDLE_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/protobuf/tensor_bundle.pb.h" #include <map> @@ -114,12 +113,12 @@ class BundleWriter { // Must be >= 1. The default size of 1 densely packs tensors. int data_alignment{1}; }; - BundleWriter(Env* env, absl::string_view prefix, + BundleWriter(Env* env, StringPiece prefix, const Options& options = Options()); // Adds the tensor "val" under key "key". // Across calls "key" must be unique but can be added in any order. - Status Add(absl::string_view key, const Tensor& val); + Status Add(StringPiece key, const Tensor& val); // Partitioned variables support. // A slice of a full tensor is stored in two entries in the metadata table: @@ -137,7 +136,7 @@ class BundleWriter { // consistent entry for "full_tensor_key" is produced. // // Returns an error if the same slice is added the second time. - Status AddSlice(absl::string_view full_tensor_key, + Status AddSlice(StringPiece full_tensor_key, const TensorShape& full_tensor_shape, const TensorSlice& slice_spec, const Tensor& slice_tensor); @@ -174,7 +173,7 @@ class BundleWriter { // Once merged, makes a best effort to delete the old metadata files. // Returns OK iff all bundles are successfully merged. Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, - absl::string_view merged_prefix); + StringPiece merged_prefix); // On construction, silently attempts to read the metadata associated with // "prefix". If caller intends to call any function afterwards, "status()" @@ -182,7 +181,7 @@ Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, // All threads accessing the same BundleReader must synchronize. class BundleReader { public: - BundleReader(Env* const env, absl::string_view prefix); + BundleReader(Env* const env, StringPiece prefix); ~BundleReader(); // Is ok() iff the reader construction is successful (completed the read of @@ -192,17 +191,17 @@ class BundleReader { // Queries whether the bundle contains an entry keyed by "key". Calls Seek() // internally, so this call invalidates the reader's current position. // REQUIRES: status().ok() - bool Contains(absl::string_view key); + bool Contains(StringPiece key); // Looks up the dtype and the shape of the tensor keyed by "key". // REQUIRES: status().ok() - Status LookupDtypeAndShape(absl::string_view key, DataType* dtype, + Status LookupDtypeAndShape(StringPiece key, DataType* dtype, TensorShape* shape) TF_MUST_USE_RESULT; // Looks up the shape of the tensor keyed by "key". // Clears "shape" if not found. // REQUIRES: status().ok() - Status LookupTensorShape(absl::string_view key, + Status LookupTensorShape(StringPiece key, TensorShape* shape) TF_MUST_USE_RESULT; // Looks up the tensor keyed by "key". If "key" refers to a partitioned @@ -217,7 +216,7 @@ class BundleReader { // // Validates the stored crc32c checksum against the restored bytes. // REQUIRES: status().ok() - Status Lookup(absl::string_view key, Tensor* val) TF_MUST_USE_RESULT; + Status Lookup(StringPiece key, Tensor* val) TF_MUST_USE_RESULT; // Looks up the tensor pointed to by the internal iterator. // @@ -234,21 +233,19 @@ class BundleReader { // a slice with a larger start index in some dimension could come before // another slice with a smaller start index in the same dimension. // REQUIRES: status().ok() - Status LookupTensorSlices(absl::string_view key, - std::vector<TensorSlice>* slices) + Status LookupTensorSlices(StringPiece key, std::vector<TensorSlice>* slices) TF_MUST_USE_RESULT; // Looks up a specific slice of a partitioned tensor. // It is only required that the stored slices cover the requested slice, // namely "slice_spec" is a subset of the union of the stored slices. // REQUIRES: status().ok() - Status LookupSlice(absl::string_view full_tensor_key, - const TensorSlice& slice_spec, + Status LookupSlice(StringPiece full_tensor_key, const TensorSlice& slice_spec, Tensor* val) TF_MUST_USE_RESULT; // Seeks to the first position in the bundle whose key is no less than "key". // REQUIRES: status().ok() - void Seek(absl::string_view key) { return iter_->Seek(key); } + void Seek(StringPiece key) { return iter_->Seek(key); } // Moves to the next position in the bundle. // REQUIRES: status().ok() void Next() const { iter_->Next(); } @@ -258,10 +255,10 @@ class BundleReader { // Returns the key at the current position. // REQUIRES: status().ok() && Valid() - absl::string_view key() const { return iter_->key(); } + StringPiece key() const { return iter_->key(); } // Returns the raw value at the current position. // REQUIRES: status().ok() && Valid() - absl::string_view value() const { return iter_->value(); } + StringPiece value() const { return iter_->value(); } string DebugString(); @@ -269,7 +266,7 @@ class BundleReader { // Seeks for "key" and reads the metadata proto. // On non-OK return, clears "entry" for the caller. // REQUIRES: status().ok() - Status GetBundleEntryProto(absl::string_view key, + Status GetBundleEntryProto(StringPiece key, BundleEntryProto* entry) TF_MUST_USE_RESULT; // Reads the tensor value described by the metadata proto "entry". @@ -280,7 +277,7 @@ class BundleReader { // Reads the slice described by "slice_spec". The corresponding full tensor // has key "ful_tensor_key" and metadata proto "full_tensor_entry". // REQUIRES: full_tensor_entry.slices_size() > 0 - Status GetSliceValue(absl::string_view full_tensor_key, + Status GetSliceValue(StringPiece full_tensor_key, const BundleEntryProto& full_tensor_entry, const TensorSlice& slice_spec, Tensor* val) TF_MUST_USE_RESULT; @@ -321,7 +318,7 @@ class FileOutputBuffer { ~FileOutputBuffer(); // Buffered append. - Status Append(absl::string_view data); + Status Append(StringPiece data); // Returns the running crc32c checksum of all currently appended bytes. uint32 crc32c() { return crc32c_; } diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc b/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc index eecf97fde54..9567e4750b7 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc @@ -18,7 +18,6 @@ limitations under the License. #include <random> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/variant.h" @@ -282,7 +281,7 @@ void TestNonStandardShapes() { } // Writes a bundle to disk with a bad "version"; checks for "expected_error". -void VersionTest(const VersionDef& version, absl::string_view expected_error) { +void VersionTest(const VersionDef& version, StringPiece expected_error) { const string path = Prefix("version_test"); { // Prepare an empty bundle with the given version information. @@ -611,7 +610,7 @@ TEST(TensorBundleTest, DirectoryStructure) { // Ensures we have the expected files. auto CheckDirFiles = [env](const string& bundle_prefix, gtl::ArraySlice<string> expected_files) { - absl::string_view dir = io::Dirname(bundle_prefix); + StringPiece dir = io::Dirname(bundle_prefix); for (const string& expected_file : expected_files) { TF_EXPECT_OK(env->FileExists(io::JoinPath(dir, expected_file))); } @@ -755,8 +754,8 @@ TEST(TensorBundleTest, TruncatedTensorContents) { string data; TF_ASSERT_OK(ReadFileToString(env, datafile, &data)); ASSERT_TRUE(!data.empty()); - TF_ASSERT_OK(WriteStringToFile( - env, datafile, absl::string_view(data.data(), data.size() - 1))); + TF_ASSERT_OK(WriteStringToFile(env, datafile, + StringPiece(data.data(), data.size() - 1))); BundleReader reader(env, Prefix("end")); TF_ASSERT_OK(reader.status()); diff --git a/tensorflow/core/util/tensor_slice_reader.cc b/tensorflow/core/util/tensor_slice_reader.cc index f77150cf0d6..c6dda2ec298 100644 --- a/tensorflow/core/util/tensor_slice_reader.cc +++ b/tensorflow/core/util/tensor_slice_reader.cc @@ -17,7 +17,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/types.pb_text.h" #include "tensorflow/core/framework/versions.h" #include "tensorflow/core/lib/core/errors.h" @@ -54,7 +53,7 @@ class TensorSliceReaderTable : public TensorSliceReader::Table { std::unique_ptr<table::Iterator> iter(table_->NewIterator()); iter->Seek(key); if (iter->Valid() && iter->key() == key) { - absl::string_view v = iter->value(); + StringPiece v = iter->value(); value->assign(v.data(), v.size()); return true; } else { diff --git a/tensorflow/core/util/tensor_slice_writer.cc b/tensorflow/core/util/tensor_slice_writer.cc index d0d6b6ced85..7ebde002e16 100644 --- a/tensorflow/core/util/tensor_slice_writer.cc +++ b/tensorflow/core/util/tensor_slice_writer.cc @@ -17,7 +17,6 @@ limitations under the License. #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/versions.pb.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/io/table_builder.h" @@ -41,7 +40,7 @@ class TableBuilder : public TensorSliceWriter::Builder { option.compression = table::kNoCompression; builder_.reset(new table::TableBuilder(option, f)); } - void Add(absl::string_view key, absl::string_view val) override { + void Add(StringPiece key, StringPiece val) override { builder_->Add(key, val); } Status Finish(int64* file_size) override { diff --git a/tensorflow/core/util/tensor_slice_writer.h b/tensorflow/core/util/tensor_slice_writer.h index de986296545..0db2fb48047 100644 --- a/tensorflow/core/util/tensor_slice_writer.h +++ b/tensorflow/core/util/tensor_slice_writer.h @@ -21,12 +21,12 @@ limitations under the License. #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_slice.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" @@ -46,7 +46,7 @@ class TensorSliceWriter { class Builder { public: virtual ~Builder() {} - virtual void Add(absl::string_view key, absl::string_view value) = 0; + virtual void Add(StringPiece key, StringPiece value) = 0; virtual Status Finish(int64* file_size) = 0; }; typedef std::function<Status(const string&, Builder**)> CreateBuilderFunction; diff --git a/tensorflow/core/util/util.cc b/tensorflow/core/util/util.cc index 6e1e86ff94d..489999d1e85 100644 --- a/tensorflow/core/util/util.cc +++ b/tensorflow/core/util/util.cc @@ -15,30 +15,29 @@ limitations under the License. #include "tensorflow/core/util/util.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { -absl::string_view NodeNamePrefix(const absl::string_view& op_name) { - absl::string_view sp(op_name); +StringPiece NodeNamePrefix(const StringPiece& op_name) { + StringPiece sp(op_name); auto p = sp.find('/'); - if (p == absl::string_view::npos || p == 0) { + if (p == StringPiece::npos || p == 0) { return ""; } else { - return absl::string_view(sp.data(), p); + return StringPiece(sp.data(), p); } } -absl::string_view NodeNameFullPrefix(const absl::string_view& op_name) { - absl::string_view sp(op_name); +StringPiece NodeNameFullPrefix(const StringPiece& op_name) { + StringPiece sp(op_name); auto p = sp.rfind('/'); - if (p == absl::string_view::npos || p == 0) { + if (p == StringPiece::npos || p == 0) { return ""; } else { - return absl::string_view(sp.data(), p); + return StringPiece(sp.data(), p); } } diff --git a/tensorflow/core/util/util.h b/tensorflow/core/util/util.h index 2e913e17cf1..4aa47aa48a2 100644 --- a/tensorflow/core/util/util.h +++ b/tensorflow/core/util/util.h @@ -16,18 +16,18 @@ limitations under the License. #ifndef TENSORFLOW_CORE_UTIL_UTIL_H_ #define TENSORFLOW_CORE_UTIL_UTIL_H_ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/tensor_shape.h" +#include "tensorflow/core/lib/core/stringpiece.h" namespace tensorflow { // If op_name has '/' in it, then return everything before the first '/'. // Otherwise return empty string. -absl::string_view NodeNamePrefix(const absl::string_view& op_name); +StringPiece NodeNamePrefix(const StringPiece& op_name); // If op_name has '/' in it, then return everything before the last '/'. // Otherwise return empty string. -absl::string_view NodeNameFullPrefix(const absl::string_view& op_name); +StringPiece NodeNameFullPrefix(const StringPiece& op_name); class MovingAverage { public: diff --git a/tensorflow/examples/label_image/BUILD b/tensorflow/examples/label_image/BUILD index c9421f35cac..c50fd93d039 100644 --- a/tensorflow/examples/label_image/BUILD +++ b/tensorflow/examples/label_image/BUILD @@ -50,7 +50,7 @@ tf_cc_binary( "//tensorflow/core:protos_all_cc", "//tensorflow/core:tensorflow", ], - }) + ["@com_google_absl//absl/strings"], + }), ) py_binary( diff --git a/tensorflow/examples/label_image/main.cc b/tensorflow/examples/label_image/main.cc index dbab8c3e5a5..ee2927d0a53 100644 --- a/tensorflow/examples/label_image/main.cc +++ b/tensorflow/examples/label_image/main.cc @@ -38,7 +38,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/const_op.h" #include "tensorflow/cc/ops/image_ops.h" #include "tensorflow/cc/ops/standard_ops.h" @@ -47,6 +46,7 @@ limitations under the License. #include "tensorflow/core/graph/default_device.h" #include "tensorflow/core/graph/graph_def_builder.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/threadpool.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -99,7 +99,7 @@ static Status ReadEntireFile(tensorflow::Env* env, const string& filename, std::unique_ptr<tensorflow::RandomAccessFile> file; TF_RETURN_IF_ERROR(env->NewRandomAccessFile(filename, &file)); - absl::string_view data; + tensorflow::StringPiece data; TF_RETURN_IF_ERROR(file->Read(0, file_size, &data, &(contents)[0])); if (data.size() != file_size) { return tensorflow::errors::DataLoss("Truncated read of '", filename, diff --git a/tensorflow/java/BUILD b/tensorflow/java/BUILD index f1b90059651..9dce78b9a36 100644 --- a/tensorflow/java/BUILD +++ b/tensorflow/java/BUILD @@ -121,7 +121,6 @@ cc_library( "//tensorflow/core:lib_internal", "//tensorflow/core:op_gen_lib", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", "@com_googlesource_code_re2//:re2", ], ) diff --git a/tensorflow/java/src/gen/cc/op_specs.cc b/tensorflow/java/src/gen/cc/op_specs.cc index 2324a36f905..4f5a491d259 100644 --- a/tensorflow/java/src/gen/cc/op_specs.cc +++ b/tensorflow/java/src/gen/cc/op_specs.cc @@ -18,7 +18,6 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/types.h" @@ -130,7 +129,7 @@ std::pair<Type, Type> TypeResolver::TypesOf(const OpDef_AttrDef& attr_def, bool* iterable_out) { std::pair<Type, Type> types = MakeTypePair(Type::Wildcard()); *iterable_out = false; - absl::string_view attr_type = attr_def.type(); + StringPiece attr_type = attr_def.type(); if (str_util::ConsumePrefix(&attr_type, "list(")) { attr_type.remove_suffix(1); // remove closing brace *iterable_out = true; diff --git a/tensorflow/java/src/gen/cc/source_writer.cc b/tensorflow/java/src/gen/cc/source_writer.cc index 757b7ae5521..a71b367691d 100644 --- a/tensorflow/java/src/gen/cc/source_writer.cc +++ b/tensorflow/java/src/gen/cc/source_writer.cc @@ -17,7 +17,6 @@ limitations under the License. #include <algorithm> #include <list> -#include "absl/strings/string_view.h" #include "tensorflow/java/src/gen/cc/source_writer.h" namespace tensorflow { @@ -49,7 +48,7 @@ SourceWriter& SourceWriter::Prefix(const char* line_prefix) { return *this; } -SourceWriter& SourceWriter::Write(const absl::string_view& str) { +SourceWriter& SourceWriter::Write(const StringPiece& str) { size_t line_pos = 0; do { size_t start_pos = line_pos; @@ -72,7 +71,7 @@ SourceWriter& SourceWriter::WriteFromFile(const string& fname, Env* env) { return Write(data_); } -SourceWriter& SourceWriter::Append(const absl::string_view& str) { +SourceWriter& SourceWriter::Append(const StringPiece& str) { if (!str.empty()) { if (newline_) { DoAppend(left_margin_ + line_prefix_); diff --git a/tensorflow/java/src/gen/cc/source_writer.h b/tensorflow/java/src/gen/cc/source_writer.h index ce444cd836b..de0113bd5b7 100644 --- a/tensorflow/java/src/gen/cc/source_writer.h +++ b/tensorflow/java/src/gen/cc/source_writer.h @@ -21,7 +21,7 @@ limitations under the License. #include <list> #include <set> -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/java/src/gen/cc/java_defs.h" @@ -61,7 +61,7 @@ class SourceWriter { // The data might potentially contain newline characters, therefore it will // be scanned to ensure that each line is indented and prefixed properly, // making it a bit slower than Append(). - SourceWriter& Write(const absl::string_view& str); + SourceWriter& Write(const StringPiece& str); // Writes a source code snippet read from a file. // @@ -74,7 +74,7 @@ class SourceWriter { // // It is expected that no newline character is present in the data provided, // otherwise Write() must be used. - SourceWriter& Append(const absl::string_view& str); + SourceWriter& Append(const StringPiece& str); // Appends a type to the current line. // @@ -153,7 +153,7 @@ class SourceWriter { const Javadoc* javadoc = nullptr); protected: - virtual void DoAppend(const absl::string_view& str) = 0; + virtual void DoAppend(const StringPiece& str) = 0; private: // A utility base class for visiting elements of a type. @@ -223,7 +223,7 @@ class SourceFileWriter : public SourceWriter { virtual ~SourceFileWriter() = default; protected: - void DoAppend(const absl::string_view& str) override { + void DoAppend(const StringPiece& str) override { TF_CHECK_OK(file_->Append(str)); } @@ -243,7 +243,7 @@ class SourceBufferWriter : public SourceWriter { const string& str() { return *buffer_; } protected: - void DoAppend(const absl::string_view& str) override { + void DoAppend(const StringPiece& str) override { buffer_->append(str.begin(), str.end()); } diff --git a/tensorflow/js/BUILD b/tensorflow/js/BUILD index 6866e4e9fca..ad0dc44f549 100644 --- a/tensorflow/js/BUILD +++ b/tensorflow/js/BUILD @@ -48,6 +48,5 @@ tf_cc_test( "//tensorflow/core:protos_all_cc", "//tensorflow/core:test", "//tensorflow/core:test_main", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/js/ops/ts_op_gen_test.cc b/tensorflow/js/ops/ts_op_gen_test.cc index 1c4061e6ee0..03241689b5f 100644 --- a/tensorflow/js/ops/ts_op_gen_test.cc +++ b/tensorflow/js/ops/ts_op_gen_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/js/ops/ts_op_gen.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_gen_lib.h" #include "tensorflow/core/lib/core/status_test_util.h" @@ -27,12 +26,12 @@ limitations under the License. namespace tensorflow { namespace { -void ExpectContainsStr(absl::string_view s, absl::string_view expected) { +void ExpectContainsStr(StringPiece s, StringPiece expected) { EXPECT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } -void ExpectDoesNotContainStr(absl::string_view s, absl::string_view expected) { +void ExpectDoesNotContainStr(StringPiece s, StringPiece expected) { EXPECT_FALSE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/python/BUILD b/tensorflow/python/BUILD index ae4d67363df..c7490176276 100644 --- a/tensorflow/python/BUILD +++ b/tensorflow/python/BUILD @@ -336,7 +336,6 @@ cc_library( "//tensorflow/core:lib_internal", "//third_party/python_runtime:headers", "@com_google_absl//absl/memory", - "@com_google_absl//absl/strings", ], ) @@ -359,7 +358,6 @@ cc_library( "//tensorflow/python/eager:pywrap_tfe_lib", "//third_party/py/numpy:headers", "//third_party/python_runtime:headers", - "@com_google_absl//absl/strings", ], ) @@ -439,7 +437,6 @@ cc_library( "//tensorflow/c:tf_status_helper", "//tensorflow/core:lib", "//tensorflow/core:lib_internal", - "@com_google_absl//absl/strings", ], ) @@ -457,7 +454,6 @@ tf_cc_shared_object( deps = [ "//tensorflow/core:framework_headers_lib", "//third_party/eigen3", - "@com_google_absl//absl/strings", "@protobuf_archive//:protobuf_headers", ], ) @@ -546,7 +542,6 @@ cc_library( "//tensorflow/core:op_gen_lib", "//tensorflow/core:proto_text", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], alwayslink = 1, ) @@ -562,7 +557,6 @@ cc_library( "//tensorflow/core:lib_internal", "//tensorflow/core:op_gen_lib", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/python/eager/pywrap_tfe_src.cc b/tensorflow/python/eager/pywrap_tfe_src.cc index cb8ac33f0ac..dcbe6d42bd4 100644 --- a/tensorflow/python/eager/pywrap_tfe_src.cc +++ b/tensorflow/python/eager/pywrap_tfe_src.cc @@ -15,7 +15,6 @@ limitations under the License. #include <thread> -#include "absl/strings/string_view.h" #include "tensorflow/python/eager/pywrap_tfe.h" #include "absl/strings/str_cat.h" @@ -208,12 +207,12 @@ bool ParseDimensionValue(const string& key, PyObject* py_value, } bool ParseStringValue(const string& key, PyObject* py_value, TF_Status* status, - absl::string_view* value) { + tensorflow::StringPiece* value) { if (PyBytes_Check(py_value)) { Py_ssize_t size = 0; char* buf = nullptr; if (PyBytes_AsStringAndSize(py_value, &buf, &size) < 0) return false; - *value = absl::string_view(buf, size); + *value = tensorflow::StringPiece(buf, size); return true; } #if PY_MAJOR_VERSION >= 3 @@ -287,7 +286,7 @@ bool SetOpAttrList( std::unique_ptr<const void*[]> values(new const void*[num_values]); std::unique_ptr<size_t[]> lengths(new size_t[num_values]); for (int i = 0; i < num_values; ++i) { - absl::string_view value; + tensorflow::StringPiece value; tensorflow::Safe_PyObjectPtr py_value(PySequence_ITEM(py_list, i)); if (!ParseStringValue(key, py_value.get(), status, &value)) return false; values[i] = value.data(); @@ -490,7 +489,7 @@ bool SetOpAttrScalar( tensorflow::gtl::FlatMap<string, tensorflow::int64>* attr_list_sizes, TF_Status* status) { if (type == TF_ATTR_STRING) { - absl::string_view value; + tensorflow::StringPiece value; if (!ParseStringValue(key, py_value, status, &value)) return false; TFE_OpSetAttrString(op, key, value.data(), value.size()); } else if (type == TF_ATTR_INT) { @@ -553,7 +552,7 @@ bool SetOpAttrScalar( // (which is what the various "defun" or "Defun" decorators do). // And in the future also allow an object that can encapsulate // the function name and its attribute values. - absl::string_view func_name; + tensorflow::StringPiece func_name; if (!ParseStringValue(key, py_value, status, &func_name)) { PyObject* name_attr = PyObject_GetAttrString(py_value, "name"); if (name_attr == nullptr || @@ -2485,7 +2484,7 @@ PyObject* TFE_Py_FastPathExecute_C(PyObject*, PyObject* args) { for (int i = kFastPathExecuteInputStartIndex + op_def->input_arg_size(); i < args_size; i += 2) { PyObject* py_attr_name = PyTuple_GET_ITEM(args, i); - const absl::string_view attr_name(TFE_GetPythonString(py_attr_name)); + const tensorflow::StringPiece attr_name(TFE_GetPythonString(py_attr_name)); PyObject* py_attr_value = PyTuple_GET_ITEM(args, i + 1); // Not creating an index since most of the time there are not more than a diff --git a/tensorflow/python/framework/python_op_gen.cc b/tensorflow/python/framework/python_op_gen.cc index f21900ba674..2022fbcbaad 100644 --- a/tensorflow/python/framework/python_op_gen.cc +++ b/tensorflow/python/framework/python_op_gen.cc @@ -17,7 +17,6 @@ limitations under the License. #include <stdio.h> #include <sstream> #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/op.h" @@ -161,7 +160,7 @@ class GenEagerPythonOp : public python_op_gen_internal::GenPythonOp { string FlattenInputs(const std::vector<int>* input_indices, std::vector<string>* output_sizes) const; - absl::string_view op_name_; + StringPiece op_name_; typedef std::unordered_map<string, std::vector<int>> AttrToArgMap; AttrToArgMap attr_to_args_; std::unordered_map<string, string> attr_expressions_; @@ -474,7 +473,7 @@ bool GenEagerPythonOp::GetEagerFunctionSetup(const string& indentation, const auto& param = param_names_[i + op_def_.input_arg_size()]; const auto& attr = *FindAttr(attr_name, op_def_); const string& attr_api_name = param.GetRenameTo(); - absl::string_view attr_type = attr.type(); + StringPiece attr_type = attr.type(); attr_expressions_[attr_name] = attr_api_name; const int default_index = i - (attrs_.size() - params_with_default_.size()); if (default_index >= 0) { diff --git a/tensorflow/python/framework/python_op_gen_internal.cc b/tensorflow/python/framework/python_op_gen_internal.cc index 5024cf06259..f6aef5bc50b 100644 --- a/tensorflow/python/framework/python_op_gen_internal.cc +++ b/tensorflow/python/framework/python_op_gen_internal.cc @@ -20,16 +20,15 @@ limitations under the License. #include <iomanip> #include <sstream> #include <unordered_map> -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/op.h" -#include "tensorflow/core/framework/op_def.pb_text.h" #include "tensorflow/core/framework/op_def.pb.h" +#include "tensorflow/core/framework/op_def.pb_text.h" #include "tensorflow/core/framework/op_def_util.h" #include "tensorflow/core/framework/op_gen_lib.h" -#include "tensorflow/core/framework/tensor.pb_text.h" #include "tensorflow/core/framework/tensor.pb.h" +#include "tensorflow/core/framework/tensor.pb_text.h" #include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.pb.h" @@ -111,7 +110,7 @@ string AvoidPythonReserved(const string& s) { // Indent the first line by "initial" spaces and all following lines // by "rest" spaces. -string Indent(int initial, int rest, absl::string_view in) { +string Indent(int initial, int rest, StringPiece in) { // TODO(josh11b): Also word-wrapping? string copy(in.data(), in.size()); str_util::StripTrailingWhitespace(©); @@ -136,7 +135,7 @@ string Indent(int initial, int rest, absl::string_view in) { // Adds append to *dest, with a space if the first line will be <= width, // or a newline otherwise. -void AppendWithinWidth(string* dest, absl::string_view append, int width) { +void AppendWithinWidth(string* dest, StringPiece append, int width) { auto first_line = append.find('\n'); if (first_line == string::npos) first_line = append.size(); if (dest->size() + first_line + 1 /* space */ > static_cast<size_t>(width)) { @@ -284,7 +283,7 @@ string GetReturns(const OpDef& op_def, strings::StrAppend(&result, " The created Operation.\n"); } else { if (num_outs == 1) { - absl::string_view description = op_def.output_arg(0).description(); + StringPiece description = op_def.output_arg(0).description(); if (ConsumeEquals(&description)) { // Skip the generated type info. strings::StrAppend(&result, Indent(4, 4, description)); } else { @@ -320,7 +319,7 @@ string GetReturns(const OpDef& op_def, str_util::Join(out_names, ", "), ").\n\n"); for (int i = 0; i < num_outs; ++i) { string desc = strings::StrCat(out_names[i], ": "); - absl::string_view description = op_def.output_arg(i).description(); + StringPiece description = op_def.output_arg(i).description(); if (ConsumeEquals(&description)) { // Skip the generated type info. strings::StrAppend(&desc, description); } else { @@ -482,7 +481,7 @@ static void AddDelimiter(string* append_to, const string& delim) { if (!append_to->empty()) strings::StrAppend(append_to, delim); } -const ApiDef::Attr* FindAttr(absl::string_view name, const ApiDef& api_def) { +const ApiDef::Attr* FindAttr(StringPiece name, const ApiDef& api_def) { for (int i = 0; i < api_def.attr_size(); ++i) { if (api_def.attr(i).name() == name) { return &api_def.attr(i); @@ -660,7 +659,7 @@ void GenPythonOp::AddDocStringInputs() { for (int i = 0; i < api_def_.arg_order_size(); ++i) { const auto& arg = *FindInputArg(api_def_.arg_order(i), op_def_); const auto& api_def_arg = *FindInputArg(api_def_.arg_order(i), api_def_); - absl::string_view description = api_def_arg.description(); + StringPiece description = api_def_arg.description(); string desc; if (ConsumeEquals(&description)) { // Skip the generated type info. desc = strings::StrCat(param_names_[i].GetRenameTo(), ": "); diff --git a/tensorflow/python/framework/python_op_gen_main.cc b/tensorflow/python/framework/python_op_gen_main.cc index 5a9b009500a..e20ad5fd339 100644 --- a/tensorflow/python/framework/python_op_gen_main.cc +++ b/tensorflow/python/framework/python_op_gen_main.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/python/framework/python_op_gen.h" #include <memory> @@ -48,8 +47,8 @@ Status ReadOpListFromFile(const string& filename, // The parser assumes that the op name is the first string on each // line with no preceding whitespace, and ignores lines that do // not start with an op name as a comment. - strings::Scanner scanner{absl::string_view(line_contents)}; - absl::string_view op_name; + strings::Scanner scanner{StringPiece(line_contents)}; + StringPiece op_name; if (scanner.One(strings::Scanner::LETTER_DIGIT_DOT) .Any(strings::Scanner::LETTER_DIGIT_DASH_DOT_SLASH_UNDERSCORE) .GetResult(nullptr, &op_name)) { @@ -90,7 +89,7 @@ Status ParseOpListCommandLine(const char* arg, std::vector<string>* op_list) { // Returns an empty string if the current executable's name does not // follow a known pattern. string InferSourceFileName(const char* argv_zero) { - absl::string_view command_str = io::Basename(argv_zero); + StringPiece command_str = io::Basename(argv_zero); // For built-in ops, the Bazel build creates a separate executable // with the name gen_<op type>_ops_py_wrappers_cc containing the diff --git a/tensorflow/python/framework/test_file_system.cc b/tensorflow/python/framework/test_file_system.cc index 13d05c6fd02..6e9915adbb6 100644 --- a/tensorflow/python/framework/test_file_system.cc +++ b/tensorflow/python/framework/test_file_system.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/null_file_system.h" @@ -21,7 +20,7 @@ namespace tensorflow { class TestRandomAccessFile : public RandomAccessFile { // The file contents is 10 bytes of all A's - Status Read(uint64 offset, size_t n, absl::string_view* result, + Status Read(uint64 offset, size_t n, StringPiece* result, char* scratch) const override { Status s; for (int i = 0; i < n; ++i) { @@ -32,7 +31,7 @@ class TestRandomAccessFile : public RandomAccessFile { } scratch[i] = 'A'; } - *result = absl::string_view(scratch, n); + *result = StringPiece(scratch, n); return s; } }; diff --git a/tensorflow/python/lib/core/py_func.cc b/tensorflow/python/lib/core/py_func.cc index 4d920750cd1..6189503d8f5 100644 --- a/tensorflow/python/lib/core/py_func.cc +++ b/tensorflow/python/lib/core/py_func.cc @@ -20,7 +20,6 @@ limitations under the License. #include <Python.h> #include "numpy/arrayobject.h" -#include "absl/strings/string_view.h" #include "tensorflow/c/eager/c_api.h" #include "tensorflow/c/eager/c_api_internal.h" #include "tensorflow/c/tf_status_helper.h" @@ -402,7 +401,7 @@ Status ConvertNdarrayToTensor(PyObject* obj, Tensor* ret) { std::max(1, EIGEN_MAX_ALIGN_BYTES) != 0) { Tensor t(dtype, shape); - absl::string_view p = t.tensor_data(); + StringPiece p = t.tensor_data(); memcpy(const_cast<char*>(p.data()), PyArray_DATA(input), p.size()); *ret = t; } else { @@ -465,7 +464,7 @@ Status ConvertTensorToNdarray(const Tensor& t, PyObject** ret) { } } else { CHECK(DataTypeCanUseMemcpy(t.dtype())); - absl::string_view p = t.tensor_data(); + StringPiece p = t.tensor_data(); memcpy(PyArray_DATA(np_array), p.data(), p.size()); } *ret = PyArray_Return(np_array); diff --git a/tensorflow/python/lib/core/strings.i b/tensorflow/python/lib/core/strings.i index 8b894ab3878..9d807e51be0 100644 --- a/tensorflow/python/lib/core/strings.i +++ b/tensorflow/python/lib/core/strings.i @@ -34,13 +34,13 @@ limitations under the License. // as it comes up. %{ -#include "absl/strings/string_view.h" +#include "tensorflow/core/lib/core/stringpiece.h" // Handles str in Python 2, bytes in Python 3. // Returns true on success, false on failure. -bool _BytesToStringPiece(PyObject* obj, absl::string_view* result) { +bool _BytesToStringPiece(PyObject* obj, tensorflow::StringPiece* result) { if (obj == Py_None) { - *result = absl::string_view(); + *result = tensorflow::StringPiece(); } else { char* ptr; Py_ssize_t len; @@ -48,30 +48,30 @@ bool _BytesToStringPiece(PyObject* obj, absl::string_view* result) { // Python has raised an error (likely TypeError or UnicodeEncodeError). return false; } - *result = absl::string_view(ptr, len); + *result = tensorflow::StringPiece(ptr, len); } return true; } %} -%typemap(typecheck) absl::string_view = char *; -%typemap(typecheck) const absl::string_view & = char *; +%typemap(typecheck) tensorflow::StringPiece = char *; +%typemap(typecheck) const tensorflow::StringPiece & = char *; -// "absl::string_view" arguments must be specified as a 'str' or 'bytes' object. -%typemap(in) absl::string_view { +// "tensorflow::StringPiece" arguments must be specified as a 'str' or 'bytes' object. +%typemap(in) tensorflow::StringPiece { if (!_BytesToStringPiece($input, &$1)) SWIG_fail; } -// "const absl::string_view&" arguments can be provided the same as -// "absl::string_view", whose typemap is defined above. -%typemap(in) const absl::string_view & (absl::string_view temp) { +// "const tensorflow::StringPiece&" arguments can be provided the same as +// "tensorflow::StringPiece", whose typemap is defined above. +%typemap(in) const tensorflow::StringPiece & (tensorflow::StringPiece temp) { if (!_BytesToStringPiece($input, &temp)) SWIG_fail; $1 = &temp; } -// C++ functions returning absl::string_view will simply return bytes in +// C++ functions returning tensorflow::StringPiece will simply return bytes in // Python, or None if the StringPiece contained a NULL pointer. -%typemap(out) absl::string_view { +%typemap(out) tensorflow::StringPiece { if ($1.data()) { $result = PyBytes_FromStringAndSize($1.data(), $1.size()); } else { diff --git a/tensorflow/python/lib/io/py_record_writer.cc b/tensorflow/python/lib/io/py_record_writer.cc index ee4eac27f1d..faf20df8683 100644 --- a/tensorflow/python/lib/io/py_record_writer.cc +++ b/tensorflow/python/lib/io/py_record_writer.cc @@ -15,8 +15,8 @@ limitations under the License. #include "tensorflow/python/lib/io/py_record_writer.h" -#include "absl/strings/string_view.h" #include "tensorflow/c/tf_status_helper.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/record_writer.h" #include "tensorflow/core/lib/io/zlib_compression_options.h" #include "tensorflow/core/platform/env.h" @@ -48,7 +48,7 @@ PyRecordWriter::~PyRecordWriter() { file_.reset(); } -void PyRecordWriter::WriteRecord(absl::string_view record, +void PyRecordWriter::WriteRecord(tensorflow::StringPiece record, TF_Status* out_status) { if (writer_ == nullptr) { TF_SetStatus(out_status, TF_FAILED_PRECONDITION, diff --git a/tensorflow/python/lib/io/py_record_writer.h b/tensorflow/python/lib/io/py_record_writer.h index 0aa7b753341..9b0792c6db8 100644 --- a/tensorflow/python/lib/io/py_record_writer.h +++ b/tensorflow/python/lib/io/py_record_writer.h @@ -18,8 +18,8 @@ limitations under the License. #include <memory> -#include "absl/strings/string_view.h" #include "tensorflow/c/c_api.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/record_writer.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/types.h" @@ -42,7 +42,7 @@ class PyRecordWriter { TF_Status* out_status); ~PyRecordWriter(); - void WriteRecord(absl::string_view record, TF_Status* out_status); + void WriteRecord(tensorflow::StringPiece record, TF_Status* out_status); void Flush(TF_Status* out_status); void Close(TF_Status* out_status); diff --git a/tensorflow/python/util/util.cc b/tensorflow/python/util/util.cc index 0889950e162..11eb9ce9476 100644 --- a/tensorflow/python/util/util.cc +++ b/tensorflow/python/util/util.cc @@ -20,7 +20,6 @@ limitations under the License. #include <vector> #include "absl/memory/memory.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" @@ -113,7 +112,7 @@ PyObject* MappingKeys(PyObject* o) { // Note that '__class__' attribute is set only in new-style classes. // A lot of tensorflow code uses __class__ without checks, so it seems like // we only support new-style classes. -absl::string_view GetClassName(PyObject* o) { +StringPiece GetClassName(PyObject* o) { // __class__ is equivalent to type() for new style classes. // type() is equivalent to PyObject_Type() // (https://docs.python.org/3.5/c-api/object.html#c.PyObject_Type) @@ -123,9 +122,9 @@ absl::string_view GetClassName(PyObject* o) { // __name__ is the value of `tp_name` after the last '.' // (https://docs.python.org/2/c-api/typeobj.html#c.PyTypeObject.tp_name) - absl::string_view name(type->tp_name); + StringPiece name(type->tp_name); size_t pos = name.rfind('.'); - if (pos != absl::string_view::npos) { + if (pos != StringPiece::npos) { name.remove_prefix(pos + 1); } return name; diff --git a/tensorflow/tools/graph_transforms/BUILD b/tensorflow/tools/graph_transforms/BUILD index 4d33cdf0cfc..1ad18952690 100644 --- a/tensorflow/tools/graph_transforms/BUILD +++ b/tensorflow/tools/graph_transforms/BUILD @@ -32,7 +32,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) @@ -121,7 +120,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":transform_utils", - "@com_google_absl//absl/strings", "//tensorflow/c:checkpoint_reader", "//tensorflow/core/util/tensor_bundle", "//tensorflow/core:core_cpu", @@ -183,7 +181,6 @@ tf_cc_test( "//tensorflow/core/kernels:quantization_utils", "//tensorflow/core/kernels:quantized_ops", "//tensorflow/core/util/tensor_bundle", - "@com_google_absl//absl/strings", ], ) @@ -201,7 +198,6 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:protos_all_cc", - "@com_google_absl//absl/strings", ], ) diff --git a/tensorflow/tools/graph_transforms/fold_constants_lib.cc b/tensorflow/tools/graph_transforms/fold_constants_lib.cc index 5bdc529a156..6df2718e610 100644 --- a/tensorflow/tools/graph_transforms/fold_constants_lib.cc +++ b/tensorflow/tools/graph_transforms/fold_constants_lib.cc @@ -24,12 +24,12 @@ limitations under the License. #include <utility> #include <vector> -#include "absl/strings/string_view.h" #include "tensorflow/core/common_runtime/constant_folding.h" #include "tensorflow/core/common_runtime/shape_refiner.h" #include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/graph/subgraph.h" +#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/platform/init_main.h" #include "tensorflow/core/public/session.h" @@ -39,10 +39,9 @@ limitations under the License. namespace tensorflow { namespace graph_transforms { namespace { -using StringPieceSet = std::unordered_set<absl::string_view, StringPieceHasher>; +using StringPieceSet = std::unordered_set<StringPiece, StringPieceHasher>; template <typename T> -using StringPieceMap = - std::unordered_map<absl::string_view, T, StringPieceHasher>; +using StringPieceMap = std::unordered_map<StringPiece, T, StringPieceHasher>; } // namespace Status ReplaceSendRecvs(const GraphDef& original_graph_def, @@ -110,7 +109,7 @@ Status ReplaceSendRecvs(const GraphDef& original_graph_def, // Some input nodes are removed in rewrite_graph_def. Add those nodes to // output_graph_def. - for (absl::string_view name : input_nodes) { + for (StringPiece name : input_nodes) { const NodeDef& removed_node = *CHECK_NOTNULL(original_map[name]); output_graph_def->add_node()->MergeFrom(removed_node); } @@ -164,7 +163,7 @@ Status RemoveUnusedNodes(const GraphDef& input_graph_def, } while (!current_nodes.empty()) { StringPieceSet next_nodes; - for (absl::string_view node_name : current_nodes) { + for (StringPiece node_name : current_nodes) { if (node_map.count(node_name) == 0) { LOG(ERROR) << "Bad graph structure, no node named '" << node_name << "' found for input lookup"; diff --git a/tensorflow/tools/graph_transforms/fold_constants_test.cc b/tensorflow/tools/graph_transforms/fold_constants_test.cc index 262314c0795..dcdc3c29069 100644 --- a/tensorflow/tools/graph_transforms/fold_constants_test.cc +++ b/tensorflow/tools/graph_transforms/fold_constants_test.cc @@ -15,7 +15,6 @@ limitations under the License. #include <utility> -#include "absl/strings/string_view.h" #include "tensorflow/cc/ops/const_op.h" #include "tensorflow/cc/ops/image_ops.h" #include "tensorflow/cc/ops/nn_ops.h" @@ -209,7 +208,7 @@ class ConstantFoldingTest : public ::testing::Test { } for (const NodeDef& node : graph_def.node()) { - const absl::string_view name(node.name()); + const StringPiece name(node.name()); const int occurrence_count = folded_node_map.count(node.name()); if (str_util::EndsWith(name, "expect_removed")) { EXPECT_EQ(0, occurrence_count) << "node.name()=" << node.name(); diff --git a/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc b/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc index 1d586e2cba7..d97496cbeb1 100644 --- a/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc +++ b/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" @@ -89,7 +88,7 @@ Status ExtractMinMaxRecords(const string& log_file_name, if (!strings::safe_strtof(max_number_string.c_str(), &max)) { continue; } - absl::string_view name_string = line_parts[min_max_index - 1]; + StringPiece name_string = line_parts[min_max_index - 1]; if (!str_util::EndsWith(name_string, print_suffix)) { continue; } diff --git a/tensorflow/tools/graph_transforms/sparsify_gather_test.cc b/tensorflow/tools/graph_transforms/sparsify_gather_test.cc index 5d3da9c59db..b8d6ba00de8 100644 --- a/tensorflow/tools/graph_transforms/sparsify_gather_test.cc +++ b/tensorflow/tools/graph_transforms/sparsify_gather_test.cc @@ -12,7 +12,6 @@ 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 "absl/strings/string_view.h" #include "tensorflow/cc/ops/const_op.h" #include "tensorflow/cc/ops/sendrecv_ops.h" #include "tensorflow/cc/ops/standard_ops.h" @@ -39,7 +38,7 @@ Status ReadTensorFromCheckpoint( class SparsifyGatherTest : public ::testing::Test { protected: - NodeDef* CreateNode(const absl::string_view name, const absl::string_view op, + NodeDef* CreateNode(const StringPiece name, const StringPiece op, const std::vector<NodeDef*>& inputs, GraphDef* graph_def, bool control_dep = false) { NodeDef* node_def = graph_def->add_node(); @@ -57,7 +56,7 @@ class SparsifyGatherTest : public ::testing::Test { return node_def; } - void MakeGather(absl::string_view name, bool gather_v2, NodeDef* params, + void MakeGather(StringPiece name, bool gather_v2, NodeDef* params, NodeDef* indices, GraphDef* graph_def) { if (gather_v2) { NodeDef* axis_node = diff --git a/tensorflow/tools/graph_transforms/transform_graph.cc b/tensorflow/tools/graph_transforms/transform_graph.cc index 9a2b3178504..7efe450710a 100644 --- a/tensorflow/tools/graph_transforms/transform_graph.cc +++ b/tensorflow/tools/graph_transforms/transform_graph.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/tools/graph_transforms/transform_graph.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/function.pb.h" #include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -42,11 +41,11 @@ Status ParseTransformParameters(const string& transforms_string, TRANSFORM_PARAM_NAME, TRANSFORM_PARAM_VALUE, } state = TRANSFORM_NAME; - absl::string_view remaining(transforms_string); - absl::string_view match; - absl::string_view transform_name; - absl::string_view parameter_name; - absl::string_view parameter_value; + StringPiece remaining(transforms_string); + StringPiece match; + StringPiece transform_name; + StringPiece parameter_name; + StringPiece parameter_value; TransformFuncParameters func_parameters; while (!remaining.empty()) { if (state == TRANSFORM_NAME) { diff --git a/tensorflow/tools/graph_transforms/transform_utils.cc b/tensorflow/tools/graph_transforms/transform_utils.cc index 3097adcb0b4..c715380aaec 100644 --- a/tensorflow/tools/graph_transforms/transform_utils.cc +++ b/tensorflow/tools/graph_transforms/transform_utils.cc @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/tools/graph_transforms/transform_utils.h" -#include "absl/strings/string_view.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/lib/hash/hash.h" @@ -88,7 +87,7 @@ void NodeNamePartsFromInput(const string& input_name, string* prefix, } else { *suffix = ":" + input_parts[1]; } - absl::string_view node_name_piece(input_parts[0]); + StringPiece node_name_piece(input_parts[0]); if (str_util::ConsumePrefix(&node_name_piece, "^")) { *prefix = "^"; } else { @@ -641,7 +640,7 @@ Status TransformFuncContext::GetOneInt32Parameter(const string& name, } string string_value; TF_RETURN_IF_ERROR(GetOneStringParameter(name, "", &string_value)); - if (!strings::safe_strto32(absl::string_view(string_value), result)) { + if (!strings::safe_strto32(StringPiece(string_value), result)) { return errors::InvalidArgument("Couldn't interpret the ", name, " argument as a number:", string_value); } @@ -658,7 +657,7 @@ Status TransformFuncContext::GetOneInt64Parameter(const string& name, } string string_value; TF_RETURN_IF_ERROR(GetOneStringParameter(name, "", &string_value)); - if (!strings::safe_strto64(absl::string_view(string_value), result)) { + if (!strings::safe_strto64(StringPiece(string_value), result)) { return errors::InvalidArgument("Couldn't interpret the ", name, " argument as a number:", string_value); } diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc index da50cae4840..15d7c702819 100644 --- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc +++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc @@ -447,7 +447,7 @@ void Generator::AppendParseMessageFunction(const Descriptor& md) { Print("scanner->RestartCapture()"); Print(" .Many(Scanner::LETTER_DIGIT_UNDERSCORE)"); Print(" .StopCapture();"); - Print("absl::string_view identifier;"); + Print("StringPiece identifier;"); Print("if (!scanner->GetResult(nullptr, &identifier)) return false;"); Print("bool parsed_colon = false;"); Print("(void)parsed_colon;"); // Avoid "set but not used" compiler warning @@ -528,7 +528,7 @@ void Generator::AppendParseMessageFunction(const Descriptor& md) { Print("SetProtobufStringSwapAllowed(&str_value, ", mutable_value_expr, ");"); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { - Print("absl::string_view value;"); + Print("StringPiece value;"); Print( "if (!parsed_colon || " "!scanner->RestartCapture().Many("