Coverage Report

Created: 2026-02-26 06:09

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
28.8k
    pub fn new() -> Self {
30
28.8k
        Buffer { slab: Slab::new() }
31
28.8k
    }
<h2::proto::streams::buffer::Buffer<h2::proto::streams::recv::Event>>::new
Line
Count
Source
29
14.4k
    pub fn new() -> Self {
30
14.4k
        Buffer { slab: Slab::new() }
31
14.4k
    }
<h2::proto::streams::buffer::Buffer<h2::frame::Frame>>::new
Line
Count
Source
29
827
    pub fn new() -> Self {
30
827
        Buffer { slab: Slab::new() }
31
827
    }
<h2::proto::streams::buffer::Buffer<h2::frame::Frame>>::new
Line
Count
Source
29
13.6k
    pub fn new() -> Self {
30
13.6k
        Buffer { slab: Slab::new() }
31
13.6k
    }
32
33
1.21k
    pub fn is_empty(&self) -> bool {
34
1.21k
        self.slab.is_empty()
35
1.21k
    }
36
}
37
38
impl Deque {
39
1.08M
    pub fn new() -> Self {
40
1.08M
        Deque { indices: None }
41
1.08M
    }
42
43
4.62M
    pub fn is_empty(&self) -> bool {
44
4.62M
        self.indices.is_none()
45
4.62M
    }
46
47
1.03M
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
1.03M
        let key = buf.slab.insert(Slot { value, next: None });
49
50
1.03M
        match self.indices {
51
484k
            Some(ref mut idxs) => {
52
484k
                buf.slab[idxs.tail].next = Some(key);
53
484k
                idxs.tail = key;
54
484k
            }
55
545k
            None => {
56
545k
                self.indices = Some(Indices {
57
545k
                    head: key,
58
545k
                    tail: key,
59
545k
                });
60
545k
            }
61
        }
62
1.03M
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::proto::streams::recv::Event>
Line
Count
Source
47
6.61k
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
6.61k
        let key = buf.slab.insert(Slot { value, next: None });
49
50
6.61k
        match self.indices {
51
4.07k
            Some(ref mut idxs) => {
52
4.07k
                buf.slab[idxs.tail].next = Some(key);
53
4.07k
                idxs.tail = key;
54
4.07k
            }
55
2.54k
            None => {
56
2.54k
                self.indices = Some(Indices {
57
2.54k
                    head: key,
58
2.54k
                    tail: key,
59
2.54k
                });
60
2.54k
            }
61
        }
62
6.61k
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::frame::Frame>
Line
Count
Source
47
747
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
747
        let key = buf.slab.insert(Slot { value, next: None });
49
50
747
        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
747
            None => {
56
747
                self.indices = Some(Indices {
57
747
                    head: key,
58
747
                    tail: key,
59
747
                });
60
747
            }
61
        }
62
747
    }
<h2::proto::streams::buffer::Deque>::push_back::<h2::frame::Frame>
Line
Count
Source
47
1.02M
    pub fn push_back<T>(&mut self, buf: &mut Buffer<T>, value: T) {
48
1.02M
        let key = buf.slab.insert(Slot { value, next: None });
49
50
1.02M
        match self.indices {
51
480k
            Some(ref mut idxs) => {
52
480k
                buf.slab[idxs.tail].next = Some(key);
53
480k
                idxs.tail = key;
54
480k
            }
55
541k
            None => {
56
541k
                self.indices = Some(Indices {
57
541k
                    head: key,
58
541k
                    tail: key,
59
541k
                });
60
541k
            }
61
        }
62
1.02M
    }
63
64
55.7k
    pub fn push_front<T>(&mut self, buf: &mut Buffer<T>, value: T) {
65
55.7k
        let key = buf.slab.insert(Slot { value, next: None });
66
67
55.7k
        match self.indices {
68
74
            Some(ref mut idxs) => {
69
74
                buf.slab[key].next = Some(idxs.head);
70
74
                idxs.head = key;
71
74
            }
72
55.6k
            None => {
73
55.6k
                self.indices = Some(Indices {
74
55.6k
                    head: key,
75
55.6k
                    tail: key,
76
55.6k
                });
77
55.6k
            }
78
        }
79
55.7k
    }
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
55.7k
    pub fn push_front<T>(&mut self, buf: &mut Buffer<T>, value: T) {
65
55.7k
        let key = buf.slab.insert(Slot { value, next: None });
66
67
55.7k
        match self.indices {
68
74
            Some(ref mut idxs) => {
69
74
                buf.slab[key].next = Some(idxs.head);
70
74
                idxs.head = key;
71
74
            }
72
55.6k
            None => {
73
55.6k
                self.indices = Some(Indices {
74
55.6k
                    head: key,
75
55.6k
                    tail: key,
76
55.6k
                });
77
55.6k
            }
78
        }
79
55.7k
    }
80
81
2.44M
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
2.44M
        match self.indices {
83
1.08M
            Some(mut idxs) => {
84
1.08M
                let mut slot = buf.slab.remove(idxs.head);
85
86
1.08M
                if idxs.head == idxs.tail {
87
599k
                    assert!(slot.next.is_none());
88
599k
                    self.indices = None;
89
484k
                } else {
90
484k
                    idxs.head = slot.next.take().unwrap();
91
484k
                    self.indices = Some(idxs);
92
484k
                }
93
94
1.08M
                Some(slot.value)
95
            }
96
1.36M
            None => None,
97
        }
98
2.44M
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::proto::streams::recv::Event>
Line
Count
Source
81
523k
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
523k
        match self.indices {
83
4.95k
            Some(mut idxs) => {
84
4.95k
                let mut slot = buf.slab.remove(idxs.head);
85
86
4.95k
                if idxs.head == idxs.tail {
87
1.58k
                    assert!(slot.next.is_none());
88
1.58k
                    self.indices = None;
89
3.36k
                } else {
90
3.36k
                    idxs.head = slot.next.take().unwrap();
91
3.36k
                    self.indices = Some(idxs);
92
3.36k
                }
93
94
4.95k
                Some(slot.value)
95
            }
96
518k
            None => None,
97
        }
98
523k
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::frame::Frame>
Line
Count
Source
81
1.49k
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
1.49k
        match self.indices {
83
747
            Some(mut idxs) => {
84
747
                let mut slot = buf.slab.remove(idxs.head);
85
86
747
                if idxs.head == idxs.tail {
87
747
                    assert!(slot.next.is_none());
88
747
                    self.indices = None;
89
0
                } else {
90
0
                    idxs.head = slot.next.take().unwrap();
91
0
                    self.indices = Some(idxs);
92
0
                }
93
94
747
                Some(slot.value)
95
            }
96
747
            None => None,
97
        }
98
1.49k
    }
<h2::proto::streams::buffer::Deque>::pop_front::<h2::frame::Frame>
Line
Count
Source
81
1.92M
    pub fn pop_front<T>(&mut self, buf: &mut Buffer<T>) -> Option<T> {
82
1.92M
        match self.indices {
83
1.07M
            Some(mut idxs) => {
84
1.07M
                let mut slot = buf.slab.remove(idxs.head);
85
86
1.07M
                if idxs.head == idxs.tail {
87
597k
                    assert!(slot.next.is_none());
88
597k
                    self.indices = None;
89
480k
                } else {
90
480k
                    idxs.head = slot.next.take().unwrap();
91
480k
                    self.indices = Some(idxs);
92
480k
                }
93
94
1.07M
                Some(slot.value)
95
            }
96
843k
            None => None,
97
        }
98
1.92M
    }
99
}