Skip to content

Commit be1e755

Browse files
authored
fix: qpack idiomization (mozilla#3181)
1 parent 64caf4c commit be1e755

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

neqo-qpack/src/table.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ impl HeaderTable {
134134
/// `HeaderLookup` if the index does not exist in the static table.
135135
pub fn get_static(index: u64) -> Res<&'static StaticTableEntry> {
136136
let inx = usize::try_from(index).or(Err(Error::HeaderLookup))?;
137-
if inx >= HEADER_STATIC_TABLE.len() {
138-
return Err(Error::HeaderLookup);
139-
}
140-
Ok(&HEADER_STATIC_TABLE[inx])
137+
HEADER_STATIC_TABLE.get(inx).ok_or(Error::HeaderLookup)
141138
}
142139

143140
fn get_dynamic_with_abs_index(&mut self, index: u64) -> Res<&mut DynamicTableEntry> {
@@ -147,18 +144,12 @@ impl HeaderTable {
147144
}
148145
let inx = self.base - index - 1;
149146
let inx = usize::try_from(inx).or(Err(Error::HeaderLookup))?;
150-
if inx >= self.dynamic.len() {
151-
return Err(Error::HeaderLookup);
152-
}
153-
Ok(&mut self.dynamic[inx])
147+
self.dynamic.get_mut(inx).ok_or(Error::HeaderLookup)
154148
}
155149

156150
fn get_dynamic_with_relative_index(&self, index: u64) -> Res<&DynamicTableEntry> {
157151
let inx = usize::try_from(index).or(Err(Error::HeaderLookup))?;
158-
if inx >= self.dynamic.len() {
159-
return Err(Error::HeaderLookup);
160-
}
161-
Ok(&self.dynamic[inx])
152+
self.dynamic.get(inx).ok_or(Error::HeaderLookup)
162153
}
163154

164155
/// Get a entry in the dynamic table.
@@ -254,14 +245,15 @@ impl HeaderTable {
254245
"[{self}] reduce table to {reduce}, currently used:{}",
255246
self.used,
256247
);
257-
while (!self.dynamic.is_empty()) && self.used > reduce {
258-
if let Some(e) = self.dynamic.back() {
259-
if !e.can_reduce(self.acked_inserts_cnt) {
260-
return false;
261-
}
262-
self.used -= u64::try_from(e.size()).expect("usize fits in u64");
263-
self.dynamic.pop_back();
248+
while let Some(e) = self.dynamic.back() {
249+
if self.used <= reduce {
250+
break;
251+
}
252+
if !e.can_reduce(self.acked_inserts_cnt) {
253+
return false;
264254
}
255+
self.used -= u64::try_from(e.size()).expect("usize fits in u64");
256+
self.dynamic.pop_back();
265257
}
266258
true
267259
}

0 commit comments

Comments
 (0)