@@ -41,7 +41,7 @@ use std::{
4141 hash:: { Hash , Hasher } ,
4242 mem:: ManuallyDrop ,
4343 process:: abort,
44- ptr:: { self , addr_of , addr_of_mut , NonNull } ,
44+ ptr:: { self , NonNull } ,
4545 str:: FromStr ,
4646} ;
4747
@@ -532,6 +532,7 @@ impl JsString {
532532 /// Obtains the underlying [`&[u16]`][slice] slice of a [`JsString`]
533533 #[ inline]
534534 #[ must_use]
535+ #[ allow( clippy:: cast_ptr_alignment) ]
535536 pub fn as_str ( & self ) -> JsStr < ' _ > {
536537 match self . ptr . unwrap ( ) {
537538 UnwrappedTagged :: Ptr ( h) => {
@@ -552,26 +553,20 @@ impl JsString {
552553 // which means it is safe to read the `refcount` as `read_only` here.
553554 unsafe {
554555 let h = h. as_ptr ( ) ;
555- if ( * h) . refcount . read_only == 0 {
556+ let tagged_len = ( * h) . tagged_len ;
557+ let len = tagged_len. len ( ) ;
558+ let is_latin1 = tagged_len. is_latin1 ( ) ;
559+ let ptr = if ( * h) . refcount . read_only == 0 {
556560 let h = h. cast :: < StaticJsString > ( ) ;
557- return if ( * h) . tagged_len . is_latin1 ( ) {
558- JsStr :: latin1 ( std:: slice:: from_raw_parts (
559- ( * h) . ptr ,
560- ( * h) . tagged_len . len ( ) ,
561- ) )
562- } else {
563- JsStr :: utf16 ( std:: slice:: from_raw_parts (
564- ( * h) . ptr . cast ( ) ,
565- ( * h) . tagged_len . len ( ) ,
566- ) )
567- } ;
568- }
561+ ( * h) . ptr
562+ } else {
563+ ( & raw const ( * h) . data ) . cast :: < u8 > ( )
564+ } ;
569565
570- let len = ( * h) . len ( ) ;
571- if ( * h) . is_latin1 ( ) {
572- JsStr :: latin1 ( std:: slice:: from_raw_parts ( addr_of ! ( ( * h) . data) . cast ( ) , len) )
566+ if is_latin1 {
567+ JsStr :: latin1 ( std:: slice:: from_raw_parts ( ptr, len) )
573568 } else {
574- JsStr :: utf16 ( std:: slice:: from_raw_parts ( addr_of ! ( ( * h ) . data ) . cast ( ) , len) )
569+ JsStr :: utf16 ( std:: slice:: from_raw_parts ( ptr . cast :: < u16 > ( ) , len) )
575570 }
576571 }
577572 }
@@ -611,7 +606,7 @@ impl JsString {
611606
612607 let string = {
613608 // SAFETY: `allocate_inner` guarantees that `ptr` is a valid pointer.
614- let mut data = unsafe { addr_of_mut ! ( ( * ptr. as_ptr( ) ) . data) . cast :: < u8 > ( ) } ;
609+ let mut data = unsafe { ( & raw mut ( * ptr. as_ptr ( ) ) . data ) . cast :: < u8 > ( ) } ;
615610 for & string in strings {
616611 // SAFETY:
617612 // The sum of all `count` for each `string` equals `full_count`, and since we're
@@ -746,7 +741,7 @@ impl JsString {
746741 let ptr = Self :: allocate_inner ( count, string. is_latin1 ( ) ) ;
747742
748743 // SAFETY: `allocate_inner` guarantees that `ptr` is a valid pointer.
749- let data = unsafe { addr_of_mut ! ( ( * ptr. as_ptr( ) ) . data) . cast :: < u8 > ( ) } ;
744+ let data = unsafe { ( & raw mut ( * ptr. as_ptr ( ) ) . data ) . cast :: < u8 > ( ) } ;
750745
751746 // SAFETY:
752747 // - We read `count = data.len()` elements from `data`, which is within the bounds of the slice.
0 commit comments