Skip to content

Commit 9779383

Browse files
committed
add early exit
1 parent 642eb9f commit 9779383

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/parser/src/parser.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ impl Parser {
5656
let size = self.read_varint()?;
5757
self.tick = tick as i32;
5858

59+
if self.should_early_exit() {
60+
break;
61+
}
62+
5963
// Safety check
6064
if self.ptr + size as usize >= self.bytes.get_len() {
6165
break;
@@ -64,7 +68,7 @@ impl Parser {
6468
let is_compressed = (cmd & 64) == 64;
6569
let demo_cmd = demo_cmd_type_from_int(msg_type as i32).unwrap();
6670

67-
// Early exit these for performance reasons
71+
// skip these for performance reasons
6872
if demo_cmd == DEM_Packet || demo_cmd == DEM_AnimationData {
6973
self.ptr += size as usize;
7074
continue;
@@ -126,6 +130,21 @@ impl Parser {
126130
}
127131
Ok(self.combine_thread_outputs(&mut ok))
128132
}
133+
fn should_early_exit(&self) -> bool {
134+
if self.only_header && !self.header.is_empty() {
135+
return true;
136+
}
137+
if !self.wanted_ticks.is_empty() {
138+
// odd ticks in beginning of demo
139+
if self.tick > 1000000 {
140+
return false;
141+
}
142+
if self.largest_wanted_tick < self.tick {
143+
return true;
144+
}
145+
}
146+
false
147+
}
129148
// fn parse_stringtables_cmd(bytes: &[u8]) -> Result<(), DemoParserError> {}
130149
pub fn create_parser_thread_input(&self, offset: usize, parse_all: bool) -> ParserThreadInput {
131150
let cls_by_id = match &self.cls_by_id {

src/parser/src/parser_settings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub struct Parser {
8181
pub prop_out_id: u8,
8282
pub only_header: bool,
8383
pub prop_infos: Vec<PropInfo>,
84+
pub largest_wanted_tick: i32,
8485

8586
pub header: AHashMap<String, String>,
8687
pub threads_spawned: u32,
@@ -92,6 +93,7 @@ impl Parser {
9293
let arc_huf = inputs.huffman_lookup_table.clone();
9394
Parser {
9495
threads_spawned: 0,
96+
largest_wanted_tick: *inputs.wanted_ticks.iter().max().unwrap_or(&999999999),
9597
stringtable_players: AHashMap::default(),
9698
only_header: inputs.only_header,
9799
ge_list_set: false,

0 commit comments

Comments
 (0)