From 47d418c69e3d43554779c2867172a0b0b8348285 Mon Sep 17 00:00:00 2001 From: occheung Date: Thu, 5 Sep 2024 12:16:21 +0800 Subject: [PATCH] coremgmt: remove unnecsaary cursors --- src/runtime/src/mgmt.rs | 6 +++--- src/satman/src/mgmt.rs | 15 ++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/runtime/src/mgmt.rs b/src/runtime/src/mgmt.rs index 3b6d8ec..b2e5a88 100644 --- a/src/runtime/src/mgmt.rs +++ b/src/runtime/src/mgmt.rs @@ -135,7 +135,7 @@ async fn read_key(stream: &mut TcpStream) -> Result { #[cfg(has_drtio)] mod remote_coremgmt { use core_io::Read; - use io::{Cursor, ProtoWrite}; + use io::ProtoWrite; use libboard_artiq::{drtioaux_async, drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE}}; @@ -427,7 +427,7 @@ mod remote_coremgmt { value: Vec, _restart_idle: &Rc, ) -> Result<()> { - let mut message = Cursor::new(Vec::with_capacity(key.len() + value.len() + 4 * 2)); + let mut message = Vec::with_capacity(key.len() + value.len() + 4 * 2); message.write_string(key).unwrap(); message.write_bytes(&value).unwrap(); @@ -436,7 +436,7 @@ mod remote_coremgmt { aux_mutex, routing_table, timer, - message.get_ref(), + &message, |slice, status, len: usize| Packet::CoreMgmtConfigWriteRequest { destination: destination, last: status.is_last(), diff --git a/src/satman/src/mgmt.rs b/src/satman/src/mgmt.rs index 8b7e569..9866999 100644 --- a/src/satman/src/mgmt.rs +++ b/src/satman/src/mgmt.rs @@ -48,7 +48,7 @@ pub fn clear_log() { pub struct Manager<'a> { cfg: &'a mut Config, last_log: Sliceable, - config_payload: Cursor>, + config_payload: Vec, last_value: Sliceable, image_payload: Vec, } @@ -58,7 +58,7 @@ impl<'a> Manager<'_> { Manager { cfg: cfg, last_log: Sliceable::new(0, Vec::new()), - config_payload: Cursor::new(Vec::new()), + config_payload: Vec::new(), last_value: Sliceable::new(0, Vec::new()), image_payload: Vec::new(), } @@ -92,17 +92,14 @@ impl<'a> Manager<'_> { } pub fn clear_config_data(&mut self) { - self.config_payload.get_mut().clear(); - self.config_payload.set_position(0); + self.config_payload.clear(); } pub fn write_config(&mut self) -> Result<()> { - let key = self - .config_payload - .read_string() - .map_err(|_err| error!("error on reading key"))?; + let mut payload = &self.config_payload[..]; + let key = payload.read_string().map_err(|_err| error!("error on reading key"))?; debug!("write key: {}", key); - let value = self.config_payload.read_bytes().unwrap(); + let value = payload.read_bytes().unwrap(); self.cfg .write(&key, value)