Skip to content

Commit d6eb84d

Browse files
committed
Share a common empty DynamicLibrary array when copying instance variables from an object without any instance variables.
1 parent 93314bb commit d6eb84d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ RubyClass getClass(Object self) {
416416
@GenerateInline(inlineByDefault = true)
417417
public abstract static class CopyInstanceVariablesNode extends RubyBaseNode {
418418

419+
public static final DynamicObjectLibrary[] EMPTY_DYNAMIC_OBJECT_LIBRARY_ARRAY = new DynamicObjectLibrary[0];
419420
public static final PropertyGetter[] EMPTY_PROPERTY_GETTER_ARRAY = new PropertyGetter[0];
420421

421422
public abstract RubyDynamicObject execute(Node node, RubyDynamicObject newObject, RubyDynamicObject from);
@@ -466,6 +467,10 @@ protected static PropertyGetter[] getCopiedProperties(Shape shape) {
466467
}
467468

468469
protected DynamicObjectLibrary[] createWriteFieldNodes(PropertyGetter[] propertyGetters) {
470+
if (propertyGetters.length == 0) {
471+
return EMPTY_DYNAMIC_OBJECT_LIBRARY_ARRAY;
472+
}
473+
469474
final DynamicObjectLibrary[] nodes = new DynamicObjectLibrary[propertyGetters.length];
470475
for (int i = 0; i < propertyGetters.length; i++) {
471476
nodes[i] = DynamicObjectLibrary.getFactory().createDispatched(1);

0 commit comments

Comments
 (0)