@@ -18,6 +18,7 @@ use GLOBALS;
18
18
use serialize:: { Decodable , Decoder , Encodable , Encoder } ;
19
19
use std:: collections:: HashMap ;
20
20
use std:: fmt;
21
+ use std:: ops:: Deref ;
21
22
22
23
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
23
24
pub struct Ident {
@@ -154,9 +155,10 @@ impl Decodable for Symbol {
154
155
}
155
156
}
156
157
157
- impl < T : :: std:: ops:: Deref < Target =str > > PartialEq < T > for Symbol {
158
- fn eq ( & self , other : & T ) -> bool {
159
- self . as_str ( ) == other. deref ( )
158
+ impl PartialEq < InternedString > for Symbol {
159
+ fn eq ( & self , other : & InternedString ) -> bool {
160
+ // Compare pointers
161
+ self . as_str ( ) == * other
160
162
}
161
163
}
162
164
@@ -360,36 +362,49 @@ impl<U: ?Sized> ::std::convert::AsRef<U> for InternedString where str: ::std::co
360
362
}
361
363
}
362
364
363
- impl < T : :: std:: ops:: Deref < Target = str > > :: std:: cmp:: PartialEq < T > for InternedString {
364
- fn eq ( & self , other : & T ) -> bool {
365
- self . string == other. deref ( )
366
- }
367
- }
368
-
369
- impl :: std:: cmp:: PartialEq < InternedString > for str {
365
+ impl :: std:: cmp:: PartialEq < InternedString > for InternedString {
370
366
fn eq ( & self , other : & InternedString ) -> bool {
371
- self == other. string
367
+ self . as_ptr ( ) == other. as_ptr ( )
372
368
}
373
369
}
374
370
375
- impl < ' a > :: std:: cmp:: PartialEq < InternedString > for & ' a str {
376
- fn eq ( & self , other : & InternedString ) -> bool {
377
- * self == other. string
378
- }
379
- }
371
+ macro_rules! impl_partial_eq_for_symbol_and_interned_string {
372
+ ( $( impl $( <$impl_lt: lifetime>) * for $t: ty; ) * ) => ( $(
373
+ impl <$( $impl_lt) ,* > :: std:: cmp:: PartialEq <$t> for InternedString {
374
+ fn eq( & self , other: & $t) -> bool {
375
+ let s: & str = other. deref( ) ;
376
+ self . string == s
377
+ }
378
+ }
380
379
381
- impl :: std:: cmp:: PartialEq < InternedString > for String {
382
- fn eq ( & self , other : & InternedString ) -> bool {
383
- self == other. string
384
- }
385
- }
380
+ impl <$( $impl_lt) ,* > :: std:: cmp:: PartialEq <InternedString > for $t {
381
+ fn eq( & self , other: & InternedString ) -> bool {
382
+ let s: & str = self . deref( ) ;
383
+ s == other. string
384
+ }
385
+ }
386
386
387
- impl < ' a > :: std:: cmp:: PartialEq < InternedString > for & ' a String {
388
- fn eq ( & self , other : & InternedString ) -> bool {
389
- * self == other. string
390
- }
387
+ impl <$( $impl_lt) ,* > :: std:: cmp:: PartialEq <$t> for Symbol {
388
+ fn eq( & self , other: & $t) -> bool {
389
+ self . as_str( ) == * other
390
+ }
391
+ }
392
+
393
+ impl <$( $impl_lt) ,* > :: std:: cmp:: PartialEq <Symbol > for $t {
394
+ fn eq( & self , other: & Symbol ) -> bool {
395
+ * self == other. as_str( )
396
+ }
397
+ }
398
+ ) * )
391
399
}
392
400
401
+ impl_partial_eq_for_symbol_and_interned_string ! (
402
+ impl for str ;
403
+ impl for String ;
404
+ impl <' a> for & ' a str ;
405
+ impl <' a> for & ' a String ;
406
+ ) ;
407
+
393
408
impl !Send for InternedString { }
394
409
395
410
impl :: std:: ops:: Deref for InternedString {
0 commit comments