mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Statically allocate static atoms.
This commit is contained in:
parent
34f388229d
commit
77e3522507
2 changed files with 58 additions and 23 deletions
|
@ -17188,26 +17188,25 @@ pub mod root {
|
||||||
pub struct nsAtom {
|
pub struct nsAtom {
|
||||||
pub _bitfield_1: root::__BindgenBitfieldUnit<[u8; 4usize], u32>,
|
pub _bitfield_1: root::__BindgenBitfieldUnit<[u8; 4usize], u32>,
|
||||||
pub mHash: u32,
|
pub mHash: u32,
|
||||||
pub mString: *const u16,
|
|
||||||
}
|
}
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum nsAtom_AtomKind {
|
pub enum nsAtom_AtomKind {
|
||||||
DynamicAtom = 0,
|
Static = 0,
|
||||||
StaticAtom = 1,
|
DynamicNormal = 1,
|
||||||
HTML5Atom = 2,
|
DynamicHTML5 = 2,
|
||||||
}
|
}
|
||||||
pub type nsAtom_HasThreadSafeRefCnt = root::mozilla::TrueType;
|
pub type nsAtom_HasThreadSafeRefCnt = root::mozilla::TrueType;
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsAtom() {
|
fn bindgen_test_layout_nsAtom() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::size_of::<nsAtom>(),
|
::std::mem::size_of::<nsAtom>(),
|
||||||
16usize,
|
8usize,
|
||||||
concat!("Size of: ", stringify!(nsAtom))
|
concat!("Size of: ", stringify!(nsAtom))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::align_of::<nsAtom>(),
|
::std::mem::align_of::<nsAtom>(),
|
||||||
8usize,
|
4usize,
|
||||||
concat!("Alignment of ", stringify!(nsAtom))
|
concat!("Alignment of ", stringify!(nsAtom))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -17220,16 +17219,6 @@ pub mod root {
|
||||||
stringify!(mHash)
|
stringify!(mHash)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
|
||||||
unsafe { &(*(::std::ptr::null::<nsAtom>())).mString as *const _ as usize },
|
|
||||||
8usize,
|
|
||||||
concat!(
|
|
||||||
"Offset of field: ",
|
|
||||||
stringify!(nsAtom),
|
|
||||||
"::",
|
|
||||||
stringify!(mString)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
impl nsAtom {
|
impl nsAtom {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -17278,19 +17267,55 @@ pub mod root {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsStaticAtom {
|
pub struct nsStaticAtom {
|
||||||
pub _base: root::nsAtom,
|
pub _base: root::nsAtom,
|
||||||
|
pub mStringOffset: u32,
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsStaticAtom() {
|
fn bindgen_test_layout_nsStaticAtom() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::size_of::<nsStaticAtom>(),
|
::std::mem::size_of::<nsStaticAtom>(),
|
||||||
16usize,
|
12usize,
|
||||||
concat!("Size of: ", stringify!(nsStaticAtom))
|
concat!("Size of: ", stringify!(nsStaticAtom))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::align_of::<nsStaticAtom>(),
|
::std::mem::align_of::<nsStaticAtom>(),
|
||||||
8usize,
|
4usize,
|
||||||
concat!("Alignment of ", stringify!(nsStaticAtom))
|
concat!("Alignment of ", stringify!(nsStaticAtom))
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { &(*(::std::ptr::null::<nsStaticAtom>())).mStringOffset as *const _ as usize },
|
||||||
|
8usize,
|
||||||
|
concat!("Offset of field: ", stringify!(nsStaticAtom), "::", stringify!(mString))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct nsDynamicAtom {
|
||||||
|
pub _base: root::nsAtom,
|
||||||
|
pub mRefCnt: root::mozilla::ThreadSafeAutoRefCnt,
|
||||||
|
pub mString: *const u16,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_nsDynamicAtom() {
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::size_of::<nsDynamicAtom>(),
|
||||||
|
24usize,
|
||||||
|
concat!("Size of: ", stringify!(nsDynamicAtom))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::align_of::<nsDynamicAtom>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(nsDynamicAtom))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { &(*(::std::ptr::null::<nsDynamicAtom>())).mRefCnt as *const _ as usize },
|
||||||
|
8usize,
|
||||||
|
concat!("Offset of field: ", stringify!(nsDynamicAtom), "::", stringify!(mRefCnt))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { &(*(::std::ptr::null::<nsDynamicAtom>())).mString as *const _ as usize },
|
||||||
|
16usize,
|
||||||
|
concat!("Offset of field: ", stringify!(nsDynamicAtom), "::", stringify!(mString))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
pub type nsLoadFlags = u32;
|
pub type nsLoadFlags = u32;
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -10,7 +10,7 @@ use gecko_bindings::bindings::Gecko_AddRefAtom;
|
||||||
use gecko_bindings::bindings::Gecko_Atomize;
|
use gecko_bindings::bindings::Gecko_Atomize;
|
||||||
use gecko_bindings::bindings::Gecko_Atomize16;
|
use gecko_bindings::bindings::Gecko_Atomize16;
|
||||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||||
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsStaticAtom};
|
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsDynamicAtom, nsStaticAtom};
|
||||||
use nsstring::{nsAString, nsStr};
|
use nsstring::{nsAString, nsStr};
|
||||||
use precomputed_hash::PrecomputedHash;
|
use precomputed_hash::PrecomputedHash;
|
||||||
use std::{mem, slice, str};
|
use std::{mem, slice, str};
|
||||||
|
@ -113,9 +113,19 @@ impl WeakAtom {
|
||||||
/// Get the atom as a slice of utf-16 chars.
|
/// Get the atom as a slice of utf-16 chars.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_slice(&self) -> &[u16] {
|
pub fn as_slice(&self) -> &[u16] {
|
||||||
unsafe {
|
let string = if self.is_static() {
|
||||||
slice::from_raw_parts((*self.as_ptr()).mString, self.len() as usize)
|
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 }
|
||||||
|
};
|
||||||
|
unsafe { slice::from_raw_parts(string, self.len() as usize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: don't expose this, since it's slow, and easy to be misused.
|
// NOTE: don't expose this, since it's slow, and easy to be misused.
|
||||||
|
@ -166,7 +176,7 @@ impl WeakAtom {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_static(&self) -> bool {
|
pub fn is_static(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*self.as_ptr()).mKind() == nsAtom_AtomKind::StaticAtom as u32
|
(*self.as_ptr()).mKind() == nsAtom_AtomKind::Static as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue