Skip to content

Commit

Permalink
Cache a linear search for the #[staged_api] attribute.
Browse files Browse the repository at this point in the history
This search happens a lot! Locally, compiling hyper sees the following improvements:

before

real    0m30.843s
user    0m51.644s
sys     0m2.128s

real    0m30.164s
user    0m53.320s
sys     0m2.208s

after

real    0m28.438s
user    0m51.076s
sys     0m2.276s

real    0m28.612s
user    0m51.560s
sys     0m2.192s
  • Loading branch information
brson committed Aug 6, 2015
1 parent 430a9fd commit fd142bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl<'a> CrateReader<'a> {
let loader::Library { dylib, rlib, metadata } = lib;

let cnum_map = self.resolve_crate_deps(root, metadata.as_slice(), span);
let staged_api = self.is_staged_api(metadata.as_slice());

let cmeta = Rc::new( cstore::crate_metadata {
name: name.to_string(),
Expand All @@ -270,6 +271,7 @@ impl<'a> CrateReader<'a> {
cnum: cnum,
codemap_import_info: RefCell::new(vec![]),
span: span,
staged_api: staged_api
});

let source = cstore::CrateSource {
Expand All @@ -283,6 +285,17 @@ impl<'a> CrateReader<'a> {
(cnum, cmeta, source)
}

fn is_staged_api(&self, data: &[u8]) -> bool {
let attrs = decoder::get_crate_attributes(data);
for attr in &attrs {
if &attr.name()[..] == "staged_api" {
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
}
}

return false;
}

fn resolve_crate(&mut self,
root: &Option<CratePaths>,
ident: &str,
Expand Down
11 changes: 1 addition & 10 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rbml::reader;
use std::rc::Rc;
use syntax::ast;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::diagnostic::expect;

use std::collections::hash_map::HashMap;
Expand Down Expand Up @@ -386,15 +385,7 @@ pub fn get_stability(cstore: &cstore::CStore,
}

pub fn is_staged_api(cstore: &cstore::CStore, krate: ast::CrateNum) -> bool {
let cdata = cstore.get_crate_data(krate);
let attrs = decoder::get_crate_attributes(cdata.data());
for attr in &attrs {
if &attr.name()[..] == "staged_api" {
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
}
}

return false;
cstore.get_crate_data(krate).staged_api
}

pub fn get_repr_attrs(cstore: &cstore::CStore, def: ast::DefId)
Expand Down
1 change: 1 addition & 0 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct crate_metadata {
pub cnum: ast::CrateNum,
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
pub span: codemap::Span,
pub staged_api: bool
}

#[derive(Copy, Debug, PartialEq, Clone)]
Expand Down

0 comments on commit fd142bb

Please sign in to comment.