Merge pull request #46446 from zhuzilin:optimize-readline
PiperOrigin-RevId: 360960162 Change-Id: I7d9aff7d7ce0e3b033032819f5ed7b74befc86a1
This commit is contained in:
commit
33b48dbbea
@ -60,25 +60,32 @@ Status BufferedInputStream::ReadLineHelper(StringType* result,
|
||||
bool include_eol) {
|
||||
result->clear();
|
||||
Status s;
|
||||
size_t start_pos = pos_;
|
||||
while (true) {
|
||||
if (pos_ == limit_) {
|
||||
result->append(buf_.data() + start_pos, pos_ - start_pos);
|
||||
// Get more data into buffer
|
||||
s = FillBuffer();
|
||||
if (limit_ == 0) {
|
||||
break;
|
||||
}
|
||||
start_pos = pos_;
|
||||
}
|
||||
char c = buf_[pos_++];
|
||||
char c = buf_[pos_];
|
||||
if (c == '\n') {
|
||||
result->append(buf_.data() + start_pos, pos_ - start_pos);
|
||||
if (include_eol) {
|
||||
result->append(1, c);
|
||||
}
|
||||
pos_++;
|
||||
return Status::OK();
|
||||
}
|
||||
// We don't append '\r' to *result
|
||||
if (c != '\r') {
|
||||
result->append(1, c);
|
||||
if (c == '\r') {
|
||||
result->append(buf_.data() + start_pos, pos_ - start_pos);
|
||||
start_pos = pos_ + 1;
|
||||
}
|
||||
pos_++;
|
||||
}
|
||||
if (errors::IsOutOfRange(s) && !result->empty()) {
|
||||
return Status::OK();
|
||||
|
Loading…
Reference in New Issue
Block a user