Copilot commented on code in PR #6987:
URL: https://github.com/apache/opendal/pull/6987#discussion_r2613589633
##########
core/benches/types/buffer.rs:
##########
@@ -100,19 +100,17 @@ mod iterator {
fn contiguous(b: Bencher) {
b.with_inputs(|| Buffer::from(vec![1; 1_000_000]))
.bench_refs(|buffer| {
- loop {
- let Some(_) = buffer.next() else { break };
- }
+ // Fully consume the iterator, ignoring each item.
+ for _ in buffer.by_ref() {}
Review Comment:
The `by_ref()` call is redundant here. Since `buffer` is `&mut Buffer` (from
`bench_refs`) and `Buffer` implements `Iterator`, you can iterate directly with
`for _ in buffer {}`. The `&mut T where T: Iterator` automatically implements
`Iterator`, so `by_ref()` is unnecessary.
##########
core/benches/types/buffer.rs:
##########
@@ -100,19 +100,17 @@ mod iterator {
fn contiguous(b: Bencher) {
b.with_inputs(|| Buffer::from(vec![1; 1_000_000]))
.bench_refs(|buffer| {
- loop {
- let Some(_) = buffer.next() else { break };
- }
+ // Fully consume the iterator, ignoring each item.
+ for _ in buffer.by_ref() {}
});
}
#[divan::bench(args = [10, 1_000, 1_000_000])]
fn non_contiguous(b: Bencher, parts: usize) {
b.with_inputs(|| Buffer::from(vec![1; 1_000_000 /
parts].repeat(parts)))
.bench_refs(|buffer| {
- loop {
- let Some(_) = buffer.next() else { break };
- }
+ // Fully consume the iterator, ignoring each item.
+ for _ in buffer.by_ref() {}
Review Comment:
The `by_ref()` call is redundant here. Since `buffer` is `&mut Buffer` (from
`bench_refs`) and `Buffer` implements `Iterator`, you can iterate directly with
`for _ in buffer {}`. The `&mut T where T: Iterator` automatically implements
`Iterator`, so `by_ref()` is unnecessary.
--
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]