1
1
/*
2
- * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. This
2
+ * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. This
3
3
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4
4
* redistribute it and/or modify it under the terms of the:
5
5
*
9
9
*/
10
10
package org .truffleruby .language .supercall ;
11
11
12
+ import com .oracle .truffle .api .profiles .ConditionProfile ;
12
13
import org .truffleruby .core .array .ArrayToObjectArrayNode ;
13
14
import org .truffleruby .core .array .ArrayToObjectArrayNodeGen ;
14
15
import org .truffleruby .core .array .ArrayUtils ;
@@ -28,6 +29,7 @@ public class ReadZSuperArgumentsNode extends RubyContextSourceNode {
28
29
@ Child private ArrayToObjectArrayNode unsplatNode ;
29
30
30
31
private final int restArgIndex ;
32
+ private final ConditionProfile isArrayProfile = ConditionProfile .create ();
31
33
32
34
public ReadZSuperArgumentsNode (int restArgIndex , RubyNode [] reloadNodes ) {
33
35
this .restArgIndex = restArgIndex ;
@@ -48,7 +50,14 @@ public final Object execute(VirtualFrame frame) {
48
50
49
51
if (restArgIndex != -1 ) {
50
52
final Object restArg = superArguments [restArgIndex ];
51
- final Object [] restArgs = unsplat ((RubyArray ) restArg );
53
+
54
+ final Object [] restArgs ;
55
+ if (isArrayProfile .profile (restArg instanceof RubyArray )) {
56
+ restArgs = unsplat ((RubyArray ) restArg );
57
+ } else {
58
+ restArgs = new Object []{ restArg };
59
+ }
60
+
52
61
final int after = superArguments .length - (restArgIndex + 1 );
53
62
Object [] splattedArguments = ArrayUtils .copyOf (superArguments , superArguments .length + restArgs .length - 1 );
54
63
ArrayUtils .arraycopy (
0 commit comments