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:
Oliver Hamlet
2025-03-28 18:00:16 +00:00
parent b17691dbdd
commit b996406e8f
2 changed files with 9 additions and 3 deletions
+3 -1
View File
@@ -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,
+6 -2
View File
@@ -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 {