Skip to content

Cache a linear search for the #[staged_api] attribute. #27574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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