From 8b6c5988b53a662318c3d2214eb3c4abc97b7750 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 20 Sep 2017 18:38:20 -0700 Subject: [PATCH] Hoist the LRU cache into its own crate to share it with selectors. --- Cargo.lock | 9 +++++++++ components/lru_cache/Cargo.toml | 13 +++++++++++++ components/{style/cache.rs => lru_cache/lib.rs} | 2 ++ components/selectors/Cargo.toml | 1 + components/selectors/lib.rs | 1 + components/style/Cargo.toml | 1 + components/style/context.rs | 2 +- components/style/lib.rs | 2 +- components/style/sharing/mod.rs | 2 +- 9 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 components/lru_cache/Cargo.toml rename components/{style/cache.rs => lru_cache/lib.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index 0d771ea371d..aec56362afe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1704,6 +1704,13 @@ name = "log" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lru_cache" +version = "0.0.1" +dependencies = [ + "arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lzw" version = "0.10.0" @@ -2712,6 +2719,7 @@ dependencies = [ "cssparser 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lru_cache 0.0.1", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.0.1", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3128,6 +3136,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lru_cache 0.0.1", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.0.1", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/lru_cache/Cargo.toml b/components/lru_cache/Cargo.toml new file mode 100644 index 00000000000..7e8f0693f7e --- /dev/null +++ b/components/lru_cache/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "lru_cache" +version = "0.0.1" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" +publish = false # We should publish this at some point + +[lib] +name = "lru_cache" +path = "lib.rs" + +[dependencies] +arrayvec = "0.3.20" diff --git a/components/style/cache.rs b/components/lru_cache/lib.rs similarity index 99% rename from components/style/cache.rs rename to components/lru_cache/lib.rs index d43a4a71955..ffffca9a579 100644 --- a/components/style/cache.rs +++ b/components/lru_cache/lib.rs @@ -4,6 +4,8 @@ //! A simple LRU cache. +extern crate arrayvec; + use arrayvec::{Array, ArrayVec}; /// A LRU cache using a statically-sized array for storage. diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 0fa01f994b3..da9adffde93 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -30,6 +30,7 @@ log = "0.3" fnv = "1.0" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = { path = "../malloc_size_of_derive" } +lru_cache = { path = "../lru_cache" } phf = "0.7.18" precomputed-hash = "0.1" servo_arc = { path = "../servo_arc" } diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index 870e1c3ca0c..2184dfc64e7 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -10,6 +10,7 @@ #[macro_use] extern crate log; #[macro_use] extern crate matches; extern crate fnv; +extern crate lru_cache; extern crate malloc_size_of; #[macro_use] extern crate malloc_size_of_derive; extern crate phf; diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 44062782184..d88ae34cd78 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -48,6 +48,7 @@ itertools = "0.5" itoa = "0.3" html5ever = {version = "0.19", optional = true} lazy_static = "0.2" +lru_cache = { path = "../lru_cache" } log = "0.3" malloc_size_of = { path = "../malloc_size_of", optional=true } malloc_size_of_derive = { path = "../malloc_size_of_derive", optional=true } diff --git a/components/style/context.rs b/components/style/context.rs index e88382e4cd4..390ac09a5c4 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -8,13 +8,13 @@ #[cfg(feature = "servo")] use animation::PropertyAnimation; use app_units::Au; use bloom::StyleBloom; -use cache::{Entry, LRUCache}; use data::{EagerPseudoStyles, ElementData}; use dom::{OpaqueNode, TNode, TElement, SendElement}; use euclid::ScaleFactor; use euclid::Size2D; use fnv::FnvHashMap; use font_metrics::FontMetricsProvider; +use lru_cache::{Entry, LRUCache}; #[cfg(feature = "gecko")] use gecko_bindings::structs; use parallel::{STACK_SAFETY_MARGIN_KB, STYLE_THREAD_STACK_SIZE_KB}; #[cfg(feature = "servo")] use parking_lot::RwLock; diff --git a/components/style/lib.rs b/components/style/lib.rs index 5ae4f1633a6..af150229f79 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -59,6 +59,7 @@ extern crate itoa; extern crate lazy_static; #[macro_use] extern crate log; +extern crate lru_cache; #[cfg(feature = "gecko")] #[macro_use] extern crate malloc_size_of; #[cfg(feature = "gecko")] #[macro_use] extern crate malloc_size_of_derive; #[allow(unused_extern_crates)] @@ -102,7 +103,6 @@ pub mod applicable_declarations; #[cfg(feature = "servo")] pub mod attr; pub mod bezier; pub mod bloom; -pub mod cache; pub mod context; pub mod counter_style; pub mod custom_properties; diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index 72214d79f90..0c652265c0e 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -68,9 +68,9 @@ use Atom; use applicable_declarations::ApplicableDeclarationBlock; use atomic_refcell::{AtomicRefCell, AtomicRefMut}; use bloom::StyleBloom; -use cache::{LRUCache, Entry}; use context::{SelectorFlagsMap, SharedStyleContext, StyleContext}; use dom::{TElement, SendElement}; +use lru_cache::{LRUCache, Entry}; use matching::MatchMethods; use owning_ref::OwningHandle; use properties::ComputedValues;