Code cleanup in QuicStreamSequencer.

One change is to clean up nested loop. Another is to change int return type to QuicByteCount to avoid casting.

gfe-relnote: no behavior change.
PiperOrigin-RevId: 289708679
Change-Id: I7faa53c54d429825bf83fe564ad6b5d9a9babe9b
diff --git a/quic/core/quic_stream_sequencer.cc b/quic/core/quic_stream_sequencer.cc
index f5849f6..49f0917 100644
--- a/quic/core/quic_stream_sequencer.cc
+++ b/quic/core/quic_stream_sequencer.cc
@@ -5,6 +5,7 @@
 #include "net/third_party/quiche/src/quic/core/quic_stream_sequencer.h"
 
 #include <algorithm>
+#include <cstddef>
 #include <limits>
 #include <string>
 #include <utility>
@@ -13,6 +14,7 @@
 #include "net/third_party/quiche/src/quic/core/quic_packets.h"
 #include "net/third_party/quiche/src/quic/core/quic_stream.h"
 #include "net/third_party/quiche/src/quic/core/quic_stream_sequencer_buffer.h"
+#include "net/third_party/quiche/src/quic/core/quic_types.h"
 #include "net/third_party/quiche/src/quic/core/quic_utils.h"
 #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h"
 #include "net/third_party/quiche/src/quic/platform/api/quic_clock.h"
@@ -43,14 +45,9 @@
   const QuicStreamOffset byte_offset = frame.offset;
   const size_t data_len = frame.data_length;
 
-  if (frame.fin) {
-    bool should_process_data = CloseStreamAtOffset(frame.offset + data_len);
-    if (data_len == 0) {
-      return;
-    }
-    if (!should_process_data) {
-      return;
-    }
+  if (frame.fin &&
+      (!CloseStreamAtOffset(frame.offset + data_len) || data_len == 0)) {
+    return;
   }
   OnFrameData(byte_offset, data_len, frame.data_buffer);
 }
@@ -191,7 +188,7 @@
   Readv(&iov, 1);
 }
 
-int QuicStreamSequencer::Readv(const struct iovec* iov, size_t iov_len) {
+size_t QuicStreamSequencer::Readv(const struct iovec* iov, size_t iov_len) {
   DCHECK(!blocked_);
   std::string error_details;
   size_t bytes_read;
@@ -201,11 +198,11 @@
     std::string details =
         quiche::QuicheStrCat("Stream ", stream_->id(), ": ", error_details);
     stream_->CloseConnectionWithDetails(read_error, details);
-    return static_cast<int>(bytes_read);
+    return bytes_read;
   }
 
   stream_->AddBytesConsumed(bytes_read);
-  return static_cast<int>(bytes_read);
+  return bytes_read;
 }
 
 bool QuicStreamSequencer::HasBytesToRead() const {
diff --git a/quic/core/quic_stream_sequencer.h b/quic/core/quic_stream_sequencer.h
index c3d34c0..68845b8 100644
--- a/quic/core/quic_stream_sequencer.h
+++ b/quic/core/quic_stream_sequencer.h
@@ -91,7 +91,7 @@
   // bytes read.  Any buffered data no longer in use will be released.
   // TODO(rch): remove this method and instead implement it as a helper method
   // based on GetReadableRegions and MarkConsumed.
-  int Readv(const struct iovec* iov, size_t iov_len);
+  size_t Readv(const struct iovec* iov, size_t iov_len);
 
   // Consumes |num_bytes| data.  Used in conjunction with |GetReadableRegions|
   // to do zero-copy reads.
diff --git a/quic/core/quic_stream_sequencer_test.cc b/quic/core/quic_stream_sequencer_test.cc
index 67051c2..7cd498e 100644
--- a/quic/core/quic_stream_sequencer_test.cc
+++ b/quic/core/quic_stream_sequencer_test.cc
@@ -63,7 +63,7 @@
     struct iovec iov;
     iov.iov_base = buffer;
     iov.iov_len = num_bytes;
-    ASSERT_EQ(static_cast<int>(num_bytes), sequencer_->Readv(&iov, 1));
+    ASSERT_EQ(num_bytes, sequencer_->Readv(&iov, 1));
   }
 
  protected: