Skip to content

Commit 100712a

Browse files
committed
Update offset of each write of MemoryView's array elements.
1 parent 6bdd6cd commit 100712a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ static Object getShape(int[] intArray,
9191
@Cached CStructAccess.AllocateNode alloc,
9292
@Cached CStructAccess.WriteLongNode write) {
9393
Object mem = alloc.alloc(intArray.length * Long.BYTES);
94-
for (int i = 0; i < intArray.length; i++) {
95-
write.write(mem, intArray[i]);
96-
}
94+
write.writeIntArray(mem, intArray);
9795
return mem;
9896
}
9997
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,16 @@ public final void writeLongArray(Object pointer, long[] values, int length, int
10481048
}
10491049
}
10501050

1051+
public final void writeIntArray(Object pointer, int[] values) {
1052+
writeIntArray(pointer, values, values.length, 0, 0);
1053+
}
1054+
1055+
public final void writeIntArray(Object pointer, int[] values, int length, int sourceOffset, int targetOffset) {
1056+
for (int i = 0; i < length; i++) {
1057+
execute(pointer, (i + targetOffset) * Long.BYTES, values[i + sourceOffset]);
1058+
}
1059+
}
1060+
10511061
public final boolean accepts(ArgDescriptor desc) {
10521062
return desc.isI64();
10531063
}

0 commit comments

Comments
 (0)