Skip to content

Commit 825e87f

Browse files
committed
Add HandleStack.pushRange
1 parent 9b11c77 commit 825e87f

File tree

1 file changed

+29
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common

1 file changed

+29
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/HandleStack.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,12 +42,21 @@
4242

4343
import java.util.Arrays;
4444

45+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
46+
4547
public final class HandleStack {
4648
private int[] handles;
4749
private int top = 0;
4850

4951
public HandleStack(int initialCapacity) {
52+
this(initialCapacity, false);
53+
}
54+
55+
public HandleStack(int initialCapacity, boolean fill) {
5056
handles = new int[initialCapacity];
57+
if (fill) {
58+
pushRange(0, initialCapacity);
59+
}
5160
}
5261

5362
public void push(int i) {
@@ -57,6 +66,24 @@ public void push(int i) {
5766
handles[top++] = i;
5867
}
5968

69+
/**
70+
* Push a range of values to the stack.
71+
*
72+
* @param start The first value to push (inclusive).
73+
* @param end The last value to push (exclusive).
74+
*/
75+
@TruffleBoundary
76+
public void pushRange(int start, int end) {
77+
int n = end - start;
78+
if (top + n > handles.length) {
79+
handles = Arrays.copyOf(handles, top + n);
80+
}
81+
for (int i = 0; i < n; i++) {
82+
handles[top + i] = end - i - 1;
83+
}
84+
top += n;
85+
}
86+
6087
public int pop() {
6188
if (top <= 0) {
6289
return -1;
@@ -67,4 +94,4 @@ public int pop() {
6794
public int getTop() {
6895
return top;
6996
}
70-
}
97+
}

0 commit comments

Comments
 (0)