Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/output.rs')
-rw-r--r--crates/parser/src/output.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/parser/src/output.rs b/crates/parser/src/output.rs
index 0ea15a656c..2f09b11218 100644
--- a/crates/parser/src/output.rs
+++ b/crates/parser/src/output.rs
@@ -33,6 +33,14 @@ pub enum Step<'a> {
}
impl Output {
+ /// Preallocate the event buffer. Each `Event` in the input stream maps to
+ /// roughly one `u32` in the output, so passing the event count as the
+ /// initial capacity avoids most of the amortized `Vec::grow` allocations
+ /// during `event::process`.
+ pub(crate) fn with_event_capacity(cap: usize) -> Self {
+ Output { event: Vec::with_capacity(cap), error: Vec::new() }
+ }
+
const EVENT_MASK: u32 = 0b1;
const TAG_MASK: u32 = 0x0000_00F0;
const N_INPUT_TOKEN_MASK: u32 = 0x0000_FF00;