Skip to content

Commit 89dc7b7

Browse files
Improve shrinking code
1 parent 1ace019 commit 89dc7b7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

simpleinterpolation/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ impl InterpolationCompiler {
152152
escaped: false,
153153
};
154154

155-
// for each character, check if the character is a
155+
// for each character, check if the character exists, then
156+
// feed it into the compiler
156157
while let Some(character) = compiler.chars.get(compiler.index).copied() {
157158
compiler.handle_char(character)?;
158159
}
159160

160-
compiler.parts.shrink_to_fit();
161+
compiler.shrink();
161162

162163
Ok(Interpolation {
163164
parts: compiler.parts,
@@ -215,6 +216,17 @@ impl InterpolationCompiler {
215216
}
216217
Ok(identifier)
217218
}
219+
220+
fn shrink(&mut self) {
221+
self.parts.shrink_to_fit();
222+
223+
for (a, b) in &mut self.parts {
224+
a.shrink_to_fit();
225+
b.shrink_to_fit();
226+
}
227+
228+
self.next.shrink_to_fit();
229+
}
218230
}
219231

220232
/// Error returned in the parsing stage.

0 commit comments

Comments
 (0)