@@ -622,15 +622,18 @@ public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr,
622
622
@ CoreMethod (names = "[]=" , required = 2 , lowerFixnumParameters = 0 , raiseIfFrozenSelf = true )
623
623
public abstract static class ElementSetNode extends CoreMethodNode {
624
624
625
+ @ Child private SizeNode sizeNode ;
625
626
@ Child private ToStrNode toStrNode ;
626
627
627
628
public ElementSetNode (RubyContext context , SourceSection sourceSection ) {
628
629
super (context , sourceSection );
630
+ sizeNode = StringNodesFactory .SizeNodeFactory .create (context , sourceSection , new RubyNode [] { null });
629
631
toStrNode = ToStrNodeFactory .create (context , sourceSection , null );
630
632
}
631
633
632
634
public ElementSetNode (ElementSetNode prev ) {
633
635
super (prev );
636
+ sizeNode = prev .sizeNode ;
634
637
toStrNode = prev .toStrNode ;
635
638
}
636
639
@@ -648,7 +651,7 @@ public RubyString elementSet(VirtualFrame frame, RubyString string, RubyRange.In
648
651
649
652
int begin = range .getBegin ();
650
653
int end = range .getEnd ();
651
- final int stringLength = string . length ( );
654
+ final int stringLength = sizeNode . executeIntegerFixnum ( frame , string );
652
655
653
656
if (begin < 0 ) {
654
657
begin += stringLength ;
@@ -801,19 +804,23 @@ public int byteSize(RubyString string) {
801
804
@ CoreMethod (names = "chop!" , raiseIfFrozenSelf = true )
802
805
public abstract static class ChopBangNode extends CoreMethodNode {
803
806
807
+ @ Child private SizeNode sizeNode ;
808
+
804
809
public ChopBangNode (RubyContext context , SourceSection sourceSection ) {
805
810
super (context , sourceSection );
811
+ sizeNode = StringNodesFactory .SizeNodeFactory .create (context , sourceSection , new RubyNode [] { null });
806
812
}
807
813
808
814
public ChopBangNode (ChopBangNode prev ) {
809
815
super (prev );
816
+ sizeNode = prev .sizeNode ;
810
817
}
811
818
812
819
@ Specialization
813
- public Object chopBang (RubyString string ) {
820
+ public Object chopBang (VirtualFrame frame , RubyString string ) {
814
821
notDesignedForCompilation ();
815
822
816
- if (string . length ( ) == 0 ) {
823
+ if (sizeNode . executeIntegerFixnum ( frame , string ) == 0 ) {
817
824
return nil ();
818
825
}
819
826
@@ -1483,38 +1490,43 @@ public RubyString replace(RubyString string, RubyString other) {
1483
1490
@ CoreMethod (names = "rindex" , required = 1 , optional = 1 , lowerFixnumParameters = 1 )
1484
1491
public abstract static class RindexNode extends CoreMethodNode {
1485
1492
1493
+ @ Child private SizeNode sizeNode ;
1494
+
1486
1495
public RindexNode (RubyContext context , SourceSection sourceSection ) {
1487
1496
super (context , sourceSection );
1497
+ sizeNode = StringNodesFactory .SizeNodeFactory .create (context , sourceSection , new RubyNode [] { null });
1488
1498
}
1489
1499
1490
1500
public RindexNode (RindexNode prev ) {
1491
1501
super (prev );
1502
+ sizeNode = prev .sizeNode ;
1492
1503
}
1493
1504
1494
1505
@ Specialization
1495
- public Object rindex (RubyString string , RubyString subString , @ SuppressWarnings ("unused" ) UndefinedPlaceholder endPosition ) {
1506
+ public Object rindex (VirtualFrame frame , RubyString string , RubyString subString , @ SuppressWarnings ("unused" ) UndefinedPlaceholder endPosition ) {
1496
1507
notDesignedForCompilation ();
1497
1508
1498
- return rindex (string , subString , string . length ( ));
1509
+ return rindex (frame , string , subString , sizeNode . executeIntegerFixnum ( frame , string ));
1499
1510
}
1500
1511
1501
1512
@ Specialization
1502
- public Object rindex (RubyString string , RubyString subString , int endPosition ) {
1513
+ public Object rindex (VirtualFrame frame , RubyString string , RubyString subString , int endPosition ) {
1503
1514
notDesignedForCompilation ();
1504
1515
1516
+ final int stringLength = sizeNode .executeIntegerFixnum (frame , string );
1505
1517
int normalizedEndPosition = endPosition ;
1506
1518
1507
1519
if (endPosition < 0 ) {
1508
- normalizedEndPosition = endPosition + string . length () ;
1520
+ normalizedEndPosition = endPosition + stringLength ;
1509
1521
1510
1522
if (normalizedEndPosition < 0 ) {
1511
1523
return nil ();
1512
1524
}
1513
- } else if (endPosition > string . length () ) {
1514
- normalizedEndPosition = string . length () ;
1525
+ } else if (endPosition > stringLength ) {
1526
+ normalizedEndPosition = stringLength ;
1515
1527
}
1516
1528
1517
- int result = StringSupport .rindex (string .getBytes (), string . length () , subString .length (),
1529
+ int result = StringSupport .rindex (string .getBytes (), stringLength , subString .length (),
1518
1530
normalizedEndPosition , subString , string .getBytes ().getEncoding ()
1519
1531
);
1520
1532
@@ -1770,6 +1782,8 @@ public SizeNode(SizeNode prev) {
1770
1782
super (prev );
1771
1783
}
1772
1784
1785
+ public abstract int executeIntegerFixnum (VirtualFrame frame , RubyString string );
1786
+
1773
1787
@ Specialization (guards = "isSingleByteOptimizable" )
1774
1788
public int sizeSingleByte (RubyString string ) {
1775
1789
return string .getByteList ().getRealSize ();
@@ -1819,7 +1833,7 @@ public SuccBangNode(SuccBangNode prev) {
1819
1833
public RubyString succBang (RubyString string ) {
1820
1834
notDesignedForCompilation ();
1821
1835
1822
- if (string .length () > 0 ) {
1836
+ if (string .getByteList (). getRealSize () > 0 ) {
1823
1837
string .set (StringSupport .succCommon (getContext ().getRuntime (), string .getBytes ()));
1824
1838
}
1825
1839
0 commit comments