@@ -317,6 +317,7 @@ static TruffleString fromBufferWithStringCompaction(Node node, Object dataA, int
317
317
@ Cached InlinedConditionProfile utf32Profile ,
318
318
@ Cached InlinedConditionProfile utf32Compact0Profile ,
319
319
@ Cached InlinedConditionProfile utf32Compact1Profile ,
320
+ @ Cached InlinedConditionProfile singleByteProfile ,
320
321
@ Cached InlinedByteValueProfile unlikelyEncodingProfile ) {
321
322
assert dataA instanceof byte [] || dataA instanceof NativePointer ;
322
323
try {
@@ -343,6 +344,9 @@ static TruffleString fromBufferWithStringCompaction(Node node, Object dataA, int
343
344
codeRange = StringAttributes .getCodeRange (attrs );
344
345
stride = Stride .fromCodeRangeUTF16 (codeRange );
345
346
if (copy || stride == 0 ) {
347
+ if (singleByteProfile .profile (node , isCacheHead && length == 1 && stride == 0 )) {
348
+ return TStringConstants .getSingleByte (Encoding .UTF_16 , TStringOps .readS1 (arrayA , offsetA , 1 , 0 ));
349
+ }
346
350
offset = 0 ;
347
351
array = new byte [length << stride ];
348
352
if (utf16CompactProfile .profile (node , stride == 0 )) {
@@ -361,6 +365,9 @@ static TruffleString fromBufferWithStringCompaction(Node node, Object dataA, int
361
365
codePointLength = length ;
362
366
stride = Stride .fromCodeRangeUTF32 (codeRange );
363
367
if (copy || stride < 2 ) {
368
+ if (singleByteProfile .profile (node , isCacheHead && length == 1 && stride == 0 )) {
369
+ return TStringConstants .getSingleByte (Encoding .UTF_32 , TStringOps .readS2 (arrayA , offsetA , 1 , 0 ));
370
+ }
364
371
offset = 0 ;
365
372
array = new byte [length << stride ];
366
373
if (utf32Compact0Profile .profile (node , stride == 0 )) {
@@ -379,6 +386,9 @@ static TruffleString fromBufferWithStringCompaction(Node node, Object dataA, int
379
386
stride = 0 ;
380
387
final long attrs ;
381
388
if (utf8Profile .profile (node , isUTF8 (encoding ))) {
389
+ if (singleByteProfile .profile (node , isCacheHead && length == 1 )) {
390
+ return TStringConstants .getSingleByte (Encoding .UTF_8 , TStringOps .readS0 (arrayA , offsetA , 1 , 0 ));
391
+ }
382
392
attrs = TStringOps .calcStringAttributesUTF8 (node , arrayA , offsetA , length , false , false , utf8BrokenProfile );
383
393
} else {
384
394
attrs = unlikelyCases (node , arrayA , offsetA , byteLength , encoding , unlikelyEncodingProfile .profile (node , encoding .id ));
@@ -1410,7 +1420,8 @@ static TruffleString materializeSubstring(Node node, AbstractTruffleString a, by
1410
1420
@ SuppressWarnings ("unused" ) boolean lazy ,
1411
1421
@ Shared ("attributes" ) @ Cached CalcStringAttributesNode calcAttributesNode ,
1412
1422
@ Exclusive @ Cached InlinedConditionProfile utf16Profile ,
1413
- @ Exclusive @ Cached InlinedConditionProfile utf32Profile ) {
1423
+ @ Exclusive @ Cached InlinedConditionProfile utf32Profile ,
1424
+ @ Exclusive @ Cached InlinedConditionProfile singleByteProfile ) {
1414
1425
final long attrs ;
1415
1426
final int codeRange ;
1416
1427
final int stride ;
@@ -1431,6 +1442,9 @@ static TruffleString materializeSubstring(Node node, AbstractTruffleString a, by
1431
1442
codeRange = StringAttributes .getCodeRange (attrs );
1432
1443
newStride = 0 ;
1433
1444
}
1445
+ if (singleByteProfile .profile (node , length == 1 && newStride == 0 && encoding .isSupported ())) {
1446
+ return TStringConstants .getSingleByte (encoding , TStringOps .readValue (arrayA , offsetA , a .length (), stride , fromIndex ));
1447
+ }
1434
1448
byte [] newBytes = TStringOps .arraycopyOfWithStride (node , arrayA , offsetA + (fromIndex << stride ), length , stride , length , newStride );
1435
1449
return TruffleString .createFromByteArray (newBytes , length , newStride , encoding , StringAttributes .getCodePointLength (attrs ), codeRange );
1436
1450
}
@@ -1440,11 +1454,15 @@ static TruffleString createLazySubstring(Node node, TruffleString a, byte[] arra
1440
1454
@ SuppressWarnings ("unused" ) boolean lazy ,
1441
1455
@ Shared ("attributes" ) @ Cached CalcStringAttributesNode calcAttributesNode ,
1442
1456
@ Exclusive @ Cached InlinedConditionProfile stride1MustMaterializeProfile ,
1443
- @ Exclusive @ Cached InlinedConditionProfile stride2MustMaterializeProfile ) {
1457
+ @ Exclusive @ Cached InlinedConditionProfile stride2MustMaterializeProfile ,
1458
+ @ Exclusive @ Cached InlinedConditionProfile singleByteProfile ) {
1444
1459
long lazyOffset = offsetA + (fromIndex << a .stride ());
1445
1460
long attrs = calcAttributesNode .execute (node , a , arrayA , offsetA , length , a .stride (), encoding , fromIndex , codeRangeA );
1446
1461
int codeRange = StringAttributes .getCodeRange (attrs );
1447
1462
int codePointLength = StringAttributes .getCodePointLength (attrs );
1463
+ if (singleByteProfile .profile (node , length == 1 && Stride .fromCodeRange (codeRange , encoding ) == 0 && encoding .isSupported ())) {
1464
+ return TStringConstants .getSingleByte (encoding , TStringOps .readValue (arrayA , offsetA , a .length (), a .stride (), fromIndex ));
1465
+ }
1448
1466
final Object data ;
1449
1467
final int offset ;
1450
1468
final int stride ;
0 commit comments