mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Use upstream lazy_static!() macro through Cargo
... instead of having our own copy. https://github.com/Kimundi/lazy-static.rs
This commit is contained in:
parent
af96e8e409
commit
a40b94d7f9
6 changed files with 7 additions and 66 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -457,6 +457,7 @@ dependencies = [
|
|||
"cssparser 0.1.0 (git+https://github.com/servo/rust-cssparser#fa619d4ffd6920dee6e7ea79f42d9cceb9015407)",
|
||||
"encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#35f0d70f65f73ba16f296f9ec675eddee661ba79)",
|
||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
||||
"lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)",
|
||||
"macros 0.0.1",
|
||||
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
||||
"util 0.0.1",
|
||||
|
|
|
@ -184,66 +184,3 @@ macro_rules! bitfield(
|
|||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! lazy_init(
|
||||
($(static ref $N:ident : $T:ty = $e:expr;)*) => (
|
||||
$(
|
||||
#[allow(non_camel_case_types)]
|
||||
struct $N {__unit__: ()}
|
||||
static $N: $N = $N {__unit__: ()};
|
||||
impl Deref<$T> for $N {
|
||||
fn deref<'a>(&'a self) -> &'a $T {
|
||||
unsafe {
|
||||
static mut s: *const $T = 0 as *const $T;
|
||||
static mut ONCE: ::sync::one::Once = ::sync::one::ONCE_INIT;
|
||||
ONCE.doit(|| {
|
||||
s = ::std::mem::transmute::<Box<$T>, *const $T>(box () ($e));
|
||||
});
|
||||
&*s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)*
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::hashmap::HashMap;
|
||||
lazy_init! {
|
||||
static ref NUMBER: uint = times_two(3);
|
||||
static ref VEC: [Box<uint>, ..3] = [box 1, box 2, box 3];
|
||||
static ref OWNED_STRING: String = "hello".to_string();
|
||||
static ref HASHMAP: HashMap<uint, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert(0u, "abc");
|
||||
m.insert(1, "def");
|
||||
m.insert(2, "ghi");
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
fn times_two(n: uint) -> uint {
|
||||
n * 2
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
assert_eq!(*OWNED_STRING, "hello".to_string());
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert!(HASHMAP.find(&1).is_some());
|
||||
assert!(HASHMAP.find(&3).is_none());
|
||||
assert_eq!(VEC.as_slice(), &[box 1, box 2, box 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat() {
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert_eq!(*NUMBER, 6);
|
||||
assert_eq!(*NUMBER, 6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,3 +29,5 @@ git = "https://github.com/servo/rust-cssparser"
|
|||
[dependencies.encoding]
|
||||
git = "https://github.com/lifthrasiir/rust-encoding"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
git = "https://github.com/Kimundi/lazy-static.rs"
|
||||
|
|
|
@ -22,9 +22,9 @@ extern crate url;
|
|||
|
||||
extern crate cssparser;
|
||||
extern crate encoding;
|
||||
|
||||
#[phase(plugin)]
|
||||
extern crate "macros" as servo_macros;
|
||||
extern crate lazy_static;
|
||||
|
||||
extern crate "util" as servo_util;
|
||||
|
||||
|
||||
|
|
|
@ -1822,7 +1822,7 @@ fn get_writing_mode(inheritedbox_style: &style_structs::InheritedBox) -> Writing
|
|||
|
||||
|
||||
/// The initial values for all style structs as defined by the specification.
|
||||
lazy_init! {
|
||||
lazy_static! {
|
||||
static ref INITIAL_VALUES: ComputedValues = ComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
|
||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -483,6 +483,7 @@ dependencies = [
|
|||
"cssparser 0.1.0 (git+https://github.com/servo/rust-cssparser#fa619d4ffd6920dee6e7ea79f42d9cceb9015407)",
|
||||
"encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#35f0d70f65f73ba16f296f9ec675eddee661ba79)",
|
||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
||||
"lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)",
|
||||
"macros 0.0.1",
|
||||
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
||||
"util 0.0.1",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue