eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 90e19a06111b126ec1f2eedb23c456912aa71a40
parent b059fbc7b511777f1bbcc81a67e8c1342bcffd5b
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 30 Dec 2025 14:08:26 +0000

replace loop with clone_from_slice

Diffstat:
Mecu-esp32/src/wifi.rs | 35++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -236,13 +236,25 @@ enum RData { impl RData { fn encode_as_label<'a>(name: &str, out: &'a mut [u8], offset: usize) -> &'a [u8] { let mut offset = offset; + for l in name.split('.') { + let end = l.len() + offset + 1; out[offset] = (l.len() & 0xff) as u8; - offset += 1; - for c in l.as_bytes().iter() { - out[offset] = *c; - offset += 1; - } + let _ = &out[(offset+1) .. end].clone_from_slice(l.as_bytes()); + offset = end; + } + out[offset] = 0; + &out[..offset+1] + } + + fn encode_as_strings<'a>(strings: &[String], out: &'a mut [u8], offset: usize) -> &'a [u8] { + let mut offset = offset; + + for l in strings.into_iter() { + let end = l.len() + offset + 1; + out[offset] = (l.len() & 0xff) as u8; + let _ = &out[(offset+1) .. end].clone_from_slice(l.as_bytes()); + offset = end; } out[offset] = 0; &out[..offset+1] @@ -257,7 +269,6 @@ impl RData { } } - fn to_bytes<'a>(&self, out: &'a mut [u8]) -> &'a [u8] { match self { RData::Srv { target, port, priority, weight } => { @@ -277,17 +288,7 @@ impl RData { &out[..4] }, RData::Txt(strings) => { - let mut offset = 0; - for s in strings { - out[offset] = (s.len() & 0xff) as u8; - offset += 1; - for c in s.as_bytes().iter() { - out[offset] = *c; - offset += 1; - } - } - out[offset] = 0; - &out[..(offset+1)] + Self::encode_as_strings(strings, out, 0) } } }