Skip to content

Commit

Permalink
refactor: check reader finished state at the end of read
Browse files Browse the repository at this point in the history
* One function call less
  • Loading branch information
ttytm committed Jun 20, 2023
1 parent c4e4b7e commit 4b8ba41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/smooth_reader.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ mut:
}

fn (mut r MyCustomReader) read(mut buf []u8) !int {
if r.pos >= r.size {
return io.Eof{}
}
n := copy(mut buf, r.data[r.pos..r.pos + buf.cap])
time.sleep(1 * time.millisecond)
r.pos += n
if r.pos >= r.size {
return io.Eof{}
}
return n
}

Expand Down
6 changes: 3 additions & 3 deletions src/_instructions_reader.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ fn bar_reader(b BarType, reader io.Reader, size u64) &io.BufferedReader {
}

fn (mut br BarReader) read(mut buf []u8) !int {
if br.pos >= br.size {
return io.Eof{}
}
n := br.reader.read(mut buf)!
br.pos += n
match mut br.bar {
Expand All @@ -32,5 +29,8 @@ fn (mut br BarReader) read(mut buf []u8) !int {
}
}
}
if br.pos >= br.size {
return io.Eof{}
}
return n
}

0 comments on commit 4b8ba41

Please sign in to comment.