File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -503,7 +503,14 @@ impl ObjectReference {
503503        NonZeroUsize :: new ( addr. 0 ) . map ( ObjectReference ) 
504504    } 
505505
506-     /// Like `from_raw_address`, but assume `addr` is not zero. 
506+     /// Like `from_raw_address`, but assume `addr` is not zero.  This can be used to elide a check 
507+      /// against zero for performance-critical code. 
508+      /// 
509+      /// # Safety 
510+      /// 
511+      /// This method assumes `addr` is not zero.  It should only be used in cases where we know at 
512+      /// compile time that the input cannot be zero.  For example, if we compute the address by 
513+      /// adding a positive offset to a non-zero address, we know the result must not be zero. 
507514     pub  unsafe  fn  from_raw_address_unchecked ( addr :  Address )  -> ObjectReference  { 
508515        debug_assert ! ( !addr. is_zero( ) ) ; 
509516        ObjectReference ( NonZeroUsize :: new_unchecked ( addr. 0 ) ) 
Original file line number Diff line number Diff line change @@ -100,9 +100,7 @@ pub fn is_vo_bit_set<VM: VMBinding>(object: ObjectReference) -> bool {
100100/// Check if an address can be turned directly into an object reference using the VO bit. 
101101/// If so, return `Some(object)`. Otherwise return `None`. 
102102pub  fn  is_vo_bit_set_for_addr < VM :  VMBinding > ( address :  Address )  -> Option < ObjectReference >  { 
103-     let  Some ( potential_object)  = ObjectReference :: from_raw_address ( address)  else  { 
104-         return  None ; 
105-     } ; 
103+     let  potential_object = ObjectReference :: from_raw_address ( address) ?; 
106104
107105    let  addr = potential_object. to_address :: < VM > ( ) ; 
108106
@@ -126,9 +124,7 @@ pub fn is_vo_bit_set_for_addr<VM: VMBinding>(address: Address) -> Option<ObjectR
126124/// 
127125/// This is unsafe: check the comment on `side_metadata::load` 
128126pub  unsafe  fn  is_vo_bit_set_unsafe < VM :  VMBinding > ( address :  Address )  -> Option < ObjectReference >  { 
129-     let  Some ( potential_object)  = ObjectReference :: from_raw_address ( address)  else  { 
130-         return  None ; 
131-     } ; 
127+     let  potential_object = ObjectReference :: from_raw_address ( address) ?; 
132128
133129    let  addr = potential_object. to_address :: < VM > ( ) ; 
134130
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments