Skip to content

Commit 1181679

Browse files
committed
Auto merge of #27574 - brson:cache-staged-api, r=huonw
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
2 parents 68f7928 + fd142bb commit 1181679

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/librustc/metadata/creader.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ impl<'a> CrateReader<'a> {
261261
let loader::Library { dylib, rlib, metadata } = lib;
262262

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

265266
let cmeta = Rc::new( cstore::crate_metadata {
266267
name: name.to_string(),
@@ -270,6 +271,7 @@ impl<'a> CrateReader<'a> {
270271
cnum: cnum,
271272
codemap_import_info: RefCell::new(vec![]),
272273
span: span,
274+
staged_api: staged_api
273275
});
274276

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

288+
fn is_staged_api(&self, data: &[u8]) -> bool {
289+
let attrs = decoder::get_crate_attributes(data);
290+
for attr in &attrs {
291+
if &attr.name()[..] == "staged_api" {
292+
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
293+
}
294+
}
295+
296+
return false;
297+
}
298+
286299
fn resolve_crate(&mut self,
287300
root: &Option<CratePaths>,
288301
ident: &str,

src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rbml::reader;
2222
use std::rc::Rc;
2323
use syntax::ast;
2424
use syntax::attr;
25-
use syntax::attr::AttrMetaMethods;
2625
use syntax::diagnostic::expect;
2726

2827
use std::collections::hash_map::HashMap;
@@ -386,15 +385,7 @@ pub fn get_stability(cstore: &cstore::CStore,
386385
}
387386

388387
pub fn is_staged_api(cstore: &cstore::CStore, krate: ast::CrateNum) -> bool {
389-
let cdata = cstore.get_crate_data(krate);
390-
let attrs = decoder::get_crate_attributes(cdata.data());
391-
for attr in &attrs {
392-
if &attr.name()[..] == "staged_api" {
393-
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
394-
}
395-
}
396-
397-
return false;
388+
cstore.get_crate_data(krate).staged_api
398389
}
399390

400391
pub fn get_repr_attrs(cstore: &cstore::CStore, def: ast::DefId)

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct crate_metadata {
6363
pub cnum: ast::CrateNum,
6464
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
6565
pub span: codemap::Span,
66+
pub staged_api: bool
6667
}
6768

6869
#[derive(Copy, Debug, PartialEq, Clone)]

0 commit comments

Comments
 (0)