Coverage Report

Created: 2026-05-30 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2/src/proto/streams/buffer.rs
Line
Count
Source
1
use slab::Slab;
2
3
/// Buffers frames for multiple streams.
4
#[derive(Debug)]
5
pub struct Buffer<T> {
6
    slab: Slab<Slot<T>>,
7
}
8
9
/// A sequence of frames in a `Buffer`
10
#[derive(Debug)]
11
pub struct Deque {
12
    indices: Option<Indices>,
13
}
14
15
/// Tracks the head & tail for a sequence of frames in a `Buffer`.
16
#[derive(Debug, Default, Copy, Clone)]
17
struct Indices {
18
    head: usize,
19
    tail: usize,
20
}
21
22
#[derive(Debug)]
23
struct Slot<T> {
24
    value: T,
25
    next: Option<usize>,
26
}
27
28
impl<T> Buffer<T> {
29
29.1k
    pub fn new() -> Self {
30
29.1k
        Buffer { slab: Slab::new() }
31
29.1k
    }
<h2::proto::streams::buffer::Buffer<h2::proto::streams::recv::Event>>::new
Line
Count
Source
29
14.5k
    pub fn new() -> Self {
30
14.5k
        Buffer { slab: Slab::new() }
31
14.5k
    }
<h2::proto::streams::buffer::Buffer<h2::frame::Frame>>::new
Line
Count
Source
29
807
    pub fn new() -> Self {
30
807
        Buffer { slab: Slab::new() }
31
807
    }
<h2::proto::streams::buffer::Buffer<h2::frame::Frame>>::new
Line
Count
Source
29
13.7k
    pub fn new() -> Self {
30
13.7k
        Buffer { slab: Slab::new() }
31
13.7k
    }
32
33
1.05k
    pub fn is_empty(&self) -> bool {
34
1.05k
        self.slab.is_empty()
35
1.05k
    }
36
}
37
38
impl Deque {
39
1.03M
    pub fn new() -> Self {
40
1.03M
        Deque { indices: None }
41
1.03M
    }
42
43
4.24M
    pub fn is_empty(&self) -> bool {
44
4.24M
        self.indices.is_none()
45
4.24M
    }
46
47
1.00M
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
1.00M
        let key = buf.slab.insert(Slot { value, next: None });
49
50
1.00M
        match self.indices {
51
487k
            Some(ref mut idxs) => {
52
487k
                buf.slab[idxs.tail].next = Some(key);
53
487k
                idxs.tail = key;
54
487k
            }
55
515k
            None => {
56
515k
                self.indices = Some(Indices {
57
515k
                    head: key,
58
515k
                    tail: key,
59
515k
                });
60
515k
            }
61
        }
62
1.00M
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::proto::streams::recv::Event>
Line
Count
Source
47
459
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
459
        let key = buf.slab.insert(Slot { value, next: None });
49
50
459
        match self.indices {
51
18
            Some(ref mut idxs) => {
52
18
                buf.slab[idxs.tail].next = Some(key);
53
18
                idxs.tail = key;
54
18
            }
55
441
            None => {
56
441
                self.indices = Some(Indices {
57
441
                    head: key,
58
441
                    tail: key,
59
441
                });
60
441
            }
61
        }
62
459
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::frame::Frame>
Line
Count
Source
47
708
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
708
        let key = buf.slab.insert(Slot { value, next: None });
49
50
708
        match self.indices {
51
0
            Some(ref mut idxs) => {
52
0
                buf.slab[idxs.tail].next = Some(key);
53
0
                idxs.tail = key;
54
0
            }
55
708
            None => {
56
708
                self.indices = Some(Indices {
57
708
                    head: key,
58
708
                    tail: key,
59
708
                });
60
708
            }
61
        }
62
708
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::frame::Frame>
Line
Count
Source
47
1.00M
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
1.00M
        let key = buf.slab.insert(Slot { value, next: None });
49
50
1.00M
        match self.indices {
51
487k
            Some(ref mut idxs) => {
52
487k
                buf.slab[idxs.tail].next = Some(key);
53
487k
                idxs.tail = key;
54
487k
            }
55
514k
            None => {
56
514k
                self.indices = Some(Indices {
57
514k
                    head: key,
58
514k
                    tail: key,
59
514k
                });
60
514k
            }
61
        }
62
1.00M
    }
63
64
39.1k
    pub fn push_front<T>(&mut self, buf: &mut Buffer<T>, value: T) {
65
39.1k
        let key = buf.slab.insert(Slot { value, next: None });
66
67
39.1k
        match self.indices {
68
14
            Some(ref mut idxs) => {
69
14
                buf.slab[key].next = Some(idxs.head);
70
14
                idxs.head = key;
71
14
            }
72
39.0k
            None => {
73
39.0k
                self.indices = Some(Indices {
74
39.0k
                    head: key,
75
39.0k
                    tail: key,
76
39.0k
                });
77
39.0k
            }
78
        }
79
39.1k
    }
Unexecuted instantiation: <h2::proto::streams::buffer::Deque>::push_front::<h2::proto::streams::recv::Event>
<h2::proto::streams::buffer::Deque>::push_front::<h2::frame::Frame>
Line
Count
Source
64
39.1k
    pub fn push_front<T>(&mut self, buf: &mut Buffer<T>, value: T) {
65
39.1k
        let key = buf.slab.insert(Slot { value, next: None });
66
67
39.1k
        match self.indices {
68
14
            Some(ref mut idxs) => {
69
14
                buf.slab[key].next = Some(idxs.head);
70
14
                idxs.head = key;
71
14
            }
72
39.0k
            None => {
73
39.0k
                self.indices = Some(Indices {
74
39.0k
                    head: key,
75
39.0k
                    tail: key,
76
39.0k
                });
77
39.0k
            }
78
        }
79
39.1k
    }
80
81
2.27M
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
2.27M
        match self.indices {
83
1.04M
            Some(mut idxs) => {
84
1.04M
                let mut slot = buf.slab.remove(idxs.head);
85
86
1.04M
                if idxs.head == idxs.tail {
87
554k
                    assert!(slot.next.is_none());
88
554k
                    self.indices = None;
89
487k
                } else {
90
487k
                    idxs.head = slot.next.take().unwrap();
91
487k
                    self.indices = Some(idxs);
92
487k
                }
93
94
1.04M
                Some(slot.value)
95
            }
96
1.23M
            None => None,
97
        }
98
2.27M
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::proto::streams::recv::Event>
Line
Count
Source
81
567k
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
567k
        match self.indices {
83
231
            Some(mut idxs) => {
84
231
                let mut slot = buf.slab.remove(idxs.head);
85
86
231
                if idxs.head == idxs.tail {
87
219
                    assert!(slot.next.is_none());
88
219
                    self.indices = None;
89
12
                } else {
90
12
                    idxs.head = slot.next.take().unwrap();
91
12
                    self.indices = Some(idxs);
92
12
                }
93
94
231
                Some(slot.value)
95
            }
96
567k
            None => None,
97
        }
98
567k
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::frame::Frame>
Line
Count
Source
81
1.41k
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
1.41k
        match self.indices {
83
708
            Some(mut idxs) => {
84
708
                let mut slot = buf.slab.remove(idxs.head);
85
86
708
                if idxs.head == idxs.tail {
87
708
                    assert!(slot.next.is_none());
88
708
                    self.indices = None;
89
0
                } else {
90
0
                    idxs.head = slot.next.take().unwrap();
91
0
                    self.indices = Some(idxs);
92
0
                }
93
94
708
                Some(slot.value)
95
            }
96
708
            None => None,
97
        }
98
1.41k
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::frame::Frame>
Line
Count
Source
81
1.71M
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
1.71M
        match self.indices {
83
1.04M
            Some(mut idxs) => {
84
1.04M
                let mut slot = buf.slab.remove(idxs.head);
85
86
1.04M
                if idxs.head == idxs.tail {
87
553k
                    assert!(slot.next.is_none());
88
553k
                    self.indices = None;
89
487k
                } else {
90
487k
                    idxs.head = slot.next.take().unwrap();
91
487k
                    self.indices = Some(idxs);
92
487k
                }
93
94
1.04M
                Some(slot.value)
95
            }
96
670k
            None => None,
97
        }
98
1.71M
    }
99
}