@@ -42,7 +42,31 @@ public int getByte(RubiniusByteArray bytes, int index) {
4242
4343 }
4444
45- @ CoreMethod (names = "set_byte" , required = 2 , lowerFixnumParameters = {1 , 2 })
45+ @ CoreMethod (names = "prepend" , required = 1 )
46+ public abstract static class PrependNode extends CoreMethodNode {
47+
48+ public PrependNode (RubyContext context , SourceSection sourceSection ) {
49+ super (context , sourceSection );
50+ }
51+
52+ public PrependNode (PrependNode prev ) {
53+ super (prev );
54+ }
55+
56+ @ Specialization
57+ public RubiniusByteArray prepend (RubiniusByteArray bytes , RubyString string ) {
58+ final int prependLength = string .getByteList ().getUnsafeBytes ().length ;
59+ final int originalLength = bytes .getBytes ().getUnsafeBytes ().length ;
60+ final int newLength = prependLength + originalLength ;
61+ final byte [] prependedBytes = new byte [newLength ];
62+ System .arraycopy (string .getByteList ().getUnsafeBytes (), 0 , prependedBytes , 0 , prependLength );
63+ System .arraycopy (bytes .getBytes ().getUnsafeBytes (), 0 , prependedBytes , prependLength , originalLength );
64+ return new RubiniusByteArray (getContext ().getCoreLibrary ().getByteArrayClass (), new ByteList (prependedBytes ));
65+ }
66+
67+ }
68+
69+ @ CoreMethod (names = "set_byte" , required = 2 , lowerFixnumParameters = {0 , 1 })
4670 public abstract static class SetByteNode extends CoreMethodNode {
4771
4872 public SetByteNode (RubyContext context , SourceSection sourceSection ) {
@@ -66,6 +90,24 @@ public Object setByte(RubiniusByteArray bytes, int index, int value) {
6690
6791 }
6892
93+ @ CoreMethod (names = "size" )
94+ public abstract static class SizeNode extends CoreMethodNode {
95+
96+ public SizeNode (RubyContext context , SourceSection sourceSection ) {
97+ super (context , sourceSection );
98+ }
99+
100+ public SizeNode (SizeNode prev ) {
101+ super (prev );
102+ }
103+
104+ @ Specialization
105+ public int size (RubiniusByteArray bytes ) {
106+ return bytes .getBytes ().getRealSize ();
107+ }
108+
109+ }
110+
69111 @ CoreMethod (names = "locate" , required = 3 )
70112 public abstract static class LocateNode extends CoreMethodNode {
71113
0 commit comments