pitrou commented on code in PR #37460:
URL: https://github.com/apache/arrow/pull/37460#discussion_r1310200589


##########
cpp/src/arrow/io/buffered.cc:
##########
@@ -373,33 +378,35 @@ class BufferedInputStream::Impl : public BufferedBase {
       return Status::Invalid("Bytes to read must be positive. Received:", 
nbytes);
     }
 
-    if (nbytes < buffer_size_) {
-      // Pre-buffer for small reads
-      RETURN_NOT_OK(BufferIfNeeded());
+    // 1. First consume pre-buffered data.
+    int64_t pre_buffer_copy_bytes = std::min(nbytes, bytes_buffered_);
+    if (pre_buffer_copy_bytes > 0) {
+      memcpy(out, buffer_data_ + buffer_pos_, pre_buffer_copy_bytes);
+      ConsumeBuffer(pre_buffer_copy_bytes);
+    }
+    int64_t remain_bytes = nbytes - pre_buffer_copy_bytes;

Review Comment:
   Nit: call this `remaining_bytes`



##########
cpp/src/arrow/io/buffered.cc:
##########
@@ -373,33 +378,35 @@ class BufferedInputStream::Impl : public BufferedBase {
       return Status::Invalid("Bytes to read must be positive. Received:", 
nbytes);
     }
 
-    if (nbytes < buffer_size_) {
-      // Pre-buffer for small reads
-      RETURN_NOT_OK(BufferIfNeeded());
+    // 1. First consume pre-buffered data.

Review Comment:
   Should you first ensure that `nbytes` does not go past `raw_read_bound_`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to