Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
  • Loading branch information
mapleFU and pitrou authored Oct 24, 2024
1 parent e3c7eea commit 9f39c99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cpp/src/arrow/io/buffered.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ class BufferedInputStream::Impl : public BufferedBase {
}
if ((buffer_pos_ + bytes_buffered_) >= new_buffer_size) {
return Status::Invalid(
"Cannot shrink read buffer if buffered data remains, new_buffer_size:",
new_buffer_size, ", buffer_pos:", buffer_pos_,
", bytes_buffered:", bytes_buffered_, ", buffer_size:", buffer_size_);
"Cannot shrink read buffer if buffered data remains, new_buffer_size: ",
new_buffer_size, ", buffer_pos: ", buffer_pos_,
", bytes_buffered: ", bytes_buffered_, ", buffer_size: ", buffer_size_);
}
if (raw_read_bound_ >= 0) {
// No need to reserve space for more than the total remaining number of bytes.
Expand Down
7 changes: 3 additions & 4 deletions cpp/src/arrow/io/buffered_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,22 +496,21 @@ TEST_F(TestBufferedInputStream, PeekPastBufferedBytes) {
// buffered bytes.
MakeExample1(/*buffer_size=*/10, default_memory_pool(), /*raw_read_bound=*/15);
ASSERT_OK_AND_ASSIGN(auto bytes, buffered_->Read(9));
EXPECT_EQ(std::string_view(bytes->data_as<char>(), bytes->size()),
kExample1.substr(0, 9));
EXPECT_EQ(std::string_view(*bytes), kExample1.substr(0, 9));
ASSERT_EQ(1, buffered_->bytes_buffered());
ASSERT_EQ(10, buffered_->buffer_size());
ASSERT_OK_AND_ASSIGN(auto view, buffered_->Peek(3));
EXPECT_EQ(view, kExample1.substr(9, 3));
ASSERT_EQ(3, buffered_->bytes_buffered());
ASSERT_EQ(12, buffered_->buffer_size());
ASSERT_OK_AND_ASSIGN(view, buffered_->Peek(10));
// Peek() cannot go past the `raw_read_bound`
EXPECT_EQ(view, kExample1.substr(9, 6));
ASSERT_EQ(6, buffered_->bytes_buffered());
ASSERT_EQ(15, buffered_->buffer_size());
// Do read
ASSERT_OK_AND_ASSIGN(bytes, buffered_->Read(6));
EXPECT_EQ(std::string_view(bytes->data_as<char>(), bytes->size()),
kExample1.substr(9, 6));
EXPECT_EQ(std::string_view(*bytes), kExample1.substr(9, 6));
ASSERT_EQ(0, buffered_->bytes_buffered());
}

Expand Down

0 comments on commit 9f39c99

Please sign in to comment.