From 3832b261b152e78d0bebb59044048913910d7330 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 21 Jan 2021 12:16:14 +0800 Subject: [PATCH] firmware: optimize integer array/list rpc --- artiq/firmware/libproto_artiq/rpc_proto.rs | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/artiq/firmware/libproto_artiq/rpc_proto.rs b/artiq/firmware/libproto_artiq/rpc_proto.rs index 84296a62c..afc98e101 100644 --- a/artiq/firmware/libproto_artiq/rpc_proto.rs +++ b/artiq/firmware/libproto_artiq/rpc_proto.rs @@ -204,21 +204,19 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) let mut data = (*ptr).elements; writer.write_u8(tag.as_u8())?; match tag { + // we cannot use NetworkEndian::from_slice_i32 as the data is not mutable, + // and that is not needed as the data is already in network endian Tag::Bool => { let slice = slice::from_raw_parts(data as *const u8, length); writer.write_all(slice)?; }, Tag::Int32 => { - let slice = slice::from_raw_parts(data as *const u32, length); - for v in slice.iter() { - writer.write_u32(*v)?; - } + let slice = slice::from_raw_parts(data as *const u8, length * 4); + writer.write_all(slice)?; }, Tag::Int64 | Tag::Float64 => { - let slice = slice::from_raw_parts(data as *const u64, length); - for v in slice.iter() { - writer.write_u64(*v)?; - } + let slice = slice::from_raw_parts(data as *const u8, length * 8); + writer.write_all(slice)?; }, _ => { for _ in 0..length { @@ -245,21 +243,19 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) let mut data = *buffer; writer.write_u8(elt_tag.as_u8())?; match elt_tag { + // we cannot use NetworkEndian::from_slice_i32 as the data is not mutable, + // and that is not needed as the data is already in network endian Tag::Bool => { let slice = slice::from_raw_parts(data as *const u8, length); writer.write_all(slice)?; }, Tag::Int32 => { - let slice = slice::from_raw_parts(data as *const u32, length); - for v in slice.iter() { - writer.write_u32(*v)?; - } + let slice = slice::from_raw_parts(data as *const u8, length * 4); + writer.write_all(slice)?; }, Tag::Int64 | Tag::Float64 => { - let slice = slice::from_raw_parts(data as *const u64, length); - for v in slice.iter() { - writer.write_u64(*v)?; - } + let slice = slice::from_raw_parts(data as *const u8, length * 8); + writer.write_all(slice)?; }, _ => { for _ in 0..length {