File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -1422,6 +1422,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
14221422    let  usize_bytes = mem:: size_of :: < usize > ( ) ; 
14231423    let  ascii_block_size = 2  *  usize_bytes; 
14241424    let  blocks_end = if  len >= ascii_block_size {  len - ascii_block_size + 1  }  else  {  0  } ; 
1425+     let  align = v. as_ptr ( ) . align_offset ( usize_bytes) ; 
14251426
14261427    while  index < len { 
14271428        let  old_offset = index; 
@@ -1501,12 +1502,8 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
15011502            // Ascii case, try to skip forward quickly. 
15021503            // When the pointer is aligned, read 2 words of data per iteration 
15031504            // until we find a word containing a non-ascii byte. 
1504-             let  ptr = v. as_ptr ( ) ; 
1505-             let  align = unsafe  { 
1506-                 // the offset is safe, because `index` is guaranteed inbounds 
1507-                 ptr. add ( index) . align_offset ( usize_bytes) 
1508-             } ; 
1509-             if  align == 0  { 
1505+             if  align. wrapping_sub ( index)  % usize_bytes == 0  { 
1506+                 let  ptr = v. as_ptr ( ) ; 
15101507                while  index < blocks_end { 
15111508                    unsafe  { 
15121509                        let  block = ptr. add ( index)  as  * const  usize ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments