core: remove unneeded clones, allocate output buffer once at setup, and reuse same memory block

This commit is contained in:
decentclock
2022-11-08 13:15:32 -05:00
parent 8eae03336d
commit 409920a6f2

View File

@@ -88,6 +88,7 @@ pub fn make_event_loop(
// signing loop // signing loop
let dummy_peer = PubKey([0; 33]); let dummy_peer = PubKey([0; 33]);
let mut out_buffer: Vec<u8> = Vec::with_capacity(600);
while let Ok(event) = rx.recv() { while let Ok(event) = rx.recv() {
match event { match event {
Event::Connected => { Event::Connected => {
@@ -102,16 +103,18 @@ pub fn make_event_loop(
//led_tx.send(Status::ConnectingToMqtt).unwrap(); //led_tx.send(Status::ConnectingToMqtt).unwrap();
log::info!("GOT A Event::Disconnected msg!"); log::info!("GOT A Event::Disconnected msg!");
} }
Event::VlsMessage(ref msg_bytes) => { Event::VlsMessage(msg_bytes) => {
//led_tx.send(Status::Signing).unwrap(); //led_tx.send(Status::Signing).unwrap();
out_buffer.clear();
let _ret = match sphinx_signer::root::handle( let _ret = match sphinx_signer::root::handle(
&root_handler, &root_handler,
msg_bytes.clone(), msg_bytes,
dummy_peer.clone(), dummy_peer.clone(),
do_log, do_log,
&mut out_buffer,
) { ) {
Ok(b) => { Ok(()) => {
mqtt.publish(topics::VLS_RETURN, QOS, false, &b) mqtt.publish(topics::VLS_RETURN, QOS, false, &out_buffer)
.expect("could not publish VLS response"); .expect("could not publish VLS response");
} }
Err(e) => { Err(e) => {