Skip to content

Commit 70e4d61

Browse files
pdogrStranger6667
authored andcommitted
perf: Reduce the size of PrimitiveTypesBitMapIterator
1 parent 6da868d commit 70e4d61

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

jsonschema/src/primitive_type.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl IntoIterator for PrimitiveTypesBitMap {
118118
type IntoIter = PrimitiveTypesBitMapIterator;
119119
fn into_iter(self) -> Self::IntoIter {
120120
PrimitiveTypesBitMapIterator {
121-
range: 0..7,
121+
idx: 0,
122122
bit_map: self,
123123
}
124124
}
@@ -137,23 +137,21 @@ impl From<Vec<PrimitiveType>> for PrimitiveTypesBitMap {
137137
/// Iterator over all `PrimitiveType` present in a `PrimitiveTypesBitMap`
138138
#[derive(Debug)]
139139
pub struct PrimitiveTypesBitMapIterator {
140-
range: std::ops::Range<u8>,
140+
idx: u8,
141141
bit_map: PrimitiveTypesBitMap,
142142
}
143143
impl Iterator for PrimitiveTypesBitMapIterator {
144144
type Item = PrimitiveType;
145145
#[allow(clippy::integer_arithmetic)]
146146
fn next(&mut self) -> Option<Self::Item> {
147-
loop {
148-
if let Some(value) = self.range.next() {
149-
let bit_value = 1 << value;
150-
if self.bit_map.inner & bit_value != 0 {
151-
return Some(bit_map_representation_primitive_type(bit_value));
152-
}
153-
} else {
154-
return None;
147+
while self.idx <= 7 {
148+
let bit_value = 1 << self.idx;
149+
self.idx += 1;
150+
if self.bit_map.inner & bit_value != 0 {
151+
return Some(bit_map_representation_primitive_type(bit_value));
155152
}
156153
}
154+
None
157155
}
158156
}
159157

0 commit comments

Comments
 (0)