From cbc36d5c5dd60fd328b2ddb5fc039b810c4105d3 Mon Sep 17 00:00:00 2001 From: Matt Kline Date: Tue, 21 Jul 2020 13:22:28 -0700 Subject: [PATCH] ser: Remove superfluous float.to_bits() call float.to_be_bytes() has the same effect as float.to_bits().to_be_bytes() They're presumably optimized to the same code, but the former's intent is a bit clearer. --- src/ser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ser.rs b/src/ser.rs index 7016dc34..5671a0b3 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -320,11 +320,11 @@ where self.writer.write_all(&[0xf9, 0x7e, 0x00]) } else if f32::from(f16::from_f32(value)) == value { let mut buf = [0xf9, 0, 0]; - (&mut buf[1..]).copy_from_slice(&f16::from_f32(value).to_bits().to_be_bytes()); + (&mut buf[1..]).copy_from_slice(&f16::from_f32(value).to_be_bytes()); self.writer.write_all(&buf) } else { let mut buf = [0xfa, 0, 0, 0, 0]; - (&mut buf[1..]).copy_from_slice(&value.to_bits().to_be_bytes()); + (&mut buf[1..]).copy_from_slice(&value.to_be_bytes()); self.writer.write_all(&buf) } .map_err(|e| e.into()) @@ -337,7 +337,7 @@ where self.serialize_f32(value as f32) } else { let mut buf = [0xfb, 0, 0, 0, 0, 0, 0, 0, 0]; - (&mut buf[1..]).copy_from_slice(&value.to_bits().to_be_bytes()); + (&mut buf[1..]).copy_from_slice(&value.to_be_bytes()); self.writer.write_all(&buf).map_err(|e| e.into()) } }