3232import java .util .function .IntConsumer ;
3333import java .util .stream .Stream ;
3434import java .util .stream .StreamSupport ;
35- import jdk .internal .misc .Unsafe ;
3635import jdk .internal .util .ArraysSupport ;
36+ import jdk .internal .util .ByteArrayLittleEndian ;
3737import jdk .internal .vm .annotation .DontInline ;
3838import jdk .internal .vm .annotation .ForceInline ;
3939import jdk .internal .vm .annotation .IntrinsicCandidate ;
@@ -1514,8 +1514,6 @@ public static int lastIndexOfLatin1(byte[] src, int srcCount,
15141514 }
15151515 }
15161516
1517- private static final Unsafe UNSAFE = Unsafe .getUnsafe ();
1518-
15191517 static final int MAX_LENGTH = Integer .MAX_VALUE >> 1 ;
15201518
15211519 // Used by trusted callers. Assumes all necessary bounds checks have
@@ -1550,12 +1548,7 @@ static int getChars(int i, int index, byte[] buf) {
15501548 int inflated = ((packed & 0xFF00 ) << 8 ) | (packed & 0xFF );
15511549
15521550 charPos -= 2 ;
1553- assert charPos >= 0 && charPos < buf .length : "Trusted caller missed bounds check" ;
1554- UNSAFE .putIntUnaligned (
1555- buf ,
1556- Unsafe .ARRAY_BYTE_BASE_OFFSET + (charPos << 1 ),
1557- inflated ,
1558- false );
1551+ ByteArrayLittleEndian .setInt (buf , charPos << 1 , inflated );
15591552 }
15601553
15611554 // We know there are at most two digits left at this point.
@@ -1564,12 +1557,7 @@ static int getChars(int i, int index, byte[] buf) {
15641557 int inflated = ((packed & 0xFF00 ) << 8 ) | (packed & 0xFF );
15651558
15661559 charPos -= 2 ;
1567- assert charPos >= 0 && charPos < buf .length : "Trusted caller missed bounds check" ;
1568- UNSAFE .putIntUnaligned (
1569- buf ,
1570- Unsafe .ARRAY_BYTE_BASE_OFFSET + (charPos << 1 ),
1571- inflated ,
1572- false );
1560+ ByteArrayLittleEndian .setInt (buf , charPos << 1 , inflated );
15731561 } else {
15741562 putChar (buf , --charPos , '0' - i );
15751563 }
@@ -1607,12 +1595,7 @@ static int getChars(long i, int index, byte[] buf) {
16071595 int inflated = ((packed & 0xFF00 ) << 8 ) | (packed & 0xFF );
16081596
16091597 charPos -= 2 ;
1610- assert charPos >= 0 && charPos < buf .length : "Trusted caller missed bounds check" ;
1611- UNSAFE .putIntUnaligned (
1612- buf ,
1613- Unsafe .ARRAY_BYTE_BASE_OFFSET + (charPos << 1 ),
1614- inflated ,
1615- false );
1598+ ByteArrayLittleEndian .setInt (buf , charPos << 1 , inflated );
16161599 i = q ;
16171600 }
16181601
@@ -1626,12 +1609,7 @@ static int getChars(long i, int index, byte[] buf) {
16261609 int inflated = ((packed & 0xFF00 ) << 8 ) | (packed & 0xFF );
16271610
16281611 charPos -= 2 ;
1629- assert charPos >= 0 && charPos < buf .length : "Trusted caller missed bounds check" ;
1630- UNSAFE .putIntUnaligned (
1631- buf ,
1632- Unsafe .ARRAY_BYTE_BASE_OFFSET + (charPos << 1 ),
1633- inflated ,
1634- false );
1612+ ByteArrayLittleEndian .setInt (buf , charPos << 1 , inflated );
16351613 i2 = q2 ;
16361614 }
16371615
@@ -1642,12 +1620,7 @@ static int getChars(long i, int index, byte[] buf) {
16421620 int packed = (int ) StringLatin1 .PACKED_DIGITS [-i2 ];
16431621 int inflated = ((packed & 0xFF00 ) << 8 ) | (packed & 0xFF );
16441622
1645- assert charPos >= 0 && charPos < buf .length : "Trusted caller missed bounds check" ;
1646- UNSAFE .putIntUnaligned (
1647- buf ,
1648- Unsafe .ARRAY_BYTE_BASE_OFFSET + (charPos << 1 ),
1649- inflated ,
1650- false );
1623+ ByteArrayLittleEndian .setInt (buf , charPos << 1 , inflated );
16511624 } else {
16521625 putChar (buf , --charPos , '0' - i2 );
16531626 }
0 commit comments