Skip to content

Commit eac3099

Browse files
committed
Encode ScalarInt::bytes as u128 instead of [u8; 16] to see if that caused the performance regression
1 parent 362123d commit eac3099

File tree

1 file changed

+15
-1
lines changed
  • compiler/rustc_middle/src/ty/consts

1 file changed

+15
-1
lines changed

compiler/rustc_middle/src/ty/consts/int.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::throw_ub;
33
use rustc_apfloat::ieee::{Double, Single};
44
use rustc_apfloat::Float;
55
use rustc_macros::HashStable;
6+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
67
use rustc_target::abi::{Size, TargetDataLayout};
78
use std::convert::{TryFrom, TryInto};
89
use std::fmt;
@@ -115,7 +116,7 @@ impl std::fmt::Debug for ConstInt {
115116

116117
// FIXME: reuse in `super::int::ConstInt` and `Scalar::Bits`
117118
/// The raw bytes of a simple value.
118-
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, TyEncodable, TyDecodable, Hash)]
119+
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
119120
#[derive(HashStable)]
120121
pub struct ScalarInt {
121122
/// The first `size` bytes of `data` are the value.
@@ -127,6 +128,19 @@ pub struct ScalarInt {
127128
size: u8,
128129
}
129130

131+
impl<S: Encoder> Encodable<S> for ScalarInt {
132+
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
133+
s.emit_u128(self.data())?;
134+
s.emit_u8(self.size)
135+
}
136+
}
137+
138+
impl<D: Decoder> Decodable<D> for ScalarInt {
139+
fn decode(d: &mut D) -> Result<ScalarInt, D::Error> {
140+
Ok(ScalarInt { bytes: d.read_u128()?.to_ne_bytes(), size: d.read_u8()? })
141+
}
142+
}
143+
130144
impl ScalarInt {
131145
pub const TRUE: ScalarInt = ScalarInt { bytes: 1_u128.to_ne_bytes(), size: 1 };
132146

0 commit comments

Comments
 (0)