@@ -1402,45 +1402,9 @@ public IRubyObject reverse(ThreadContext context) {
1402
1402
1403
1403
@ JRubyMethod (name = "reverse" )
1404
1404
public IRubyObject reverse19 (ThreadContext context ) {
1405
- Ruby runtime = context .runtime ;
1406
- if (value .getRealSize () <= 1 ) return strDup (context .runtime );
1407
-
1408
- byte []bytes = value .getUnsafeBytes ();
1409
- int p = value .getBegin ();
1410
- int len = value .getRealSize ();
1411
- byte []obytes = new byte [len ];
1412
-
1413
- boolean single = true ;
1414
- Encoding enc = value .getEncoding ();
1415
- // this really needs to be inlined here
1416
- if (singleByteOptimizable (enc )) {
1417
- for (int i = 0 ; i <= len >> 1 ; i ++) {
1418
- obytes [i ] = bytes [p + len - i - 1 ];
1419
- obytes [len - i - 1 ] = bytes [p + i ];
1420
- }
1421
- } else {
1422
- int end = p + len ;
1423
- int op = len ;
1424
- while (p < end ) {
1425
- int cl = StringSupport .length (enc , bytes , p , end );
1426
- if (cl > 1 || (bytes [p ] & 0x80 ) != 0 ) {
1427
- single = false ;
1428
- op -= cl ;
1429
- System .arraycopy (bytes , p , obytes , op , cl );
1430
- p += cl ;
1431
- } else {
1432
- obytes [--op ] = bytes [p ++];
1433
- }
1434
- }
1435
- }
1436
-
1437
- RubyString result = new RubyString (runtime , getMetaClass (), new ByteList (obytes , false ));
1438
-
1439
- if (getCodeRange () == CR_UNKNOWN ) setCodeRange (single ? CR_7BIT : CR_VALID );
1440
- Encoding encoding = value .getEncoding ();
1441
- result .value .setEncoding (encoding );
1442
- result .copyCodeRangeForSubstr (this , encoding );
1443
- return result .infectBy (this );
1405
+ RubyString str = strDup (context .runtime );
1406
+ str .reverse_bang19 (context );
1407
+ return str ;
1444
1408
}
1445
1409
1446
1410
public RubyString reverse_bang (ThreadContext context ) {
0 commit comments