File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1
- use std :: cell :: Cell ;
1
+ use crossbeam_utils :: atomic :: AtomicCell ;
2
2
use std:: fmt;
3
3
4
4
use super :: objiter;
@@ -160,7 +160,7 @@ impl PyTuple {
160
160
#[ pymethod( name = "__iter__" ) ]
161
161
fn iter ( zelf : PyRef < Self > ) -> PyTupleIterator {
162
162
PyTupleIterator {
163
- position : Cell :: new ( 0 ) ,
163
+ position : AtomicCell :: new ( 0 ) ,
164
164
tuple : zelf,
165
165
}
166
166
}
@@ -243,7 +243,7 @@ impl PyTuple {
243
243
#[ pyclass]
244
244
#[ derive( Debug ) ]
245
245
pub struct PyTupleIterator {
246
- position : Cell < usize > ,
246
+ position : AtomicCell < usize > ,
247
247
tuple : PyTupleRef ,
248
248
}
249
249
@@ -257,10 +257,10 @@ impl PyValue for PyTupleIterator {
257
257
impl PyTupleIterator {
258
258
#[ pymethod( name = "__next__" ) ]
259
259
fn next ( & self , vm : & VirtualMachine ) -> PyResult {
260
- if self . position . get ( ) < self . tuple . as_slice ( ) . len ( ) {
261
- let ret = self . tuple . as_slice ( ) [ self . position . get ( ) ] . clone ( ) ;
262
- self . position . set ( self . position . get ( ) + 1 ) ;
263
- Ok ( ret )
260
+ let pos = self . position . load ( ) ;
261
+ if let Some ( obj ) = self . tuple . as_slice ( ) . get ( pos ) {
262
+ self . position . store ( pos + 1 ) ;
263
+ Ok ( obj . clone ( ) )
264
264
} else {
265
265
Err ( objiter:: new_stop_iteration ( vm) )
266
266
}
You can’t perform that action at this time.
0 commit comments