Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#![feature(optin_builtin_traits)]
#![allow(unused_attributes)]
#![feature(specialization)]
#![feature(macro_lifetime_matcher)]

use std::borrow::Cow;
use std::cell::Cell;
Expand Down
65 changes: 40 additions & 25 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use GLOBALS;
use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::collections::HashMap;
use std::fmt;
use std::ops::Deref;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just efficiency, I guess?)


#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Ident {
Expand Down Expand Up @@ -154,9 +155,10 @@ impl Decodable for Symbol {
}
}

impl<T: ::std::ops::Deref<Target=str>> PartialEq<T> for Symbol {
fn eq(&self, other: &T) -> bool {
self.as_str() == other.deref()
impl PartialEq<InternedString> for Symbol {
fn eq(&self, other: &InternedString) -> bool {
// Compare pointers
self.as_str() == *other
}
}

Expand Down Expand Up @@ -360,36 +362,49 @@ impl<U: ?Sized> ::std::convert::AsRef<U> for InternedString where str: ::std::co
}
}

impl<T: ::std::ops::Deref<Target = str>> ::std::cmp::PartialEq<T> for InternedString {
fn eq(&self, other: &T) -> bool {
self.string == other.deref()
}
}

impl ::std::cmp::PartialEq<InternedString> for str {
impl ::std::cmp::PartialEq<InternedString> for InternedString {
fn eq(&self, other: &InternedString) -> bool {
self == other.string
self.as_ptr() == other.as_ptr()
}
}

impl<'a> ::std::cmp::PartialEq<InternedString> for &'a str {
fn eq(&self, other: &InternedString) -> bool {
*self == other.string
}
}
macro_rules! impl_partial_eq_for_symbol_and_interned_string {
($(impl $(<$impl_lt:lifetime>)* for $t:ty;)*) => ($(
impl<$($impl_lt),*> ::std::cmp::PartialEq<$t> for InternedString {
fn eq(&self, other: &$t) -> bool {
let s: &str = other.deref();
self.string == s
}
}

impl ::std::cmp::PartialEq<InternedString> for String {
fn eq(&self, other: &InternedString) -> bool {
self == other.string
}
}
impl<$($impl_lt),*> ::std::cmp::PartialEq<InternedString> for $t {
fn eq(&self, other: &InternedString) -> bool {
let s: &str = self.deref();
s == other.string
}
}

impl<'a> ::std::cmp::PartialEq<InternedString> for &'a String {
fn eq(&self, other: &InternedString) -> bool {
*self == other.string
}
impl<$($impl_lt),*> ::std::cmp::PartialEq<$t> for Symbol {
fn eq(&self, other: &$t) -> bool {
self.as_str() == *other
}
}

impl<$($impl_lt),*> ::std::cmp::PartialEq<Symbol> for $t {
fn eq(&self, other: &Symbol) -> bool {
*self == other.as_str()
}
}
)*)
}

impl_partial_eq_for_symbol_and_interned_string!(
impl for str;
impl for String;
impl<'a> for &'a str;
impl<'a> for &'a String;
);

impl !Send for InternedString { }

impl ::std::ops::Deref for InternedString {
Expand Down