mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Shrink metadata vectors some metadata vectors during YAML parsing
For the Skyrim SE masterlist this saved ~ 3 MB of memory, and there was no noticeable impact doing the same for other metadata collection fields.
This commit is contained in:
@@ -263,7 +263,7 @@ pub(crate) fn parse_message_contents_yaml(
|
||||
key: &'static str,
|
||||
parent_yaml_type: YamlObjectType,
|
||||
) -> Result<Vec<MessageContent>, ParseMetadataError> {
|
||||
let contents = match &value.data {
|
||||
let mut contents = match &value.data {
|
||||
YamlData::String(s) => {
|
||||
vec![MessageContent::new(s.clone())]
|
||||
}
|
||||
@@ -281,6 +281,8 @@ pub(crate) fn parse_message_contents_yaml(
|
||||
}
|
||||
};
|
||||
|
||||
contents.shrink_to_fit();
|
||||
|
||||
if validate_message_contents(&contents).is_err() {
|
||||
Err(ParseMetadataError::new(
|
||||
value.span.start,
|
||||
|
||||
@@ -377,10 +377,14 @@ fn get_vec<'a, T: TryFrom<&'a MarkedYaml, Error = impl Into<ParseMetadataError>>
|
||||
hash: &'a saphyr::AnnotatedHash<MarkedYaml>,
|
||||
key: &'static str,
|
||||
) -> Result<Vec<T>, ParseMetadataError> {
|
||||
get_as_slice(hash, key, YamlObjectType::PluginMetadata)?
|
||||
let mut vec = get_as_slice(hash, key, YamlObjectType::PluginMetadata)?
|
||||
.iter()
|
||||
.map(|e| T::try_from(e).map_err(Into::into))
|
||||
.collect::<Result<Vec<T>, _>>()
|
||||
.collect::<Result<Vec<T>, _>>()?;
|
||||
|
||||
vec.shrink_to_fit();
|
||||
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
impl EmitYaml for PluginMetadata {
|
||||
|
||||
Reference in New Issue
Block a user