File tree Expand file tree Collapse file tree 1 file changed +32
-22
lines changed Expand file tree Collapse file tree 1 file changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -610,33 +610,43 @@ impl PyMemoryView {
610
610
if zelf. released . load ( ) {
611
611
return Ok ( false ) ;
612
612
}
613
+
613
614
let options_cmp = |a : & BufferOptions , b : & BufferOptions | -> bool {
614
615
a. len == b. len && a. itemsize == b. itemsize
615
616
} ;
616
- // TODO: fast pass for contiguous buffer
617
- match other. clone ( ) . downcast :: < PyMemoryView > ( ) {
618
- Ok ( other) => {
619
- if options_cmp ( & zelf. options , & other. options ) {
620
- let a = Self :: tolist ( zelf. clone ( ) , vm) ?;
621
- let b = Self :: tolist ( other, vm) ?;
622
- if vm. bool_eq ( a. as_object ( ) , b. as_object ( ) ) ? {
623
- return Ok ( true ) ;
624
- }
625
- }
617
+
618
+ let other = try_buffer_from_object ( vm, other) ?;
619
+
620
+ if !options_cmp ( & zelf. options , & other. get_options ( ) ) {
621
+ return Ok ( false ) ;
622
+ }
623
+
624
+ let a_guard;
625
+ let a_vec;
626
+ let a = match zelf. as_contiguous ( ) {
627
+ Some ( bytes) => {
628
+ a_guard = bytes;
629
+ & * a_guard
626
630
}
627
- Err ( other) => {
628
- if let Ok ( buffer) = try_buffer_from_object ( vm, & other) {
629
- let options = buffer. get_options ( ) ;
630
- // FIXME
631
- if options_cmp ( & zelf. options , & options)
632
- && ( * * ( Self :: tobytes ( zelf. clone ( ) , vm) ?) == * buffer. obj_bytes ( ) )
633
- {
634
- return Ok ( true ) ;
635
- }
636
- }
631
+ None => {
632
+ a_vec = zelf. to_contiguous ( ) ;
633
+ a_vec. as_slice ( )
637
634
}
638
- }
639
- Ok ( false )
635
+ } ;
636
+ let b_guard;
637
+ let b_vec;
638
+ let b = match other. as_contiguous ( ) {
639
+ Some ( bytes) => {
640
+ b_guard = bytes;
641
+ & * b_guard
642
+ }
643
+ None => {
644
+ b_vec = other. to_contiguous ( ) ;
645
+ b_vec. as_slice ( )
646
+ }
647
+ } ;
648
+
649
+ Ok ( a == b)
640
650
}
641
651
}
642
652
You can’t perform that action at this time.
0 commit comments