Closed whyCPPgofast closed 2 years ago
Hey I was wondering if my code is inefficient and if there is a way of reusing the GzDecoder instead of calling ::new() every iteration.
::new()
loop { let bytes = client.read_message().into_bytes().unwrap(); let mut msg = String::new(); GzDecoder::new(bytes).read_to_string(&mut msg).unwrap(); println("{}", msg); }
I tried instatiating a decoder outside of the loop but ran into multiple errors.
Something like this:
let decoder = GzDecoder::new(); loop { let bytes = client.read_message().into_bytes().unwrap(); let mut msg = String::new(); decoder.read_to_string(&mut msg).unwrap(); println("{}", msg); }
I'd recommend profiling to see if it's sufficient for your use case. If it's not then helper methods can be added to GzDecoder to reuse it.
GzDecoder
Hey I was wondering if my code is inefficient and if there is a way of reusing the GzDecoder instead of calling
::new()
every iteration.I tried instatiating a decoder outside of the loop but ran into multiple errors.
Something like this: