Skip to content

Commit cba6e10

Browse files
committed
io::Chain: specialize some BufRead methods
1 parent cada71e commit cba6e10

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Diff for: library/std/src/io/mod.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -2429,9 +2429,7 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
24292429
fn fill_buf(&mut self) -> Result<&[u8]> {
24302430
if !self.done_first {
24312431
match self.first.fill_buf()? {
2432-
buf if buf.is_empty() => {
2433-
self.done_first = true;
2434-
}
2432+
buf if buf.is_empty() => self.done_first = true,
24352433
buf => return Ok(buf),
24362434
}
24372435
}
@@ -2441,6 +2439,21 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
24412439
fn consume(&mut self, amt: usize) {
24422440
if !self.done_first { self.first.consume(amt) } else { self.second.consume(amt) }
24432441
}
2442+
2443+
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
2444+
let mut read = 0;
2445+
if !self.done_first {
2446+
let n = self.first.read_until(byte, buf)?;
2447+
read += n;
2448+
2449+
match buf.last() {
2450+
Some(b) if *b == byte && n != 0 => return Ok(read),
2451+
_ => self.done_first = true,
2452+
}
2453+
}
2454+
read += self.second.read_until(byte, buf)?;
2455+
Ok(read)
2456+
}
24442457
}
24452458

24462459
impl<T, U> SizeHint for Chain<T, U> {

0 commit comments

Comments
 (0)