mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
wrap sendprop definition in an Rc
This commit is contained in:
parent
e90bc53852
commit
a7702856d0
3 changed files with 22 additions and 21 deletions
|
|
@ -8,6 +8,7 @@ use crate::demo::sendprop::{SendProp, SendPropDefinition, SendPropValue};
|
||||||
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::hint::unreachable_unchecked;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
@ -69,7 +70,7 @@ impl PacketEntity {
|
||||||
fn get_prop_by_definition(&mut self, definition: &SendPropDefinition) -> Option<&mut SendProp> {
|
fn get_prop_by_definition(&mut self, definition: &SendPropDefinition) -> Option<&mut SendProp> {
|
||||||
self.props
|
self.props
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|prop| prop.definition.eq(definition))
|
.find(|prop| prop.definition.as_ref().eq(definition))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_update(&mut self, props: Vec<SendProp>) {
|
pub fn apply_update(&mut self, props: Vec<SendProp>) {
|
||||||
|
|
@ -90,7 +91,7 @@ fn read_bit_var<T: BitReadSized<LittleEndian>>(stream: &mut Stream) -> ReadResul
|
||||||
1 => 8,
|
1 => 8,
|
||||||
2 => 12,
|
2 => 12,
|
||||||
3 => 32,
|
3 => 32,
|
||||||
_ => unreachable!(),
|
_ => unsafe { unreachable_unchecked() },
|
||||||
};
|
};
|
||||||
stream.read_sized(bits)
|
stream.read_sized(bits)
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +248,7 @@ impl PacketEntitiesMessage {
|
||||||
Some(definition) => {
|
Some(definition) => {
|
||||||
let value = SendPropValue::parse(stream, definition)?;
|
let value = SendPropValue::parse(stream, definition)?;
|
||||||
props.push(SendProp {
|
props.push(SendProp {
|
||||||
definition: definition.clone(),
|
definition: Rc::clone(definition),
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ impl From<String> for SendTableName {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParseSendTable {
|
pub struct ParseSendTable {
|
||||||
pub name: SendTableName,
|
pub name: SendTableName,
|
||||||
pub props: Vec<SendPropDefinition>,
|
pub props: Vec<Rc<SendPropDefinition>>,
|
||||||
pub needs_decoder: bool,
|
pub needs_decoder: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,9 +86,9 @@ impl Parse for ParseSendTable {
|
||||||
return Err(MalformedSendPropDefinitionError::UntypedArray.into());
|
return Err(MalformedSendPropDefinitionError::UntypedArray.into());
|
||||||
}
|
}
|
||||||
array_element_prop = None;
|
array_element_prop = None;
|
||||||
props.push(prop.with_array_property(array_element));
|
props.push(Rc::new(prop.with_array_property(array_element)));
|
||||||
} else {
|
} else {
|
||||||
props.push(prop);
|
props.push(Rc::new(prop));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ impl Parse for ParseSendTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseSendTable {
|
impl ParseSendTable {
|
||||||
pub fn flatten_props(&self, tables: &[ParseSendTable]) -> Vec<SendPropDefinition> {
|
pub fn flatten_props(&self, tables: &[ParseSendTable]) -> Vec<Rc<SendPropDefinition>> {
|
||||||
let mut flat = Vec::with_capacity(32);
|
let mut flat = Vec::with_capacity(32);
|
||||||
self.get_all_props(tables, &self.get_excludes(tables), &mut flat);
|
self.get_all_props(tables, &self.get_excludes(tables), &mut flat);
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ impl ParseSendTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flat.into_iter().map(|prop| prop.clone()).collect()
|
flat.into_iter().map(|prop| Rc::clone(&prop)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<Exclude<'a>> {
|
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<Exclude<'a>> {
|
||||||
|
|
@ -137,11 +137,11 @@ impl ParseSendTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: below is a direct port from the js which is a direct port from C++ and not very optimal
|
// TODO: below is a direct port from the js which is a direct port from C++ and not very optimal
|
||||||
fn get_all_props<'a>(
|
fn get_all_props(
|
||||||
&'a self,
|
&self,
|
||||||
tables: &'a [ParseSendTable],
|
tables: &[ParseSendTable],
|
||||||
excludes: &[Exclude],
|
excludes: &[Exclude],
|
||||||
props: &mut Vec<&'a SendPropDefinition>,
|
props: &mut Vec<Rc<SendPropDefinition>>,
|
||||||
) {
|
) {
|
||||||
let mut local_props = Vec::new();
|
let mut local_props = Vec::new();
|
||||||
|
|
||||||
|
|
@ -149,12 +149,12 @@ impl ParseSendTable {
|
||||||
props.extend_from_slice(&local_props);
|
props.extend_from_slice(&local_props);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_all_props_iterator_props<'a>(
|
fn get_all_props_iterator_props(
|
||||||
&'a self,
|
&self,
|
||||||
tables: &'a [ParseSendTable],
|
tables: &[ParseSendTable],
|
||||||
excludes: &[Exclude],
|
excludes: &[Exclude],
|
||||||
local_props: &mut Vec<&'a SendPropDefinition>,
|
local_props: &mut Vec<Rc<SendPropDefinition>>,
|
||||||
props: &mut Vec<&'a SendPropDefinition>,
|
props: &mut Vec<Rc<SendPropDefinition>>,
|
||||||
) {
|
) {
|
||||||
self.props
|
self.props
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -168,7 +168,7 @@ impl ParseSendTable {
|
||||||
table.get_all_props(tables, excludes, props);
|
table.get_all_props(tables, excludes, props);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
local_props.push(prop);
|
local_props.push(Rc::clone(prop));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -189,9 +189,9 @@ impl<'a> Exclude<'a> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SendTable {
|
pub struct SendTable {
|
||||||
pub name: SendTableName,
|
pub name: SendTableName,
|
||||||
pub props: Vec<SendPropDefinition>,
|
pub props: Vec<Rc<SendPropDefinition>>,
|
||||||
pub needs_decoder: bool,
|
pub needs_decoder: bool,
|
||||||
pub flattened_props: Vec<SendPropDefinition>,
|
pub flattened_props: Vec<Rc<SendPropDefinition>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,7 @@ impl From<Vec<SendPropValue>> for SendPropValue {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SendProp {
|
pub struct SendProp {
|
||||||
pub definition: SendPropDefinition,
|
pub definition: Rc<SendPropDefinition>,
|
||||||
pub value: SendPropValue,
|
pub value: SendPropValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue