File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -5304,6 +5304,29 @@ impl<A, B> SlicePartialEq<B> for [A]
5304
5304
}
5305
5305
}
5306
5306
5307
+ // Use an equal-pointer optimization when types are `Eq`
5308
+ impl < A > SlicePartialEq < A > for [ A ]
5309
+ where A : PartialEq < A > + Eq
5310
+ {
5311
+ default fn equal ( & self , other : & [ A ] ) -> bool {
5312
+ if self . len ( ) != other. len ( ) {
5313
+ return false ;
5314
+ }
5315
+
5316
+ if self . as_ptr ( ) == other. as_ptr ( ) {
5317
+ return true ;
5318
+ }
5319
+
5320
+ for i in 0 ..self . len ( ) {
5321
+ if !self [ i] . eq ( & other[ i] ) {
5322
+ return false ;
5323
+ }
5324
+ }
5325
+
5326
+ true
5327
+ }
5328
+ }
5329
+
5307
5330
// Use memcmp for bytewise equality when the types allow
5308
5331
impl < A > SlicePartialEq < A > for [ A ]
5309
5332
where A : PartialEq < A > + BytewiseEquality
@@ -5409,7 +5432,7 @@ impl SliceOrd<u8> for [u8] {
5409
5432
#[ doc( hidden) ]
5410
5433
/// Trait implemented for types that can be compared for equality using
5411
5434
/// their bytewise representation
5412
- trait BytewiseEquality { }
5435
+ trait BytewiseEquality : Eq + Copy { }
5413
5436
5414
5437
macro_rules! impl_marker_for {
5415
5438
( $traitname: ident, $( $ty: ty) * ) => {
You can’t perform that action at this time.
0 commit comments