From 02bd14d9ec3444caea138bb67c2faa5463a70a89 Mon Sep 17 00:00:00 2001 From: Ximon Eighteen <3304436+ximon18@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:46:44 +0100 Subject: [PATCH] Don't over allocate. --- src/commands/signzone.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands/signzone.rs b/src/commands/signzone.rs index 8bfa426..fc85d67 100644 --- a/src/commands/signzone.rs +++ b/src/commands/signzone.rs @@ -657,12 +657,21 @@ impl SignZone { env: &impl Env, expected_apex: Option<&Name>, ) -> Result, Error> { + // Don't use Zonefile::load() as it knows nothing about the size of + // the original file so uses default allocation which allocates more + // bytes than are needed. Instead control the allocation size based on + // our knowledge of the file size. let mut zone_file = File::open(env.in_cwd(&self.zonefile_path))?; - let mut reader = inplace::Zonefile::load(&mut zone_file)?; + let zone_file_len = zone_file.metadata()?.len(); + let mut buf = inplace::Zonefile::with_capacity(zone_file_len as usize).writer(); + std::io::copy(&mut zone_file, &mut buf)?; + let mut reader = buf.into_inner(); + let mut records = SortedRecords::new(); + if let Some(origin) = &self.origin { reader.set_origin(origin.clone()); } - let mut records = SortedRecords::new(); + for entry in reader { let entry = entry.map_err(|err| format!("Invalid zone file: {err}"))?; match entry {