Skip to content

Commit

Permalink
Automated Code Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 674596857
  • Loading branch information
Google-ML-Automation committed Sep 14, 2024
1 parent 4990bb3 commit 5f20098
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 128 deletions.
19 changes: 10 additions & 9 deletions third_party/tsl/tsl/lib/io/block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ class Block::Iter : public Iterator {
uint32 current_;
uint32 restart_index_; // Index of restart block in which current_ falls
string key_;
StringPiece value_;
absl::string_view value_;
absl::Status status_;

inline int Compare(const StringPiece& a, const StringPiece& b) const {
inline int Compare(const absl::string_view& a,
const absl::string_view& b) const {
return a.compare(b);
}

Expand All @@ -121,7 +122,7 @@ class Block::Iter : public Iterator {

// ParseNextKey() starts at the end of value_, so set value_ accordingly
uint32 offset = GetRestartPoint(index);
value_ = StringPiece(data_ + offset, 0);
value_ = absl::string_view(data_ + offset, 0);
}

public:
Expand All @@ -136,11 +137,11 @@ class Block::Iter : public Iterator {

bool Valid() const override { return current_ < restarts_; }
absl::Status status() const override { return status_; }
StringPiece key() const override {
absl::string_view key() const override {
assert(Valid());
return key_;
}
StringPiece value() const override {
absl::string_view value() const override {
assert(Valid());
return value_;
}
Expand All @@ -150,7 +151,7 @@ class Block::Iter : public Iterator {
ParseNextKey();
}

void Seek(const StringPiece& target) override {
void Seek(const absl::string_view& target) override {
// Binary search in restart array to find the last restart point
// with a key < target
uint32 left = 0;
Expand All @@ -166,7 +167,7 @@ class Block::Iter : public Iterator {
CorruptionError();
return;
}
StringPiece mid_key(key_ptr, non_shared);
absl::string_view 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.
Expand Down Expand Up @@ -201,7 +202,7 @@ class Block::Iter : public Iterator {
restart_index_ = num_restarts_;
status_ = errors::DataLoss("bad entry in block");
key_.clear();
value_ = StringPiece();
value_ = absl::string_view();
}

bool ParseNextKey() {
Expand All @@ -224,7 +225,7 @@ class Block::Iter : public Iterator {
} else {
key_.resize(shared);
key_.append(p, non_shared);
value_ = StringPiece(p + non_shared, value_length);
value_ = absl::string_view(p + non_shared, value_length);
while (restart_index_ + 1 < num_restarts_ &&
GetRestartPoint(restart_index_ + 1) < current_) {
++restart_index_;
Expand Down
11 changes: 6 additions & 5 deletions third_party/tsl/tsl/lib/io/block_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ size_t BlockBuilder::CurrentSizeEstimate() const {
sizeof(uint32)); // Restart array length
}

StringPiece BlockBuilder::Finish() {
absl::string_view BlockBuilder::Finish() {
// Append restart array
CHECK_LE(restarts_.size(), std::numeric_limits<uint32_t>::max());
for (const auto r : restarts_) {
Expand All @@ -79,11 +79,12 @@ StringPiece BlockBuilder::Finish() {
// Downcast safe because of the CHECK.
core::PutFixed32(&buffer_, static_cast<uint32_t>(restarts_.size()));
finished_ = true;
return StringPiece(buffer_);
return absl::string_view(buffer_);
}

void BlockBuilder::Add(const StringPiece& key, const StringPiece& value) {
StringPiece last_key_piece(last_key_);
void BlockBuilder::Add(const absl::string_view& key,
const absl::string_view& value) {
absl::string_view last_key_piece(last_key_);
assert(!finished_);
assert(counter_ <= options_->block_restart_interval);
assert(buffer_.empty() // No values yet?
Expand Down Expand Up @@ -119,7 +120,7 @@ void BlockBuilder::Add(const StringPiece& key, const StringPiece& value) {
// Update state
last_key_.resize(shared);
last_key_.append(key.data() + shared, non_shared);
assert(StringPiece(last_key_) == key);
assert(absl::string_view(last_key_) == key);
counter_++;
}

Expand Down
4 changes: 2 additions & 2 deletions third_party/tsl/tsl/lib/io/block_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,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 StringPiece& key, const StringPiece& value);
void Add(const absl::string_view& key, const absl::string_view& 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.
StringPiece Finish();
absl::string_view Finish();

// Returns an estimate of the current (uncompressed) size of the block
// we are building.
Expand Down
5 changes: 3 additions & 2 deletions third_party/tsl/tsl/lib/io/buffered_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BufferedWritableFile : public WritableFile {
}
~BufferedWritableFile() override { Close().IgnoreError(); }

absl::Status Append(StringPiece str_data) override {
absl::Status Append(absl::string_view str_data) override {
int64_t bytes_left = str_data.size();
const char* data = str_data.data();

Expand Down Expand Up @@ -75,7 +75,8 @@ class BufferedWritableFile : public WritableFile {

absl::Status Flush() override {
if (buffer_pos_ > 0) {
TF_RETURN_IF_ERROR(file_->Append(StringPiece(&buffer_[0], buffer_pos_)));
TF_RETURN_IF_ERROR(
file_->Append(absl::string_view(&buffer_[0], buffer_pos_)));
buffer_pos_ = 0;
}
return file_->Flush();
Expand Down
2 changes: 1 addition & 1 deletion third_party/tsl/tsl/lib/io/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ limitations under the License.

namespace tsl {

using Slice = StringPiece;
using Slice = absl::string_view;

namespace table {

Expand Down
16 changes: 8 additions & 8 deletions third_party/tsl/tsl/lib/io/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BlockHandle::EncodeTo(string* dst) const {
core::PutVarint64(dst, size_);
}

absl::Status BlockHandle::DecodeFrom(StringPiece* input) {
absl::Status BlockHandle::DecodeFrom(absl::string_view* input) {
if (core::GetVarint64(input, &offset_) && core::GetVarint64(input, &size_)) {
return absl::OkStatus();
} else {
Expand All @@ -56,7 +56,7 @@ void Footer::EncodeTo(string* dst) const {
assert(dst->size() == original_size + kEncodedLength);
}

absl::Status Footer::DecodeFrom(StringPiece* input) {
absl::Status Footer::DecodeFrom(absl::string_view* 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);
Expand All @@ -73,14 +73,14 @@ absl::Status Footer::DecodeFrom(StringPiece* input) {
if (result.ok()) {
// We skip over any leftover data (just padding for now) in "input"
const char* end = magic_ptr + 8;
*input = StringPiece(end, input->data() + input->size() - end);
*input = absl::string_view(end, input->data() + input->size() - end);
}
return result;
}

absl::Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle,
BlockContents* result) {
result->data = StringPiece();
result->data = absl::string_view();
result->cacheable = false;
result->heap_allocated = false;

Expand All @@ -93,7 +93,7 @@ absl::Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle,
}

char* buf = new char[n + kBlockTrailerSize];
StringPiece contents;
absl::string_view contents;
absl::Status s =
file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf);
if (!s.ok()) {
Expand Down Expand Up @@ -126,11 +126,11 @@ absl::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 = StringPiece(data, n);
result->data = absl::string_view(data, n);
result->heap_allocated = false;
result->cacheable = false; // Do not double-cache
} else {
result->data = StringPiece(buf, n);
result->data = absl::string_view(buf, n);
result->heap_allocated = true;
result->cacheable = true;
}
Expand All @@ -150,7 +150,7 @@ absl::Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle,
return errors::DataLoss("corrupted compressed block contents");
}
delete[] buf;
result->data = StringPiece(ubuf, ulength);
result->data = absl::string_view(ubuf, ulength);
result->heap_allocated = true;
result->cacheable = true;
break;
Expand Down
6 changes: 3 additions & 3 deletions third_party/tsl/tsl/lib/io/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BlockHandle {
void set_size(uint64 size) { size_ = size; }

void EncodeTo(string* dst) const;
absl::Status DecodeFrom(StringPiece* input);
absl::Status DecodeFrom(absl::string_view* input);

// Maximum encoding length of a BlockHandle
enum { kMaxEncodedLength = 10 + 10 };
Expand All @@ -71,7 +71,7 @@ class Footer {
void set_index_handle(const BlockHandle& h) { index_handle_ = h; }

void EncodeTo(string* dst) const;
absl::Status DecodeFrom(StringPiece* input);
absl::Status DecodeFrom(absl::string_view* input);

// Encoded length of a Footer. Note that the serialization of a
// Footer will always occupy exactly this many bytes. It consists
Expand All @@ -92,7 +92,7 @@ static const uint64 kTableMagicNumber = 0xdb4775248b80fb57ull;
static const size_t kBlockTrailerSize = 5;

struct BlockContents {
StringPiece data; // Actual contents of data
absl::string_view data; // Actual contents of data
bool cacheable; // True iff data can be cached
bool heap_allocated; // True iff caller should delete[] data.data()
};
Expand Down
4 changes: 2 additions & 2 deletions third_party/tsl/tsl/lib/io/inputbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ InputBuffer::InputBuffer(RandomAccessFile* file, size_t buffer_bytes)
InputBuffer::~InputBuffer() { delete[] buf_; }

absl::Status InputBuffer::FillBuffer() {
StringPiece data;
absl::string_view data;
absl::Status s = file_->Read(file_pos_, size_, &data, buf_);
if (data.data() != buf_) {
memmove(buf_, data.data(), data.size());
Expand Down Expand Up @@ -225,7 +225,7 @@ absl::Status InputBuffer::Hint(int64_t bytes_to_read) {
bytes_to_read -= bytes_remain_in_buf;

// Read the remaining bytes from file.
StringPiece data;
absl::string_view data;
absl::Status s = file_->Read(file_pos_, bytes_to_read, &data, limit_);
if (data.data() != limit_) {
memmove(limit_, data.data(), data.size());
Expand Down
18 changes: 9 additions & 9 deletions third_party/tsl/tsl/lib/io/inputbuffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,31 @@ TEST(InputBuffer, ReadNBytes) {

EXPECT_EQ(0, in.Tell());
TF_ASSERT_OK(in.ReadNBytes(3, read, &bytes_read));
EXPECT_EQ(StringPiece(read, 3), "012");
EXPECT_EQ(absl::string_view(read, 3), "012");

EXPECT_EQ(3, in.Tell());
TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read));
EXPECT_EQ(StringPiece(read, 3), "012");
EXPECT_EQ(absl::string_view(read, 3), "012");

EXPECT_EQ(3, in.Tell());
TF_ASSERT_OK(in.ReadNBytes(4, read, &bytes_read));
EXPECT_EQ(StringPiece(read, 4), "3456");
EXPECT_EQ(absl::string_view(read, 4), "3456");

EXPECT_EQ(7, in.Tell());
TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read));
EXPECT_EQ(StringPiece(read, 4), "3456");
EXPECT_EQ(absl::string_view(read, 4), "3456");

EXPECT_EQ(7, in.Tell());
EXPECT_TRUE(errors::IsOutOfRange(in.ReadNBytes(5, read, &bytes_read)));
EXPECT_EQ(StringPiece(read, 3), "789");
EXPECT_EQ(absl::string_view(read, 3), "789");

EXPECT_EQ(10, in.Tell());
EXPECT_TRUE(errors::IsOutOfRange(in.ReadNBytes(5, read, &bytes_read)));
EXPECT_EQ(StringPiece(read, 3), "789");
EXPECT_EQ(absl::string_view(read, 3), "789");

EXPECT_EQ(10, in.Tell());
TF_ASSERT_OK(in.ReadNBytes(0, read, &bytes_read));
EXPECT_EQ(StringPiece(read, 3), "789");
EXPECT_EQ(absl::string_view(read, 3), "789");
EXPECT_EQ(10, in.Tell());
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ TEST(InputBuffer, ReadVarint32) {
for (uint32 number : data) {
varint.clear();
core::PutVarint32(&varint, number);
TF_CHECK_OK(file->Append(StringPiece(varint)));
TF_CHECK_OK(file->Append(absl::string_view(varint)));
}
}

Expand Down Expand Up @@ -360,7 +360,7 @@ TEST(InputBuffer, ReadVarint64) {
for (uint64 number : data) {
varint.clear();
core::PutVarint64(&varint, number);
TF_CHECK_OK(file->Append(StringPiece(varint)));
TF_CHECK_OK(file->Append(absl::string_view(varint)));
}
}

Expand Down
10 changes: 5 additions & 5 deletions third_party/tsl/tsl/lib/io/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class EmptyIterator : public Iterator {
public:
explicit EmptyIterator(const absl::Status& s) : status_(s) {}
bool Valid() const override { return false; }
void Seek(const StringPiece& target) override {}
void Seek(const absl::string_view& target) override {}
void SeekToFirst() override {}
void Next() override { assert(false); }
StringPiece key() const override {
absl::string_view key() const override {
assert(false);
return StringPiece();
return absl::string_view();
}
StringPiece value() const override {
absl::string_view value() const override {
assert(false);
return StringPiece();
return absl::string_view();
}
absl::Status status() const override { return status_; }

Expand Down
6 changes: 3 additions & 3 deletions third_party/tsl/tsl/lib/io/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 StringPiece& target) = 0;
virtual void Seek(const absl::string_view& 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.
Expand All @@ -59,13 +59,13 @@ class Iterator {
// the returned slice is valid only until the next modification of
// the iterator.
// REQUIRES: Valid()
virtual StringPiece key() const = 0;
virtual absl::string_view 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 StringPiece value() const = 0;
virtual absl::string_view value() const = 0;

// If an error has occurred, return it. Else return an ok status.
virtual absl::Status status() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions third_party/tsl/tsl/lib/io/proto_encode_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ProtoEncodeHelper {
Encode32(combine(tag, WIRETYPE_VARINT));
EncodeBool(v);
}
void WriteString(int tag, StringPiece v) {
void WriteString(int tag, absl::string_view v) {
Encode32(combine(tag, WIRETYPE_LENGTH_DELIMITED));
Encode32(v.size());
EncodeBytes(v.data(), v.size());
Expand All @@ -58,7 +58,7 @@ class ProtoEncodeHelper {
Encode32(combine(tag, WIRETYPE_LENGTH_DELIMITED));
Encode32(len);
}
void WriteRawBytes(StringPiece v) { EncodeBytes(v.data(), v.size()); }
void WriteRawBytes(absl::string_view v) { EncodeBytes(v.data(), v.size()); }

private:
// Note: this module's behavior must match the protocol buffer wire encoding
Expand Down
Loading

0 comments on commit 5f20098

Please sign in to comment.