diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-10-01 09:47:36 +0200 |
|---|---|---|
| committer | oli <github35764891676564198441@oli-obk.de> | 2020-11-04 09:58:59 +0000 |
| commit | eac309984fc102f15d5d1d3401d3f53b076f371d (patch) | |
| tree | ceae2d5b47b67b7c40515cec34e9dce87a6db461 | |
| parent | 362123dd7577daa4cf737bc8f50146beedd3d944 (diff) | |
| download | rust-eac309984fc102f15d5d1d3401d3f53b076f371d.tar.gz rust-eac309984fc102f15d5d1d3401d3f53b076f371d.zip | |
Encode `ScalarInt::bytes` as `u128` instead of `[u8; 16]` to see if that caused the performance regression
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts/int.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 807005b4595..cd6c86916d0 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -3,6 +3,7 @@ use crate::throw_ub; use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; use rustc_macros::HashStable; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_target::abi::{Size, TargetDataLayout}; use std::convert::{TryFrom, TryInto}; use std::fmt; @@ -115,7 +116,7 @@ impl std::fmt::Debug for ConstInt { // FIXME: reuse in `super::int::ConstInt` and `Scalar::Bits` /// The raw bytes of a simple value. -#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, TyEncodable, TyDecodable, Hash)] +#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(HashStable)] pub struct ScalarInt { /// The first `size` bytes of `data` are the value. @@ -127,6 +128,19 @@ pub struct ScalarInt { size: u8, } +impl<S: Encoder> Encodable<S> for ScalarInt { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_u128(self.data())?; + s.emit_u8(self.size) + } +} + +impl<D: Decoder> Decodable<D> for ScalarInt { + fn decode(d: &mut D) -> Result<ScalarInt, D::Error> { + Ok(ScalarInt { bytes: d.read_u128()?.to_ne_bytes(), size: d.read_u8()? }) + } +} + impl ScalarInt { pub const TRUE: ScalarInt = ScalarInt { bytes: 1_u128.to_ne_bytes(), size: 1 }; |
