@@ -365,23 +365,28 @@ pub(crate) fn is_less_than<'a, const LEFT_FIRST: bool>(
365365 let ( px, py, gc) = match ( Primitive :: try_from ( x. into ( ) ) , Primitive :: try_from ( y. into ( ) ) ) {
366366 ( Ok ( px) , Ok ( py) ) => {
367367 let gc = gc. into_nogc ( ) ;
368- ( px. bind ( gc) , py. bind ( gc) , gc)
368+ let px = px. bind ( gc) ;
369+ let py = py. bind ( gc) ;
370+ ( px, py, gc)
369371 }
370372 ( Ok ( px) , Err ( _) ) => {
371373 let px = px. scope ( agent, gc. nogc ( ) ) ;
372374 let py = to_primitive ( agent, y. into ( ) , Some ( PreferredType :: Number ) , gc. reborrow ( ) )
373375 . unbind ( ) ?;
374376 let gc = gc. into_nogc ( ) ;
375- let px = px. get ( agent) ;
376- ( px. bind ( gc) , py. bind ( gc) , gc)
377+ let px = px. get ( agent) . bind ( gc) ;
378+ let py = py. bind ( gc) ;
379+ ( px, py, gc)
377380 }
378381 ( Err ( _) , Ok ( py) ) => {
379382 let py = py. scope ( agent, gc. nogc ( ) ) ;
380383 let px = to_primitive ( agent, x. into ( ) , Some ( PreferredType :: Number ) , gc. reborrow ( ) )
381384 . unbind ( ) ?;
382385 let gc = gc. into_nogc ( ) ;
383- let py = py. get ( agent) ;
384- ( px. bind ( gc) , py. bind ( gc) , gc)
386+ let px = px. bind ( gc) ;
387+ // SAFETY: not shared.
388+ let py = unsafe { py. take ( agent) } . bind ( gc) ;
389+ ( px, py, gc)
385390 }
386391 ( Err ( _) , Err ( _) ) => {
387392 if LEFT_FIRST {
@@ -392,17 +397,22 @@ pub(crate) fn is_less_than<'a, const LEFT_FIRST: bool>(
392397 let y = y. scope ( agent, gc. nogc ( ) ) ;
393398 let px = to_primitive ( agent, x. into ( ) , Some ( PreferredType :: Number ) , gc. reborrow ( ) )
394399 . unbind ( ) ?
395- . scope ( agent, gc. nogc ( ) ) ;
400+ . bind ( gc. nogc ( ) ) ;
401+ let py = y. get ( agent) . bind ( gc. nogc ( ) ) ;
402+ // SAFETY: not shared.
403+ let px = unsafe { y. replace_self ( agent, px. unbind ( ) ) } ;
396404 let py = to_primitive (
397405 agent,
398- y . get ( agent ) ,
406+ py . unbind ( ) ,
399407 Some ( PreferredType :: Number ) ,
400408 gc. reborrow ( ) ,
401409 )
402410 . unbind ( ) ?;
403411 let gc = gc. into_nogc ( ) ;
404- let px = px. get ( agent) ;
405- ( px. bind ( gc) , py. bind ( gc) , gc)
412+ // SAFETY: not shared.
413+ let px = unsafe { px. take ( agent) } . bind ( gc) ;
414+ let py = py. bind ( gc) ;
415+ ( px, py, gc)
406416 } else {
407417 // 2. Else,
408418 // a. NOTE: The order of evaluation needs to be reversed to preserve left to right evaluation.
@@ -412,17 +422,21 @@ pub(crate) fn is_less_than<'a, const LEFT_FIRST: bool>(
412422 let x = x. scope ( agent, gc. nogc ( ) ) ;
413423 let py = to_primitive ( agent, y. into ( ) , Some ( PreferredType :: Number ) , gc. reborrow ( ) )
414424 . unbind ( ) ?
415- . scope ( agent, gc. nogc ( ) ) ;
425+ . bind ( gc. nogc ( ) ) ;
426+ let px = x. get ( agent) . bind ( gc. nogc ( ) ) ;
427+ // SAFETY: not shared.
428+ let py = unsafe { x. replace_self ( agent, py. unbind ( ) ) } ;
416429 let px = to_primitive (
417430 agent,
418- x . get ( agent ) ,
431+ px . unbind ( ) ,
419432 Some ( PreferredType :: Number ) ,
420433 gc. reborrow ( ) ,
421434 )
422435 . unbind ( ) ?;
423436 let gc = gc. into_nogc ( ) ;
424- let py = py. get ( agent) ;
425- ( px. bind ( gc) , py. bind ( gc) , gc)
437+ let px = px. bind ( gc) ;
438+ let py = unsafe { py. take ( agent) } . bind ( gc) ;
439+ ( px, py, gc)
426440 }
427441 }
428442 } ;
0 commit comments