Skip to content

Commit a1eaac4

Browse files
committed
Fix: virtual call to 'SequenceStorage.length'.
1 parent 0b50030 commit a1eaac4

File tree

1 file changed

+11
-9
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator

1 file changed

+11
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7676
public abstract static class NextNode extends PythonUnaryBuiltinNode {
7777

7878
@Specialization
79-
public Object next(PArrayIterator self,
79+
Object next(PArrayIterator self,
8080
@Cached("createClassProfile()") ValueProfile itemTypeProfile,
81-
@Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode) {
82-
if (self.index < self.array.len()) {
81+
@Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode,
82+
@Cached SequenceStorageNodes.LenNode lenNode) {
83+
SequenceStorage sequenceStorage = self.array.getSequenceStorage();
84+
if (self.index < lenNode.execute(sequenceStorage)) {
8385
// TODO avoid boxing by getting the array's typecode and using primitive return
8486
// types
85-
return itemTypeProfile.profile(getItemNode.execute(self.array.getSequenceStorage(), self.index++));
87+
return itemTypeProfile.profile(getItemNode.execute(sequenceStorage, self.index++));
8688
}
8789
throw raise(StopIteration);
8890
}
8991

9092
@Specialization
91-
public int next(PIntegerSequenceIterator self) {
93+
int next(PIntegerSequenceIterator self) {
9294
if (!self.isExhausted() && self.index < self.sequence.length()) {
9395
return self.sequence.getIntItemNormalized(self.index++);
9496
}
@@ -97,7 +99,7 @@ public int next(PIntegerSequenceIterator self) {
9799
}
98100

99101
@Specialization
100-
public int next(PRangeIterator self) {
102+
int next(PRangeIterator self) {
101103
if (self.index < self.stop) {
102104
int value = self.index;
103105
self.index += self.step;
@@ -107,7 +109,7 @@ public int next(PRangeIterator self) {
107109
}
108110

109111
@Specialization
110-
public int next(PRangeReverseIterator self) {
112+
int next(PRangeReverseIterator self) {
111113
if (self.index > self.stop) {
112114
int value = self.index;
113115
self.index -= self.step;
@@ -117,7 +119,7 @@ public int next(PRangeReverseIterator self) {
117119
}
118120

119121
@Specialization
120-
public double next(PDoubleSequenceIterator self) {
122+
double next(PDoubleSequenceIterator self) {
121123
if (!self.isExhausted() && self.index < self.sequence.length()) {
122124
return self.sequence.getDoubleItemNormalized(self.index++);
123125
}
@@ -126,7 +128,7 @@ public double next(PDoubleSequenceIterator self) {
126128
}
127129

128130
@Specialization
129-
public long next(PLongSequenceIterator self) {
131+
long next(PLongSequenceIterator self) {
130132
if (!self.isExhausted() && self.index < self.sequence.length()) {
131133
return self.sequence.getLongItemNormalized(self.index++);
132134
}

0 commit comments

Comments
 (0)