Removed StringPiece::set and StringPiece::clear, as they have no absl::string_view equivalents.

This will allow for a more convenient transition to absl::string_view.

Calls to set StringPiece::set and StringPiece::clear were replaced with the StringPiece constructor as follows:

string_piece_foo.set(data, size) => string_piece_foo = StringPiece(data, size)
string_piece_foo.clear() => string_piece_foo = StringPiece()

PiperOrigin-RevId: 175326576
This commit is contained in:
A. Unique TensorFlower
2017-11-10 13:12:49 -08:00
committed by TensorFlower Gardener
parent f157cc92a8
commit 83c2da808e
13 changed files with 27 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
Please go to Stack Overflow for help and support:
https://stackoverflow.com/questions/tagged/tensorflow
If you open a GitHub issue, here is our policy:

View File

@@ -97,7 +97,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->set(scratch, 0);
*result = StringPiece(scratch, 0);
return errors::OutOfRange("Read after file end.");
}
const off64_t region_left =
@@ -106,7 +106,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile {
if (read < 0) {
return errors::Internal("Error reading from asset.");
}
result->set(scratch, region_left);
*result = StringPiece(scratch, region_left);
return (region_left == to_read)
? Status::OK()
: errors::OutOfRange("Read less bytes than requested.");

View File

@@ -84,7 +84,7 @@ static bool SplitAt(char split_ch, StringPiece* orig,
auto pos = orig->find(split_ch);
if (pos == StringPiece::npos) {
*before_split = *orig;
orig->clear();
*orig = StringPiece();
return false;
} else {
*before_split = orig->substr(0, pos);
@@ -236,7 +236,7 @@ string PBTxtFromMultiline(StringPiece multiline_pbtxt) {
unescaped.push_back('\n');
}
strings::StrAppend(&unescaped, line);
line.clear();
line = StringPiece();
}
// Escape what we extracted and then output it in quotes.

View File

@@ -36,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.set(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.set(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.set(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;
}
@@ -104,9 +104,9 @@ Status Rendezvous::ParseKey(StringPiece key, ParsedKey* out) {
strings::HexStringToUint64(parts[1], &out->src_incarnation) &&
DeviceNameUtils::ParseFullName(parts[2], &out->dst) &&
!parts[3].empty()) {
out->src_device.set(parts[0].data(), parts[0].size());
out->dst_device.set(parts[2].data(), parts[2].size());
out->edge_name.set(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);

View File

@@ -147,8 +147,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) {
StringPiece sp;
sp.set(&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());

View File

@@ -51,11 +51,6 @@ class StringPiece {
// Create a slice that refers to s[0,strlen(s)-1]
StringPiece(const char* s) : data_(s), size_(strlen(s)) {}
void set(const void* data, size_t len) {
data_ = reinterpret_cast<const char*>(data);
size_ = len;
}
// Return a pointer to the beginning of the referenced data
const char* data() const { return data_; }
@@ -79,12 +74,6 @@ class StringPiece {
return data_[n];
}
// Change this slice to refer to an empty array
void clear() {
data_ = "";
size_ = 0;
}
// Drop the first "n" bytes from this slice.
void remove_prefix(size_t n) {
assert(n <= size());

View File

@@ -199,7 +199,7 @@ class Block::Iter : public Iterator {
restart_index_ = num_restarts_;
status_ = errors::DataLoss("bad entry in block");
key_.clear();
value_.clear();
value_ = StringPiece();
}
bool ParseNextKey() {

View File

@@ -407,11 +407,11 @@ bool ConsumeNonWhitespace(StringPiece* s, StringPiece* val) {
}
const size_t n = p - s->data();
if (n > 0) {
val->set(s->data(), n);
*val = StringPiece(s->data(), n);
s->remove_prefix(n);
return true;
} else {
val->clear();
*val = StringPiece();
return false;
}
}

View File

@@ -45,7 +45,7 @@ AlphaNum::AlphaNum(Hex hex) {
value >>= 4;
mask >>= 4;
} while (mask != 0);
piece_.set(writer, end - writer);
piece_ = StringPiece(writer, end - writer);
}
// ----------------------------------------------------------------------

View File

@@ -247,7 +247,7 @@ class GcsRandomAccessFile : public RandomAccessFile {
/// The implementation of reads with an LRU block cache. Thread safe.
Status Read(uint64 offset, size_t n, StringPiece* result,
char* scratch) const override {
result->clear();
*result = StringPiece();
std::vector<char> out;
TF_RETURN_IF_ERROR(file_block_cache_->Read(filename_, offset, n, &out));
std::memcpy(scratch, out.data(), std::min(out.size(), n));

View File

@@ -58,12 +58,13 @@ class RandomAccessFileFromMemmapped : public RandomAccessFile {
Status Read(uint64 offset, size_t to_read, StringPiece* result,
char* scratch) const override {
if (offset >= length_) {
result->set(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->set(reinterpret_cast<const uint8*>(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");

View File

@@ -39,7 +39,7 @@ bool ConsumeDotSeparatedIdentifiers(StringPiece* s, const string& prefix,
for (i = 0; i < s->size() && IsDotOrIdentifierChar((*s)[i]); ++i) {
// Intentionally empty
}
val->set(s->data(), i);
*val = StringPiece(s->data(), i);
s->remove_prefix(i);
return i > 0;
}

View File

@@ -40,7 +40,7 @@ limitations under the License.
// Returns true on success, false on failure.
bool _BytesToStringPiece(PyObject* obj, tensorflow::StringPiece* result) {
if (obj == Py_None) {
result->clear();
*result = tensorflow::StringPiece();
} else {
char* ptr;
Py_ssize_t len;
@@ -48,7 +48,7 @@ bool _BytesToStringPiece(PyObject* obj, tensorflow::StringPiece* result) {
// Python has raised an error (likely TypeError or UnicodeEncodeError).
return false;
}
result->set(ptr, len);
*result = tensorflow::StringPiece(ptr, len);
}
return true;
}