Use correct length in advance when loading files

This reduces the need to shuffle the stack
This commit is contained in:
Sosthène Guédon
2023-04-13 10:17:40 +02:00
parent ac6097a8d1
commit 6e2a89327a
2 changed files with 8 additions and 3 deletions
+5 -3
View File
@@ -907,9 +907,12 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent
_ => &[0x53],
};
reply.expand(tag)?;
let offset = reply.len();
match container {
Container::KeyHistoryObject => self.get_key_history_object(reply.lend())?,
Container::KeyHistoryObject => {
let offset = reply.len();
self.get_key_history_object(reply.lend())?;
reply.prepend_len(offset)?;
}
_ => {
if !ContainerStorage(container).load(
self.trussed,
@@ -920,7 +923,6 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent
}
}
}
reply.prepend_len(offset)?;
Ok(())
}
+3
View File
@@ -632,6 +632,7 @@ fn load_if_exists_streaming<const R: usize>(
Ok(r) => {
read_len += r.data.len();
file_len = r.len;
buffer.append_len(file_len)?;
buffer.expand(&r.data)?;
}
Err(_) => match try_syscall!(client.entry_metadata(location, path.clone())) {
@@ -752,6 +753,7 @@ impl ContainerStorage {
}
}
// Write the length of the file and write
pub fn load<const R: usize>(
self,
client: &mut impl trussed::Client,
@@ -763,6 +765,7 @@ impl ContainerStorage {
}
if let Some(data) = self.default() {
reply.append_len(data.len())?;
reply.expand(&data)?;
Ok(true)
} else {