1
Fork 0
mirror of https://github.com/RGBCube/cstree synced 2025-07-27 09:07:44 +00:00

Change SyntaxNode's Hash and Eq to be based on pointer equality (#15)

This commit is contained in:
DQ 2021-02-10 22:23:31 +01:00 committed by GitHub
parent d67c18cc11
commit f6905735eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 9 deletions

View file

@ -5,7 +5,7 @@ use std::{
}; };
use fxhash::FxHasher32; use fxhash::FxHasher32;
use servo_arc::{Arc, HeaderSlice, HeaderWithLength, ThinArc}; use servo_arc::{Arc, HeaderWithLength, ThinArc};
use crate::{ use crate::{
green::{GreenElement, GreenElementRef, PackedGreenElement, SyntaxKind}, green::{GreenElement, GreenElementRef, PackedGreenElement, SyntaxKind},
@ -122,11 +122,6 @@ impl GreenNode {
inner: self.data.slice.iter(), inner: self.data.slice.iter(),
} }
} }
pub(crate) fn ptr(&self) -> *const u8 {
let r: &HeaderSlice<_, _> = &self.data;
r as *const _ as _
}
} }
impl Hash for GreenNode { impl Hash for GreenNode {

View file

@ -185,7 +185,7 @@ impl<L: Language, D, R> SyntaxNode<L, D, R> {
// Identity semantics for hash & eq // Identity semantics for hash & eq
impl<L: Language, D, R> PartialEq for SyntaxNode<L, D, R> { impl<L: Language, D, R> PartialEq for SyntaxNode<L, D, R> {
fn eq(&self, other: &SyntaxNode<L, D, R>) -> bool { fn eq(&self, other: &SyntaxNode<L, D, R>) -> bool {
self.green().ptr() == other.green().ptr() && self.text_range().start() == other.text_range().start() self.data == other.data
} }
} }
@ -193,8 +193,7 @@ impl<L: Language, D, R> Eq for SyntaxNode<L, D, R> {}
impl<L: Language, D, R> Hash for SyntaxNode<L, D, R> { impl<L: Language, D, R> Hash for SyntaxNode<L, D, R> {
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
ptr::hash(self.green().ptr(), state); ptr::hash(self.data, state);
self.text_range().start().hash(state);
} }
} }