19
19
20
20
import static org .truffleruby .core .array .ArrayHelpers .setSize ;
21
21
22
+ import org .truffleruby .Layouts ;
23
+
22
24
@ ImportStatic (ArrayGuards .class )
23
25
public abstract class ArrayAppendManyNode extends RubyBaseNode {
24
26
@@ -32,20 +34,24 @@ public DynamicObject appendManySameType(DynamicObject array, DynamicObject other
32
34
@ Cached ("of(array)" ) ArrayStrategy strategy ,
33
35
@ Cached ("of(other)" ) ArrayStrategy otherStrategy ,
34
36
@ Cached ("strategy.generalize(otherStrategy)" ) ArrayStrategy generalized ,
37
+ @ Cached ("strategy.capacityNode()" ) ArrayOperationNodes .ArrayCapacityNode capacityNode ,
38
+ @ Cached ("generalized.copyStoreNode()" ) ArrayOperationNodes .ArrayCopyStoreNode copyStoreNode ,
39
+ @ Cached ("otherStrategy.copyToNode()" ) ArrayOperationNodes .ArrayCopyToNode copyToNode ,
35
40
@ Cached ("createBinaryProfile()" ) ConditionProfile extendProfile ) {
36
41
final int oldSize = strategy .getSize (array );
37
42
final int otherSize = otherStrategy .getSize (other );
38
43
final int newSize = oldSize + otherSize ;
39
- final ArrayMirror storeMirror = strategy . newMirror (array );
40
- final ArrayMirror otherStoreMirror = otherStrategy . newMirror (other );
44
+ final Object store = Layouts . ARRAY . getStore (array );
45
+ final Object otherStore = Layouts . ARRAY . getStore (other );
41
46
42
- if (extendProfile .profile (newSize > storeMirror .getLength ())) {
43
- final int capacity = ArrayUtils .capacity (getContext (), storeMirror .getLength (), newSize );
44
- final ArrayMirror newStoreMirror = storeMirror .copyArrayAndMirror (capacity );
45
- otherStoreMirror .copyTo (newStoreMirror , 0 , oldSize , otherSize );
46
- strategy .setStoreAndSize (array , newStoreMirror .getArray (), newSize );
47
+ final int length = capacityNode .execute (store );
48
+ if (extendProfile .profile (newSize > length )) {
49
+ final int capacity = ArrayUtils .capacity (getContext (), length , newSize );
50
+ Object newStore = copyStoreNode .execute (store , capacity );
51
+ copyToNode .execute (otherStore , newStore , 0 , oldSize , otherSize );
52
+ strategy .setStoreAndSize (array , newStore , newSize );
47
53
} else {
48
- otherStoreMirror . copyTo ( storeMirror , 0 , oldSize , otherSize );
54
+ copyToNode . execute ( otherStore , store , 0 , oldSize , otherSize );
49
55
setSize (array , newSize );
50
56
}
51
57
return array ;
@@ -59,14 +65,19 @@ public DynamicObject appendManyGeneralize(DynamicObject array, DynamicObject oth
59
65
@ Cached ("of(array)" ) ArrayStrategy strategy ,
60
66
@ Cached ("of(other)" ) ArrayStrategy otherStrategy ,
61
67
@ Cached ("strategy.generalize(otherStrategy)" ) ArrayStrategy generalized ,
68
+ @ Cached ("generalized.newStoreNode()" ) ArrayOperationNodes .ArrayNewStoreNode newStoreNode ,
69
+ @ Cached ("strategy.copyToNode()" ) ArrayOperationNodes .ArrayCopyToNode copyToNode ,
70
+ @ Cached ("otherStrategy.copyToNode()" ) ArrayOperationNodes .ArrayCopyToNode otherCopyToNode ,
62
71
@ Cached ("createBinaryProfile()" ) ConditionProfile extendProfile ) {
63
72
final int oldSize = strategy .getSize (array );
64
73
final int otherSize = otherStrategy .getSize (other );
65
74
final int newSize = oldSize + otherSize ;
66
- final ArrayMirror newStoreMirror = generalized .newArray (newSize );
67
- strategy .newMirror (array ).copyTo (newStoreMirror , 0 , 0 , oldSize );
68
- otherStrategy .newMirror (other ).copyTo (newStoreMirror , 0 , oldSize , otherSize );
69
- generalized .setStoreAndSize (array , newStoreMirror .getArray (), newSize );
75
+ final Object store = Layouts .ARRAY .getStore (array );
76
+ final Object otherStore = Layouts .ARRAY .getStore (other );
77
+ final Object newStore = newStoreNode .execute (newSize );
78
+ copyToNode .execute (store , newStore , 0 , 0 , oldSize );
79
+ otherCopyToNode .execute (otherStore , newStore , 0 , oldSize , otherSize );
80
+ generalized .setStoreAndSize (array , newStore , newSize );
70
81
return array ;
71
82
}
72
83
0 commit comments