Skip to content

Commit

Permalink
Rewrite read_element like read_pi
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun authored and dralley committed Jun 9, 2024
1 parent 0a6ecd6 commit 6f1a644
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,33 @@ macro_rules! impl_buffered_source {

let start = buf.len();
loop {
match self $(.$reader)? .fill_buf() $(.$await)? {
let available = match self $(.$reader)? .fill_buf() $(.$await)? {
Ok(n) if n.is_empty() => break,
Ok(available) => {
if let Some(used) = parser.feed(available) {
Ok(n) => n,
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => {
*position += read;
return Err(Error::Io(e.into()));
}
};

if let Some(used) = parser.feed(available) {
buf.extend_from_slice(&available[..used]);

// +1 for `>` which we do not include
self $(.$reader)? .consume(used + 1);
read += used + 1;

// Position now just after the `>` symbol
*position += read;
return Ok(&buf[start..]);
} else {
// The `>` symbol not yet found, continue reading
buf.extend_from_slice(available);
// Position now just after the `>` symbol
*position += read;
return Ok(&buf[start..]);
}

let used = available.len();
self $(.$reader)? .consume(used);
read += used;
}
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => {
*position += read;
return Err(Error::Io(e.into()));
}
};
// The `>` symbol not yet found, continue reading
buf.extend_from_slice(available);
let used = available.len();
self $(.$reader)? .consume(used);
read += used;
}

*position += read;
Expand Down

0 comments on commit 6f1a644

Please sign in to comment.