Skip to content

Commit ce02aa4

Browse files
Ariel Ben-Yehudaarielb1
authored andcommitted
don't mark_stable_position needlessly in tyencode
another 1% improvement in libcore size - also 1% in librustc 550076 liballoc-bb943c5a.rlib 1425150 liballoc_jemalloc-bb943c5a.rlib 10100 liballoc_system-bb943c5a.rlib 149372 libarena-bb943c5a.rlib 3964144 libcollections-bb943c5a.rlib 17744342 libcore-bb943c5a.rlib 197420 libflate-bb943c5a.rlib 241582 libfmt_macros-bb943c5a.rlib 550560 libgetopts-bb943c5a.rlib 219444 libgraphviz-bb943c5a.rlib 402668 liblibc-bb943c5a.rlib 187158 liblog-bb943c5a.rlib 704588 librand-bb943c5a.rlib 594522 librbml-bb943c5a.rlib 1392516 librustc_back-bb943c5a.rlib 38196500 librustc-bb943c5a.rlib 12826 librustc_bitflags-bb943c5a.rlib 2286918 librustc_borrowck-bb943c5a.rlib 561714 librustc_data_structures-bb943c5a.rlib 9356400 librustc_driver-bb943c5a.rlib 9378650 librustc_front-bb943c5a.rlib 1603680 librustc_lint-bb943c5a.rlib 79184908 librustc_llvm-bb943c5a.rlib 4746824 librustc_mir-bb943c5a.rlib 3532474 librustc_platform_intrinsics-bb943c5a.rlib 592664 librustc_privacy-bb943c5a.rlib 3114986 librustc_resolve-bb943c5a.rlib 14153174 librustc_trans-bb943c5a.rlib 11918356 librustc_typeck-bb943c5a.rlib 1669986 librustc_unicode-bb943c5a.rlib 15611582 librustdoc-bb943c5a.rlib 2836912 libserialize-bb943c5a.rlib 8549994 libstd-bb943c5a.rlib 30399156 libsyntax-bb943c5a.rlib 907058 libterm-bb943c5a.rlib
1 parent 7aed441 commit ce02aa4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![allow(non_camel_case_types)]
1515

1616
use std::cell::RefCell;
17+
use std::str;
1718
use std::io::prelude::*;
1819

1920
use middle::def_id::DefId;
@@ -173,12 +174,18 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
173174
return len;
174175
}
175176
let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len);
176-
if abbrev_len < len {
177-
// I.e. it's actually an abbreviation.
178-
cx.abbrevs.borrow_mut().insert(t, ty_abbrev {
179-
s: format!("#{:x}:{:x}#", pos, len)
180-
});
181-
}
177+
cx.abbrevs.borrow_mut().insert(t, ty_abbrev {
178+
s: if abbrev_len < len {
179+
format!("#{:x}:{:x}#", pos, len)
180+
} else {
181+
// if the abbreviation is longer than the real type,
182+
// don't use #-notation. However, insert it here so
183+
// other won't have to `mark_stable_position`
184+
str::from_utf8(
185+
&w.writer.get_ref()[pos as usize..end as usize]
186+
).unwrap().to_owned()
187+
}
188+
});
182189
}
183190

184191
fn enc_mutability(w: &mut Encoder, mt: hir::Mutability) {

0 commit comments

Comments
 (0)