diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2018-04-10 17:35:15 -0700 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2018-04-10 17:35:15 -0700 |
commit | c99bcdd4b8d4b4ac495d8a26eb8a4d2c710a2589 (patch) | |
tree | 26f5f8242e9de1b27166571c56ae03f22a22270d /components/style/gecko_string_cache | |
parent | f7ae1a37e3e004e156e5833551c486a7a5f189a0 (diff) | |
download | servo-c99bcdd4b8d4b4ac495d8a26eb8a4d2c710a2589.tar.gz servo-c99bcdd4b8d4b4ac495d8a26eb8a4d2c710a2589.zip |
Run rustfmt on selectors, servo_arc, and style.
This was generated with:
./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style
Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
Diffstat (limited to 'components/style/gecko_string_cache')
-rw-r--r-- | components/style/gecko_string_cache/mod.rs | 96 | ||||
-rw-r--r-- | components/style/gecko_string_cache/namespace.rs | 13 |
2 files changed, 56 insertions, 53 deletions
diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 86ad9ca478b..ead705fa231 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -14,7 +14,7 @@ use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsDynamicAtom, nsStaticAt use nsstring::{nsAString, nsStr}; use precomputed_hash::PrecomputedHash; use std::{mem, slice, str}; -use std::borrow::{Cow, Borrow}; +use std::borrow::{Borrow, Cow}; use std::char::{self, DecodeUtf16}; use std::fmt::{self, Write}; use std::hash::{Hash, Hasher}; @@ -33,7 +33,9 @@ pub mod namespace; pub use self::namespace::{Namespace, WeakNamespace}; macro_rules! local_name { - ($s: tt) => { atom!($s) } + ($s:tt) => { + atom!($s) + }; } /// A strong reference to a Gecko atom. @@ -55,9 +57,7 @@ impl Deref for Atom { #[inline] fn deref(&self) -> &WeakAtom { - unsafe { - &*self.0 - } + unsafe { &*self.0 } } } @@ -99,9 +99,7 @@ impl WeakAtom { /// Clone this atom, bumping the refcount if the atom is not static. #[inline] pub fn clone(&self) -> Atom { - unsafe { - Atom::from_raw(self.as_ptr()) - } + unsafe { Atom::from_raw(self.as_ptr()) } } /// Get the atom hash. @@ -114,16 +112,16 @@ impl WeakAtom { #[inline] pub fn as_slice(&self) -> &[u16] { let string = if self.is_static() { - let atom_ptr = self.as_ptr() as *const nsStaticAtom; - let string_offset = unsafe { (*atom_ptr).mStringOffset }; - let string_offset = -(string_offset as isize); - let u8_ptr = atom_ptr as *const u8; - // It is safe to use offset() here because both addresses are within - // the same struct, e.g. mozilla::detail::gGkAtoms. - unsafe { u8_ptr.offset(string_offset) as *const u16 } + let atom_ptr = self.as_ptr() as *const nsStaticAtom; + let string_offset = unsafe { (*atom_ptr).mStringOffset }; + let string_offset = -(string_offset as isize); + let u8_ptr = atom_ptr as *const u8; + // It is safe to use offset() here because both addresses are within + // the same struct, e.g. mozilla::detail::gGkAtoms. + unsafe { u8_ptr.offset(string_offset) as *const u16 } } else { - let atom_ptr = self.as_ptr() as *const nsDynamicAtom; - unsafe { (*(atom_ptr)).mString } + let atom_ptr = self.as_ptr() as *const nsDynamicAtom; + unsafe { (*(atom_ptr)).mString } }; unsafe { slice::from_raw_parts(string, self.len() as usize) } } @@ -139,7 +137,7 @@ impl WeakAtom { /// pretty slow. pub fn with_str<F, Output>(&self, cb: F) -> Output where - F: FnOnce(&str) -> Output + F: FnOnce(&str) -> Output, { let mut buffer: [u8; 64] = unsafe { mem::uninitialized() }; @@ -175,17 +173,13 @@ impl WeakAtom { /// Returns whether this atom is static. #[inline] pub fn is_static(&self) -> bool { - unsafe { - (*self.as_ptr()).mKind() == nsAtom_AtomKind::Static as u32 - } + unsafe { (*self.as_ptr()).mKind() == nsAtom_AtomKind::Static as u32 } } /// Returns the length of the atom string. #[inline] pub fn len(&self) -> u32 { - unsafe { - (*self.as_ptr()).mLength() - } + unsafe { (*self.as_ptr()).mLength() } } /// Returns whether this atom is the empty string. @@ -204,7 +198,10 @@ impl WeakAtom { /// Convert this atom to ASCII lower-case pub fn to_ascii_lowercase(&self) -> Atom { let slice = self.as_slice(); - match slice.iter().position(|&char16| (b'A' as u16) <= char16 && char16 <= (b'Z' as u16)) { + match slice + .iter() + .position(|&char16| (b'A' as u16) <= char16 && char16 <= (b'Z' as u16)) + { None => self.clone(), Some(i) => { let mut buffer: [u16; 64] = unsafe { mem::uninitialized() }; @@ -222,7 +219,7 @@ impl WeakAtom { } } Atom::from(&*mutable_slice) - } + }, } } @@ -245,8 +242,9 @@ impl WeakAtom { /// Return whether this atom is an ASCII-case-insensitive match for the given string pub fn eq_str_ignore_ascii_case(&self, other: &str) -> bool { - self.chars().map(|r| r.map(|c: char| c.to_ascii_lowercase())) - .eq(other.chars().map(|c: char| Ok(c.to_ascii_lowercase()))) + self.chars() + .map(|r| r.map(|c: char| c.to_ascii_lowercase())) + .eq(other.chars().map(|c: char| Ok(c.to_ascii_lowercase()))) } } @@ -267,7 +265,10 @@ impl fmt::Display for WeakAtom { impl Atom { /// Execute a callback with the atom represented by `ptr`. - pub unsafe fn with<F, R>(ptr: *mut nsAtom, callback: F) -> R where F: FnOnce(&Atom) -> R { + pub unsafe fn with<F, R>(ptr: *mut nsAtom, callback: F) -> R + where + F: FnOnce(&Atom) -> R, + { let atom = Atom(WeakAtom::new(ptr)); let ret = callback(&atom); mem::forget(atom); @@ -283,8 +284,10 @@ impl Atom { #[inline] pub unsafe fn from_static(ptr: *mut nsStaticAtom) -> Self { let atom = Atom(ptr as *mut WeakAtom); - debug_assert!(atom.is_static(), - "Called from_static for a non-static atom!"); + debug_assert!( + atom.is_static(), + "Called from_static for a non-static atom!" + ); atom } @@ -316,13 +319,19 @@ impl Atom { } impl Hash for Atom { - fn hash<H>(&self, state: &mut H) where H: Hasher { + fn hash<H>(&self, state: &mut H) + where + H: Hasher, + { state.write_u32(self.get_hash()); } } impl Hash for WeakAtom { - fn hash<H>(&self, state: &mut H) where H: Hasher { + fn hash<H>(&self, state: &mut H) + where + H: Hasher, + { state.write_u32(self.get_hash()); } } @@ -330,9 +339,7 @@ impl Hash for WeakAtom { impl Clone for Atom { #[inline(always)] fn clone(&self) -> Atom { - unsafe { - Atom::from_raw(self.as_ptr()) - } + unsafe { Atom::from_raw(self.as_ptr()) } } } @@ -362,9 +369,7 @@ impl fmt::Debug for Atom { impl fmt::Display for Atom { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { - unsafe { - (&*self.0).fmt(w) - } + unsafe { (&*self.0).fmt(w) } } } @@ -373,9 +378,10 @@ impl<'a> From<&'a str> for Atom { fn from(string: &str) -> Atom { debug_assert!(string.len() <= u32::max_value() as usize); unsafe { - Atom(WeakAtom::new( - Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32) - )) + Atom(WeakAtom::new(Gecko_Atomize( + string.as_ptr() as *const _, + string.len() as u32, + ))) } } } @@ -390,11 +396,7 @@ impl<'a> From<&'a [u16]> for Atom { impl<'a> From<&'a nsAString> for Atom { #[inline] fn from(string: &nsAString) -> Atom { - unsafe { - Atom(WeakAtom::new( - Gecko_Atomize16(string) - )) - } + unsafe { Atom(WeakAtom::new(Gecko_Atomize16(string))) } } } diff --git a/components/style/gecko_string_cache/namespace.rs b/components/style/gecko_string_cache/namespace.rs index 92288574e14..aad7b030267 100644 --- a/components/style/gecko_string_cache/namespace.rs +++ b/components/style/gecko_string_cache/namespace.rs @@ -13,8 +13,12 @@ use string_cache::{Atom, WeakAtom}; #[macro_export] macro_rules! ns { - () => { $crate::string_cache::Namespace(atom!("")) }; - ($s: tt) => { $crate::string_cache::Namespace(atom!($s)) }; + () => { + $crate::string_cache::Namespace(atom!("")) + }; + ($s:tt) => { + $crate::string_cache::Namespace(atom!($s)) + }; } /// A Gecko namespace is just a wrapped atom. @@ -41,16 +45,13 @@ impl Deref for WeakNamespace { } } - impl Deref for Namespace { type Target = WeakNamespace; #[inline] fn deref(&self) -> &WeakNamespace { let weak: *const WeakAtom = &*self.0; - unsafe { - &*(weak as *const WeakNamespace) - } + unsafe { &*(weak as *const WeakNamespace) } } } |