diff options
author | Cameron McCormack <cam@mcc.id.au> | 2019-10-03 15:02:47 +1000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-10-08 01:40:07 +0200 |
commit | fa3f7896da851e7a5c049c8b027780a2e669b432 (patch) | |
tree | 7fda7e005a4a9293adc36273e9d32925ec2618cb | |
parent | 49af9b76b8b95fad6697c3fe265f597215edae6e (diff) |
Cache the result of Item::path_for_whitelisting.
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/ir/context.rs | 2 | ||||
-rw-r--r-- | src/ir/item.rs | 11 | ||||
-rw-r--r-- | src/lib.rs | 1 |
5 files changed, 19 insertions, 3 deletions
@@ -37,6 +37,7 @@ dependencies = [ "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -135,6 +136,11 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "libc" version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -334,6 +340,7 @@ dependencies = [ "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" @@ -50,6 +50,7 @@ cfg-if = "0.1.0" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } clang-sys = { version = "0.28.0", features = ["runtime", "clang_6_0"] } +lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } diff --git a/src/ir/context.rs b/src/ir/context.rs index 292383f5..6158d02d 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2327,7 +2327,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } let mut prefix_path = - parent.path_for_whitelisting(self); + parent.path_for_whitelisting(self).clone(); enum_.variants().iter().any(|variant| { prefix_path.push(variant.name().into()); let name = prefix_path[1..].join("::"); diff --git a/src/ir/item.rs b/src/ir/item.rs index 1e12424e..267522a5 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -20,6 +20,7 @@ use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; use clang; use clang_sys; +use lazycell::LazyCell; use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; use regex; use std::cell::{Cell, RefCell}; @@ -398,6 +399,10 @@ pub struct Item { /// considerably faster in those cases. canonical_name_cache: RefCell<Option<String>>, + /// The path to use for whitelisting and other name-based checks, as + /// returned by `path_for_whitelisting`, lazily constructed. + path_for_whitelisting: LazyCell<Vec<String>>, + /// A doc comment over the item, if any. comment: Option<String>, /// Annotations extracted from the doc comment, or the default ones @@ -434,6 +439,7 @@ impl Item { local_id: Cell::new(None), next_child_local_id: Cell::new(1), canonical_name_cache: RefCell::new(None), + path_for_whitelisting: LazyCell::new(), parent_id: parent_id, comment: comment, annotations: annotations.unwrap_or_default(), @@ -972,8 +978,9 @@ impl Item { /// Returns the path we should use for whitelisting / blacklisting, which /// doesn't include user-mangling. - pub fn path_for_whitelisting(&self, ctx: &BindgenContext) -> Vec<String> { - self.compute_path(ctx, UserMangled::No) + pub fn path_for_whitelisting(&self, ctx: &BindgenContext) -> &Vec<String> { + self.path_for_whitelisting + .borrow_with(|| self.compute_path(ctx, UserMangled::No)) } fn compute_path( @@ -24,6 +24,7 @@ extern crate cexpr; extern crate cfg_if; extern crate clang_sys; extern crate rustc_hash; +extern crate lazycell; #[macro_use] extern crate lazy_static; extern crate peeking_take_while; |