about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2020-10-01 09:47:36 +0200
committeroli <github35764891676564198441@oli-obk.de>2020-11-04 09:58:59 +0000
commiteac309984fc102f15d5d1d3401d3f53b076f371d (patch)
treeceae2d5b47b67b7c40515cec34e9dce87a6db461
parent362123dd7577daa4cf737bc8f50146beedd3d944 (diff)
downloadrust-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.rs16
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 };