mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
minor cleanup
This commit is contained in:
parent
e005f35f73
commit
8442c5e385
4 changed files with 34 additions and 28 deletions
|
|
@ -186,7 +186,9 @@ fn parse_string_table_list(
|
||||||
|
|
||||||
for _ in 0..entry_count {
|
for _ in 0..entry_count {
|
||||||
if !stream.read::<bool>()? {
|
if !stream.read::<bool>()? {
|
||||||
return Err(ParseError::InvalidDemo("there should be no holes when reading CreateStringTable message".to_string()));
|
return Err(ParseError::InvalidDemo(
|
||||||
|
"there should be no holes when reading CreateStringTable message".to_string(),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let entry = read_table_entry(stream, table_meta, &history)?;
|
let entry = read_table_entry(stream, table_meta, &history)?;
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,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<SendPropDefinition> {
|
||||||
let mut flat = Vec::new();
|
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);
|
||||||
|
|
||||||
// sort often changed props before the others
|
// sort often changed props before the others
|
||||||
|
|
@ -109,18 +109,16 @@ impl ParseSendTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<Exclude<'a>> {
|
fn get_excludes<'a>(&'a self, tables: &'a [ParseSendTable]) -> Vec<Exclude<'a>> {
|
||||||
let mut excludes = Vec::new();
|
let mut excludes = Vec::with_capacity(8);
|
||||||
|
|
||||||
for prop in self.props.iter() {
|
for prop in self.props.iter() {
|
||||||
if prop.is_exclude() && prop.table_name.is_some() {
|
if let Some(exclude_table) = prop.get_exclude_table() {
|
||||||
excludes.push(Exclude {
|
excludes.push(Exclude {
|
||||||
table: prop.table_name.as_ref().unwrap(),
|
table: exclude_table,
|
||||||
prop: &prop.name,
|
prop: &prop.name,
|
||||||
})
|
})
|
||||||
} else if prop.prop_type == SendPropType::DataTable {
|
} else if let Some(table) = prop.get_data_table(tables) {
|
||||||
if let Some(table) = prop.get_data_table(tables) {
|
excludes.extend_from_slice(&table.get_excludes(tables));
|
||||||
excludes.extend_from_slice(&table.get_excludes(tables));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,27 +145,21 @@ impl ParseSendTable {
|
||||||
local_props: &mut Vec<&'a SendPropDefinition>,
|
local_props: &mut Vec<&'a SendPropDefinition>,
|
||||||
props: &mut Vec<&'a SendPropDefinition>,
|
props: &mut Vec<&'a SendPropDefinition>,
|
||||||
) {
|
) {
|
||||||
for prop in self.props.iter() {
|
self.props
|
||||||
if prop.is_exclude() {
|
.iter()
|
||||||
continue;
|
.filter(|prop| !prop.is_exclude())
|
||||||
}
|
.filter(|prop| !excludes.iter().any(|exclude| exclude.matches(prop)))
|
||||||
|
.for_each(|prop| {
|
||||||
if excludes.iter().any(|exclude| exclude.matches(prop)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if prop.prop_type == SendPropType::DataTable {
|
|
||||||
if let Some(table) = prop.get_data_table(tables) {
|
if let Some(table) = prop.get_data_table(tables) {
|
||||||
if prop.flags.contains(SendPropFlag::Collapsible) {
|
if prop.flags.contains(SendPropFlag::Collapsible) {
|
||||||
table.get_all_props_iterator_props(tables, excludes, local_props, props);
|
table.get_all_props_iterator_props(tables, excludes, local_props, props);
|
||||||
} else {
|
} else {
|
||||||
table.get_all_props(tables, excludes, props);
|
table.get_all_props(tables, excludes, props);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
local_props.push(prop);
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
local_props.push(prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +171,7 @@ struct Exclude<'a> {
|
||||||
|
|
||||||
impl<'a> Exclude<'a> {
|
impl<'a> Exclude<'a> {
|
||||||
pub fn matches(&self, prop: &SendPropDefinition) -> bool {
|
pub fn matches(&self, prop: &SendPropDefinition) -> bool {
|
||||||
self.prop == prop.name && self.table == &prop.owner_table
|
self.table == &prop.owner_table && self.prop == prop.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ pub enum ParseError {
|
||||||
size: u32,
|
size: u32,
|
||||||
},
|
},
|
||||||
/// Misc malformed demo error
|
/// Misc malformed demo error
|
||||||
InvalidDemo(String)
|
InvalidDemo(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ReadError> for ParseError {
|
impl From<ReadError> for ParseError {
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,13 @@ impl SendPropDefinition {
|
||||||
///
|
///
|
||||||
/// Note that this is not the owner table
|
/// Note that this is not the owner table
|
||||||
pub fn get_data_table<'a>(&self, tables: &'a [ParseSendTable]) -> Option<&'a ParseSendTable> {
|
pub fn get_data_table<'a>(&self, tables: &'a [ParseSendTable]) -> Option<&'a ParseSendTable> {
|
||||||
self.table_name
|
if self.prop_type == SendPropType::DataTable {
|
||||||
.as_ref()
|
self.table_name
|
||||||
.and_then(|name| tables.iter().find(|table| table.name == *name))
|
.as_ref()
|
||||||
|
.and_then(|name| tables.iter().find(|table| table.name == *name))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(stream: &mut Stream, owner_table: SendTableName) -> ReadResult<Self> {
|
pub fn read(stream: &mut Stream, owner_table: SendTableName) -> ReadResult<Self> {
|
||||||
|
|
@ -99,6 +103,14 @@ impl SendPropDefinition {
|
||||||
pub fn is_exclude(&self) -> bool {
|
pub fn is_exclude(&self) -> bool {
|
||||||
self.flags.contains(SendPropFlag::Exclude)
|
self.flags.contains(SendPropFlag::Exclude)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_exclude_table(&self) -> Option<&SendTableName> {
|
||||||
|
if self.is_exclude() {
|
||||||
|
self.table_name.as_ref()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(BitRead, Copy, Clone, PartialEq, Debug)]
|
#[derive(BitRead, Copy, Clone, PartialEq, Debug)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue