|
49 | 49 |
|
50 | 50 | public abstract class PClosureRootNode extends PRootNode {
|
51 | 51 | @CompilerDirectives.CompilationFinal(dimensions = 1) protected final FrameSlot[] freeVarSlots;
|
| 52 | + private final int length; |
52 | 53 |
|
53 | 54 | protected PClosureRootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor, FrameSlot[] freeVarSlots) {
|
54 | 55 | super(language, frameDescriptor);
|
55 | 56 | this.freeVarSlots = freeVarSlots;
|
| 57 | + this.length = freeVarSlots != null ? freeVarSlots.length : 0; |
56 | 58 | }
|
57 | 59 |
|
58 |
| - @ExplodeLoop |
59 | 60 | protected void addClosureCellsToLocals(Frame frame) {
|
60 | 61 | PCell[] closure = PArguments.getClosure(frame);
|
61 | 62 | if (closure != null) {
|
62 | 63 | assert freeVarSlots != null : "closure root node: the free var slots cannot be null when the closure is not null";
|
63 | 64 | assert closure.length == freeVarSlots.length : "closure root node: the closure must have the same length as the free var slots array";
|
64 |
| - for (int i = 0; i < freeVarSlots.length; i++) { |
65 |
| - frame.setObject(freeVarSlots[i], closure[i]); |
| 65 | + if (freeVarSlots.length < 32) { |
| 66 | + addClosureCellsToLocalsExploded(frame, closure); |
| 67 | + } else { |
| 68 | + addClosureCellsToLocalsLoop(frame, closure); |
66 | 69 | }
|
67 | 70 | }
|
68 | 71 | }
|
| 72 | + |
| 73 | + protected void addClosureCellsToLocalsLoop(Frame frame, PCell[] closure) { |
| 74 | + for (int i = 0; i < length; i++) { |
| 75 | + frame.setObject(freeVarSlots[i], closure[i]); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + @ExplodeLoop |
| 80 | + protected void addClosureCellsToLocalsExploded(Frame frame, PCell[] closure) { |
| 81 | + for (int i = 0; i < length; i++) { |
| 82 | + frame.setObject(freeVarSlots[i], closure[i]); |
| 83 | + } |
| 84 | + } |
69 | 85 | }
|
0 commit comments