mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Introduce nsStaticAtom.
It's a sub-class of nsAtom, useful for cases where you know you are dealing exclusively with static atoms. The nice thing about it is that you can use raw nsStaticAtom pointers instead of RefPtr<>. (In fact, the AddRef/Release implementations ensure that we'll crash if we use RefPtr<nsStaticAtom>.)
This commit is contained in:
parent
de7595f16f
commit
5866b820e0
5 changed files with 12525 additions and 12503 deletions
File diff suppressed because it is too large
Load diff
|
@ -2423,7 +2423,7 @@ pub mod root {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy)]
|
||||
pub struct Element_MappedAttributeEntry {
|
||||
pub attribute: *mut *mut root::nsAtom,
|
||||
pub attribute: *mut *mut root::nsStaticAtom,
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_Element_MappedAttributeEntry() {
|
||||
|
@ -14854,6 +14854,18 @@ pub mod root {
|
|||
"::" , stringify ! ( mStorageSize ) ));
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct nsStaticAtom {
|
||||
pub _base: root::nsAtom,
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_nsStaticAtom() {
|
||||
assert_eq!(::std::mem::size_of::<nsStaticAtom>() , 24usize , concat !
|
||||
( "Size of: " , stringify ! ( nsStaticAtom ) ));
|
||||
assert_eq! (::std::mem::align_of::<nsStaticAtom>() , 8usize , concat !
|
||||
( "Alignment of " , stringify ! ( nsStaticAtom ) ));
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy)]
|
||||
pub struct nsIPrincipal {
|
||||
pub _base: root::nsISerializable,
|
||||
|
@ -19305,7 +19317,7 @@ pub mod root {
|
|||
/// @param aCaseSensitive Whether to do a case-sensitive compare on the values.
|
||||
/// @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
|
||||
/// indicating the first value of aValues that matched
|
||||
pub type nsIContent_AttrValuesArray = *const *const root::nsAtom;
|
||||
pub type nsIContent_AttrValuesArray = *const *const root::nsStaticAtom;
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum nsIContent_FlattenedParentType {
|
||||
|
@ -31834,7 +31846,7 @@ pub mod root {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy)]
|
||||
pub struct nsMediaFeature {
|
||||
pub mName: *mut *mut root::nsAtom,
|
||||
pub mName: *mut *mut root::nsStaticAtom,
|
||||
pub mRangeType: root::nsMediaFeature_RangeType,
|
||||
pub mValueType: root::nsMediaFeature_ValueType,
|
||||
pub mReqFlags: u8,
|
||||
|
|
|
@ -638,7 +638,7 @@ impl Expression {
|
|||
};
|
||||
|
||||
let atom = Atom::from(feature_name);
|
||||
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName }) {
|
||||
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName as *mut _ }) {
|
||||
Some(f) => Ok((f, range)),
|
||||
None => Err(()),
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ PRELUDE = """
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/* Autogenerated file created by components/style/binding_tools/regen_atoms.py, DO NOT EDIT DIRECTLY */
|
||||
/* Autogenerated file created by components/style/gecko/binding_tools/regen_atoms.py, DO NOT EDIT DIRECTLY */
|
||||
"""[1:]
|
||||
|
||||
|
||||
|
@ -42,14 +42,14 @@ class GkAtomSource:
|
|||
PATTERN = re.compile('^(GK_ATOM)\((.+),\s*"(.*)"\)')
|
||||
FILE = "include/nsGkAtomList.h"
|
||||
CLASS = "nsGkAtoms"
|
||||
TYPE = "nsAtom"
|
||||
TYPE = "nsStaticAtom"
|
||||
|
||||
|
||||
class CSSPseudoElementsAtomSource:
|
||||
PATTERN = re.compile('^(CSS_PSEUDO_ELEMENT)\((.+),\s*"(.*)",')
|
||||
FILE = "include/nsCSSPseudoElementList.h"
|
||||
CLASS = "nsCSSPseudoElements"
|
||||
# NB: nsICSSPseudoElement is effectively the same as a nsAtom, but we need
|
||||
# NB: nsICSSPseudoElement is effectively the same as a nsStaticAtom, but we need
|
||||
# this for MSVC name mangling.
|
||||
TYPE = "nsICSSPseudoElement"
|
||||
|
||||
|
@ -163,14 +163,14 @@ class FileAvoidWrite(BytesIO):
|
|||
self.close()
|
||||
|
||||
|
||||
IMPORTS = ("\nuse gecko_bindings::structs::nsAtom;"
|
||||
IMPORTS = ("\nuse gecko_bindings::structs::nsStaticAtom;"
|
||||
"\nuse string_cache::Atom;\n\n")
|
||||
|
||||
ATOM_TEMPLATE = (" #[link_name = \"{link_name}\"]\n"
|
||||
" pub static {name}: *mut {type};")
|
||||
|
||||
UNSAFE_STATIC = ("#[inline(always)]\n"
|
||||
"pub unsafe fn atom_from_static(ptr: *mut nsAtom) -> Atom {\n"
|
||||
"pub unsafe fn atom_from_static(ptr: *mut nsStaticAtom) -> Atom {\n"
|
||||
" Atom::from_static(ptr)\n"
|
||||
"}\n\n")
|
||||
|
||||
|
@ -220,7 +220,7 @@ def write_atom_macro(atoms, file_name):
|
|||
f.write(IMPORTS)
|
||||
|
||||
for source in SOURCES:
|
||||
if source.TYPE != "nsAtom":
|
||||
if source.TYPE != "nsStaticAtom":
|
||||
f.write("pub enum {} {{}}\n\n".format(source.TYPE))
|
||||
|
||||
f.write(UNSAFE_STATIC)
|
||||
|
|
|
@ -10,7 +10,7 @@ use gecko_bindings::bindings::Gecko_AddRefAtom;
|
|||
use gecko_bindings::bindings::Gecko_Atomize;
|
||||
use gecko_bindings::bindings::Gecko_Atomize16;
|
||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind};
|
||||
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsStaticAtom};
|
||||
use nsstring::{nsAString, nsStr};
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use std::ascii::AsciiExt;
|
||||
|
@ -254,7 +254,7 @@ impl Atom {
|
|||
/// that way, now we have sugar for is_static, creating atoms using
|
||||
/// Atom::from should involve almost no overhead.
|
||||
#[inline]
|
||||
unsafe fn from_static(ptr: *mut nsAtom) -> Self {
|
||||
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!");
|
||||
|
@ -389,4 +389,14 @@ impl From<*mut nsAtom> for Atom {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<*mut nsStaticAtom> for Atom {
|
||||
#[inline]
|
||||
fn from(ptr: *mut nsStaticAtom) -> Atom {
|
||||
assert!(!ptr.is_null());
|
||||
unsafe {
|
||||
Atom::from_static(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
malloc_size_of_is_0!(Atom);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue