From ce02aa494283fa238aa9ce435e8e82a52088fd20 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Thu, 17 Sep 2015 20:50:27 +0300 Subject: [PATCH] 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 --- src/librustc/metadata/tyencode.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 3176f5c9cc4..489d213879c 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -14,6 +14,7 @@ #![allow(non_camel_case_types)] use std::cell::RefCell; +use std::str; use std::io::prelude::*; 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>) { return len; } let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len); - if abbrev_len < len { - // I.e. it's actually an abbreviation. - cx.abbrevs.borrow_mut().insert(t, ty_abbrev { - s: format!("#{:x}:{:x}#", pos, len) - }); - } + cx.abbrevs.borrow_mut().insert(t, ty_abbrev { + s: if abbrev_len < len { + format!("#{:x}:{:x}#", pos, len) + } else { + // if the abbreviation is longer than the real type, + // don't use #-notation. However, insert it here so + // other won't have to `mark_stable_position` + str::from_utf8( + &w.writer.get_ref()[pos as usize..end as usize] + ).unwrap().to_owned() + } + }); } fn enc_mutability(w: &mut Encoder, mt: hir::Mutability) {