]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #45602 - petrochenkov:ospan, r=michaelwoerister
authorkennytm <kennytm@gmail.com>
Wed, 1 Nov 2017 05:32:10 +0000 (13:32 +0800)
committerGitHub <noreply@github.com>
Wed, 1 Nov 2017 05:32:10 +0000 (13:32 +0800)
Optimize some span operations

Do not decode span data twice/thrice/etc unnecessarily.
Applied to stable hashing and all methods in `impl Span`.

Follow up to https://github.com/rust-lang/rust/pull/44646
r? @michaelwoerister

1  2 
src/librustc/ich/hcx.rs

diff --combined src/librustc/ich/hcx.rs
index f46540114f75058e324bebe9f1ee150b4740382a,5dc05fe336132a6783325f55f966b72a30d189c4..d24344e4e2166c9960ccbd3115700f186a1113d9
@@@ -206,10 -206,9 +206,10 @@@ impl<'gcx> StableHashingContext<'gcx> 
  
      pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self,
                                                      item_attrs: &[ast::Attribute],
 +                                                    is_const: bool,
                                                      f: F) {
          let prev_overflow_checks = self.overflow_checks_enabled;
 -        if attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") {
 +        if is_const || attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") {
              self.overflow_checks_enabled = true;
          }
          let prev_hash_node_ids = self.node_id_hashing_mode;
@@@ -371,17 -370,18 +371,18 @@@ impl<'gcx> HashStable<StableHashingCont
          // If this is not an empty or invalid span, we want to hash the last
          // position that belongs to it, as opposed to hashing the first
          // position past it.
-         let span_hi = if self.hi() > self.lo() {
+         let span = self.data();
+         let span_hi = if span.hi > span.lo {
              // We might end up in the middle of a multibyte character here,
              // but that's OK, since we are not trying to decode anything at
              // this position.
-             self.hi() - ::syntax_pos::BytePos(1)
+             span.hi - ::syntax_pos::BytePos(1)
          } else {
-             self.hi()
+             span.hi
          };
  
          {
-             let loc1 = hcx.codemap().byte_pos_to_line_and_col(self.lo());
+             let loc1 = hcx.codemap().byte_pos_to_line_and_col(span.lo);
              let loc1 = loc1.as_ref()
                             .map(|&(ref fm, line, col)| (&fm.name[..], line, col.to_usize()))
                             .unwrap_or(("???", 0, 0));
              }
          }
  
-         if self.ctxt() == SyntaxContext::empty() {
+         if span.ctxt == SyntaxContext::empty() {
              0u8.hash_stable(hcx, hasher);
          } else {
              1u8.hash_stable(hcx, hasher);