File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -503,7 +503,14 @@ impl ObjectReference {
503
503
NonZeroUsize :: new ( addr. 0 ) . map ( ObjectReference )
504
504
}
505
505
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.
507
514
pub unsafe fn from_raw_address_unchecked ( addr : Address ) -> ObjectReference {
508
515
debug_assert ! ( !addr. is_zero( ) ) ;
509
516
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 {
100
100
/// Check if an address can be turned directly into an object reference using the VO bit.
101
101
/// If so, return `Some(object)`. Otherwise return `None`.
102
102
pub 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) ?;
106
104
107
105
let addr = potential_object. to_address :: < VM > ( ) ;
108
106
@@ -126,9 +124,7 @@ pub fn is_vo_bit_set_for_addr<VM: VMBinding>(address: Address) -> Option<ObjectR
126
124
///
127
125
/// This is unsafe: check the comment on `side_metadata::load`
128
126
pub 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) ?;
132
128
133
129
let addr = potential_object. to_address :: < VM > ( ) ;
134
130
You can’t perform that action at this time.
0 commit comments