@@ -10,7 +10,6 @@ use crate::vm::VirtualMachine;
10
10
use num_bigint:: { BigInt , ToBigInt } ;
11
11
use num_traits:: { One , Signed , ToPrimitive , Zero } ;
12
12
13
- use super :: objbool;
14
13
use super :: objint:: { PyInt , PyIntRef } ;
15
14
use super :: objlist:: PyList ;
16
15
use super :: objslice:: { PySlice , PySliceRef } ;
@@ -285,15 +284,14 @@ pub fn seq_equal(
285
284
vm : & VirtualMachine ,
286
285
zelf : & dyn SimpleSeq ,
287
286
other : & dyn SimpleSeq ,
288
- ) -> Result < bool , PyObjectRef > {
287
+ ) -> PyResult < bool > {
289
288
if zelf. len ( ) == other. len ( ) {
290
289
for ( a, b) in Iterator :: zip ( zelf. iter ( ) , other. iter ( ) ) {
291
- if !a. is ( b) {
292
- let eq = vm. _eq ( a. clone ( ) , b. clone ( ) ) ?;
293
- let value = objbool:: boolval ( vm, eq) ?;
294
- if !value {
295
- return Ok ( false ) ;
296
- }
290
+ if a. is ( b) {
291
+ continue ;
292
+ }
293
+ if !vm. bool_eq ( a. clone ( ) , b. clone ( ) ) ? {
294
+ return Ok ( false ) ;
297
295
}
298
296
}
299
297
Ok ( true )
@@ -302,84 +300,42 @@ pub fn seq_equal(
302
300
}
303
301
}
304
302
305
- pub fn seq_lt (
306
- vm : & VirtualMachine ,
307
- zelf : & dyn SimpleSeq ,
308
- other : & dyn SimpleSeq ,
309
- ) -> Result < bool , PyObjectRef > {
303
+ pub fn seq_lt ( vm : & VirtualMachine , zelf : & dyn SimpleSeq , other : & dyn SimpleSeq ) -> PyResult < bool > {
310
304
for ( a, b) in Iterator :: zip ( zelf. iter ( ) , other. iter ( ) ) {
311
- if vm. bool_lt ( a. clone ( ) , b. clone ( ) ) ? {
312
- return Ok ( true ) ;
313
- } else if !vm. bool_eq ( a. clone ( ) , b. clone ( ) ) ? {
314
- return Ok ( false ) ;
305
+ if let Some ( v) = vm. bool_seq_lt ( a. clone ( ) , b. clone ( ) ) ? {
306
+ return Ok ( v) ;
315
307
}
316
308
}
317
-
318
- if zelf. len ( ) == other. len ( ) {
319
- Ok ( false )
320
- } else {
321
- Ok ( zelf. len ( ) < other. len ( ) )
322
- }
309
+ Ok ( zelf. len ( ) < other. len ( ) )
323
310
}
324
311
325
- pub fn seq_gt (
326
- vm : & VirtualMachine ,
327
- zelf : & dyn SimpleSeq ,
328
- other : & dyn SimpleSeq ,
329
- ) -> Result < bool , PyObjectRef > {
312
+ pub fn seq_gt ( vm : & VirtualMachine , zelf : & dyn SimpleSeq , other : & dyn SimpleSeq ) -> PyResult < bool > {
330
313
for ( a, b) in Iterator :: zip ( zelf. iter ( ) , other. iter ( ) ) {
331
- if vm. bool_gt ( a. clone ( ) , b. clone ( ) ) ? {
332
- return Ok ( true ) ;
333
- } else if !vm. bool_eq ( a. clone ( ) , b. clone ( ) ) ? {
334
- return Ok ( false ) ;
314
+ if let Some ( v) = vm. bool_seq_gt ( a. clone ( ) , b. clone ( ) ) ? {
315
+ return Ok ( v) ;
335
316
}
336
317
}
337
-
338
- if zelf. len ( ) == other. len ( ) {
339
- Ok ( false )
340
- } else {
341
- Ok ( zelf. len ( ) > other. len ( ) )
342
- }
318
+ Ok ( zelf. len ( ) > other. len ( ) )
343
319
}
344
320
345
- pub fn seq_ge (
346
- vm : & VirtualMachine ,
347
- zelf : & dyn SimpleSeq ,
348
- other : & dyn SimpleSeq ,
349
- ) -> Result < bool , PyObjectRef > {
321
+ pub fn seq_ge ( vm : & VirtualMachine , zelf : & dyn SimpleSeq , other : & dyn SimpleSeq ) -> PyResult < bool > {
350
322
for ( a, b) in Iterator :: zip ( zelf. iter ( ) , other. iter ( ) ) {
351
- if vm. bool_gt ( a. clone ( ) , b. clone ( ) ) ? {
352
- return Ok ( true ) ;
353
- } else if !vm. bool_eq ( a. clone ( ) , b. clone ( ) ) ? {
354
- return Ok ( false ) ;
323
+ if let Some ( v) = vm. bool_seq_gt ( a. clone ( ) , b. clone ( ) ) ? {
324
+ return Ok ( v) ;
355
325
}
356
326
}
357
327
358
- if zelf. len ( ) == other. len ( ) {
359
- Ok ( true )
360
- } else {
361
- Ok ( zelf. len ( ) > other. len ( ) )
362
- }
328
+ Ok ( zelf. len ( ) >= other. len ( ) )
363
329
}
364
330
365
- pub fn seq_le (
366
- vm : & VirtualMachine ,
367
- zelf : & dyn SimpleSeq ,
368
- other : & dyn SimpleSeq ,
369
- ) -> Result < bool , PyObjectRef > {
331
+ pub fn seq_le ( vm : & VirtualMachine , zelf : & dyn SimpleSeq , other : & dyn SimpleSeq ) -> PyResult < bool > {
370
332
for ( a, b) in Iterator :: zip ( zelf. iter ( ) , other. iter ( ) ) {
371
- if vm. bool_lt ( a. clone ( ) , b. clone ( ) ) ? {
372
- return Ok ( true ) ;
373
- } else if !vm. bool_eq ( a. clone ( ) , b. clone ( ) ) ? {
374
- return Ok ( false ) ;
333
+ if let Some ( v) = vm. bool_seq_lt ( a. clone ( ) , b. clone ( ) ) ? {
334
+ return Ok ( v) ;
375
335
}
376
336
}
377
337
378
- if zelf. len ( ) == other. len ( ) {
379
- Ok ( true )
380
- } else {
381
- Ok ( zelf. len ( ) < other. len ( ) )
382
- }
338
+ Ok ( zelf. len ( ) <= other. len ( ) )
383
339
}
384
340
385
341
pub struct SeqMul < ' a > {
0 commit comments