aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/tree.rs
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2017-09-20 13:13:24 -0700
committerBobby Holley <bobbyholley@gmail.com>2017-09-21 15:25:38 -0700
commit438740b912b99ebacf3f5269b37be570cbdcaf7e (patch)
treefff091d5d28286a7627e4456ee97f71164315829 /components/selectors/tree.rs
parent29517d553e6c2fddc7e3cf0c0abef58c6d0f34aa (diff)
downloadservo-438740b912b99ebacf3f5269b37be570cbdcaf7e.tar.gz
servo-438740b912b99ebacf3f5269b37be570cbdcaf7e.zip
Implement an nth-index cache.
MozReview-Commit-ID: Ee0um3QXkxl
Diffstat (limited to 'components/selectors/tree.rs')
-rw-r--r--components/selectors/tree.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs
index 23238237b2f..958311ad0d8 100644
--- a/components/selectors/tree.rs
+++ b/components/selectors/tree.rs
@@ -8,11 +8,27 @@
use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus};
use parser::SelectorImpl;
+use servo_arc::NonZeroPtrMut;
use std::fmt::Debug;
-pub trait Element: Sized + Debug {
+/// Opaque representation of an Element, for identity comparisons. We use
+/// NonZeroPtrMut to get the NonZero optimization.
+#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+pub struct OpaqueElement(pub NonZeroPtrMut<()>);
+
+impl OpaqueElement {
+ /// Creates a new OpaqueElement from an arbitrarily-typed pointer.
+ pub fn new<T>(ptr: *const T) -> Self {
+ OpaqueElement(NonZeroPtrMut::new(ptr as *const () as *mut ()))
+ }
+}
+
+pub trait Element: Sized + Clone + Debug {
type Impl: SelectorImpl;
+ /// Converts self into an opaque representation.
+ fn opaque(&self) -> OpaqueElement;
+
fn parent_element(&self) -> Option<Self>;
/// The parent of a given pseudo-element, after matching a pseudo-element