Skip to content

Commit c34c627

Browse files
committed
[GR-15990] Update ArrayBuilderNode to use context reference
PullRequest: truffleruby/2404
2 parents 6649285 + 1a4e800 commit c34c627

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/main/java/org/truffleruby/core/array/ArrayBuilderNode.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.core.array;
1111

12-
import org.truffleruby.RubyContext;
1312
import org.truffleruby.core.array.library.ArrayStoreLibrary;
1413
import org.truffleruby.core.array.library.ArrayStoreLibrary.ArrayAllocator;
1514
import org.truffleruby.core.array.ArrayBuilderNodeFactory.AppendArrayNodeGen;
@@ -91,15 +90,15 @@ public Object finish(BuilderState state, int length) {
9190
private AppendArrayNode getAppendArrayNode() {
9291
if (appendArrayNode == null) {
9392
CompilerDirectives.transferToInterpreterAndInvalidate();
94-
appendArrayNode = insert(AppendArrayNode.create(getContext()));
93+
appendArrayNode = insert(AppendArrayNode.create());
9594
}
9695
return appendArrayNode;
9796
}
9897

9998
private AppendOneNode getAppendOneNode() {
10099
if (appendOneNode == null) {
101100
CompilerDirectives.transferToInterpreterAndInvalidate();
102-
appendOneNode = insert(AppendOneNode.create(getContext()));
101+
appendOneNode = insert(AppendOneNode.create());
103102
}
104103
return appendOneNode;
105104
}
@@ -129,10 +128,10 @@ public synchronized ArrayAllocator updateStrategy(ArrayStoreLibrary.ArrayAllocat
129128

130129
if (newStrategy != oldStrategy) {
131130
if (appendArrayNode != null) {
132-
appendArrayNode.replace(AppendArrayNode.create(getContext()));
131+
appendArrayNode.replace(AppendArrayNode.create());
133132
}
134133
if (appendOneNode != null) {
135-
appendOneNode.replace(AppendOneNode.create(getContext()));
134+
appendOneNode.replace(AppendOneNode.create());
136135
}
137136
}
138137

@@ -184,14 +183,8 @@ public BuilderState start(int length) {
184183
@ImportStatic(ArrayGuards.class)
185184
public abstract static class AppendOneNode extends ArrayBuilderBaseNode {
186185

187-
public static AppendOneNode create(RubyContext context) {
188-
return AppendOneNodeGen.create(context);
189-
}
190-
191-
private final RubyContext context;
192-
193-
public AppendOneNode(RubyContext context) {
194-
this.context = context;
186+
public static AppendOneNode create() {
187+
return AppendOneNodeGen.create();
195188
}
196189

197190
public abstract void executeAppend(BuilderState array, int index, Object value);
@@ -205,7 +198,7 @@ protected void appendCompatibleType(BuilderState state, int index, Object value,
205198
final int length = arrays.capacity(state.store);
206199
if (index >= length) {
207200
CompilerDirectives.transferToInterpreterAndInvalidate();
208-
final int capacity = ArrayUtils.capacityForOneMore(context, length);
201+
final int capacity = ArrayUtils.capacityForOneMore(getContext(), length);
209202
state.store = arrays.expand(state.store, capacity);
210203
state.capacity = capacity;
211204
replaceNodes(arrays.allocator(state.store), capacity);
@@ -227,7 +220,7 @@ protected void appendNewStrategy(BuilderState state, int index, Object value,
227220
final int currentCapacity = state.capacity;
228221
final int neededCapacity;
229222
if (index >= currentCapacity) {
230-
neededCapacity = ArrayUtils.capacityForOneMore(context, currentCapacity);
223+
neededCapacity = ArrayUtils.capacityForOneMore(getContext(), currentCapacity);
231224
} else {
232225
neededCapacity = currentCapacity;
233226
}
@@ -247,15 +240,10 @@ protected void appendNewStrategy(BuilderState state, int index, Object value,
247240
@ImportStatic(ArrayGuards.class)
248241
public abstract static class AppendArrayNode extends ArrayBuilderBaseNode {
249242

250-
public static AppendArrayNode create(RubyContext context) {
251-
return AppendArrayNodeGen.create(context);
243+
public static AppendArrayNode create() {
244+
return AppendArrayNodeGen.create();
252245
}
253246

254-
private final RubyContext context;
255-
256-
public AppendArrayNode(RubyContext context) {
257-
this.context = context;
258-
}
259247

260248
public abstract void executeAppend(BuilderState state, int index, RubyArray value);
261249

@@ -273,7 +261,7 @@ protected void appendCompatibleStrategy(BuilderState state, int index, RubyArray
273261
if (neededSize > length) {
274262
CompilerDirectives.transferToInterpreterAndInvalidate();
275263
replaceNodes(arrays.allocator(state.store), neededSize);
276-
final int capacity = ArrayUtils.capacity(context, length, neededSize);
264+
final int capacity = ArrayUtils.capacity(getContext(), length, neededSize);
277265
state.store = arrays.expand(state.store, capacity);
278266
state.capacity = capacity;
279267
}
@@ -300,7 +288,7 @@ protected void appendNewStrategy(BuilderState state, int index, RubyArray other,
300288
final int currentCapacity = state.capacity;
301289
final int neededCapacity;
302290
if (neededSize > currentCapacity) {
303-
neededCapacity = ArrayUtils.capacity(context, currentCapacity, neededSize);
291+
neededCapacity = ArrayUtils.capacity(getContext(), currentCapacity, neededSize);
304292
} else {
305293
neededCapacity = currentCapacity;
306294
}

0 commit comments

Comments
 (0)