mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
string_cache nits.
This commit is contained in:
parent
cb01d37338
commit
f9f347e80f
1 changed files with 13 additions and 4 deletions
|
@ -89,6 +89,7 @@ impl WeakAtom {
|
||||||
Atom::from(self.as_ptr())
|
Atom::from(self.as_ptr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn get_hash(&self) -> u32 {
|
pub fn get_hash(&self) -> u32 {
|
||||||
self.0.mHash
|
self.0.mHash
|
||||||
}
|
}
|
||||||
|
@ -106,19 +107,22 @@ impl WeakAtom {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_str<F, Output>(&self, cb: F) -> Output
|
pub fn with_str<F, Output>(&self, cb: F) -> Output
|
||||||
where F: FnOnce(&str) -> Output {
|
where F: FnOnce(&str) -> Output
|
||||||
|
{
|
||||||
// FIXME(bholley): We should measure whether it makes more sense to
|
// FIXME(bholley): We should measure whether it makes more sense to
|
||||||
// cache the UTF-8 version in the Gecko atom table somehow.
|
// cache the UTF-8 version in the Gecko atom table somehow.
|
||||||
let owned = String::from_utf16(self.as_slice()).unwrap();
|
let owned = String::from_utf16(self.as_slice()).unwrap();
|
||||||
cb(&owned)
|
cb(&owned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn eq_str_ignore_ascii_case(&self, s: &str) -> bool {
|
pub fn eq_str_ignore_ascii_case(&self, s: &str) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
|
Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn to_string(&self) -> String {
|
pub fn to_string(&self) -> String {
|
||||||
String::from_utf16(self.as_slice()).unwrap()
|
String::from_utf16(self.as_slice()).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -135,7 +139,12 @@ impl Atom {
|
||||||
let atom = Atom(WeakAtom::new(ptr));
|
let atom = Atom(WeakAtom::new(ptr));
|
||||||
callback(&atom);
|
callback(&atom);
|
||||||
mem::forget(atom);
|
mem::forget(atom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
|
||||||
|
Atom(ptr as *mut WeakAtom)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BloomHash for Atom {
|
impl BloomHash for Atom {
|
||||||
|
@ -214,7 +223,7 @@ impl fmt::Debug for Atom {
|
||||||
|
|
||||||
impl fmt::Display for Atom {
|
impl fmt::Display for Atom {
|
||||||
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for c in char::decode_utf16(self.as_slice().iter().cloned()) {
|
for c in self.chars() {
|
||||||
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
|
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -224,7 +233,7 @@ impl fmt::Display for Atom {
|
||||||
impl<'a> From<&'a str> for Atom {
|
impl<'a> From<&'a str> for Atom {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(string: &str) -> Atom {
|
fn from(string: &str) -> Atom {
|
||||||
assert!(string.len() <= u32::max_value() as usize);
|
debug_assert!(string.len() <= u32::max_value() as usize);
|
||||||
unsafe {
|
unsafe {
|
||||||
Atom(WeakAtom::new(
|
Atom(WeakAtom::new(
|
||||||
Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32)
|
Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue