forked from mirrors/gecko-dev
		
	Bug 1400459 devirtualized nsIAtom so that it is no longer a subclass of nsISupports. This means that nsAtom is now a better name for it than nsIAtom. <!-- Please describe your changes on the following line: --> This is the Servo-side PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1400460. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1400460 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because testing is on the Gecko side. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 715fc9cea6ed4ad22772c6d20136eac66cfe275c --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : c3c028c08f605db5000531493cec20c3f427eeac
		
			
				
	
	
		
			99 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
/* This Source Code Form is subject to the terms of the Mozilla Public
 | 
						|
 * 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/. */
 | 
						|
 | 
						|
//! A type to represent a namespace.
 | 
						|
 | 
						|
use gecko_bindings::structs::nsAtom;
 | 
						|
use precomputed_hash::PrecomputedHash;
 | 
						|
use std::borrow::Borrow;
 | 
						|
use std::fmt;
 | 
						|
use std::ops::Deref;
 | 
						|
use string_cache::{Atom, WeakAtom};
 | 
						|
 | 
						|
#[macro_export]
 | 
						|
macro_rules! ns {
 | 
						|
    () => { $crate::string_cache::Namespace(atom!("")) };
 | 
						|
    ($s: tt) => { $crate::string_cache::Namespace(atom!($s)) };
 | 
						|
}
 | 
						|
 | 
						|
/// A Gecko namespace is just a wrapped atom.
 | 
						|
#[derive(Clone, Debug, Default, Eq, Hash, MallocSizeOf, PartialEq)]
 | 
						|
pub struct Namespace(pub Atom);
 | 
						|
 | 
						|
impl PrecomputedHash for Namespace {
 | 
						|
    #[inline]
 | 
						|
    fn precomputed_hash(&self) -> u32 {
 | 
						|
        self.0.precomputed_hash()
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
/// A Gecko WeakNamespace is a wrapped WeakAtom.
 | 
						|
#[derive(Hash)]
 | 
						|
pub struct WeakNamespace(WeakAtom);
 | 
						|
 | 
						|
impl Deref for WeakNamespace {
 | 
						|
    type Target = WeakAtom;
 | 
						|
 | 
						|
    #[inline]
 | 
						|
    fn deref(&self) -> &WeakAtom {
 | 
						|
        &self.0
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
impl Deref for Namespace {
 | 
						|
    type Target = WeakNamespace;
 | 
						|
 | 
						|
    #[inline]
 | 
						|
    fn deref(&self) -> &WeakNamespace {
 | 
						|
        let weak: *const WeakAtom = &*self.0;
 | 
						|
        unsafe {
 | 
						|
            &*(weak as *const WeakNamespace)
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl<'a> From<&'a str> for Namespace {
 | 
						|
    fn from(s: &'a str) -> Self {
 | 
						|
        Namespace(Atom::from(s))
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl fmt::Display for Namespace {
 | 
						|
    fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
 | 
						|
        self.0.fmt(w)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl Borrow<WeakNamespace> for Namespace {
 | 
						|
    #[inline]
 | 
						|
    fn borrow(&self) -> &WeakNamespace {
 | 
						|
        self
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl WeakNamespace {
 | 
						|
    /// Trivially construct a WeakNamespace.
 | 
						|
    #[inline]
 | 
						|
    pub unsafe fn new<'a>(atom: *mut nsAtom) -> &'a Self {
 | 
						|
        &*(atom as *const WeakNamespace)
 | 
						|
    }
 | 
						|
 | 
						|
    /// Clone this WeakNamespace to obtain a strong reference to the same
 | 
						|
    /// underlying namespace.
 | 
						|
    #[inline]
 | 
						|
    pub fn clone(&self) -> Namespace {
 | 
						|
        Namespace(self.0.clone())
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl Eq for WeakNamespace {}
 | 
						|
impl PartialEq for WeakNamespace {
 | 
						|
    #[inline]
 | 
						|
    fn eq(&self, other: &Self) -> bool {
 | 
						|
        let weak: *const WeakNamespace = self;
 | 
						|
        let other: *const WeakNamespace = other;
 | 
						|
        weak == other
 | 
						|
    }
 | 
						|
}
 |