Skip to content

Commit cfb4d18

Browse files
committed
Avoid wrapping of sequences with native storages.
1 parent ef751a5 commit cfb4d18

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
import com.oracle.graal.python.runtime.interop.InteropArray;
135135
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
136136
import com.oracle.graal.python.runtime.sequence.PSequence;
137+
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
138+
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
137139
import com.oracle.truffle.api.CompilerAsserts;
138140
import com.oracle.truffle.api.CompilerDirectives;
139141
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -610,12 +612,22 @@ int doMaUsed(PDict object, @SuppressWarnings("unused") String key,
610612
}
611613

612614
@Specialization(guards = "eq(OB_SVAL, key)")
613-
Object doObSval(PBytes object, @SuppressWarnings("unused") String key) {
615+
Object doObSval(PBytes object, @SuppressWarnings("unused") String key,
616+
@Cached("createClassProfile()") ValueProfile classProfile) {
617+
SequenceStorage sequenceStorage = classProfile.profile(object.getSequenceStorage());
618+
if (sequenceStorage instanceof NativeSequenceStorage) {
619+
return ((NativeSequenceStorage) sequenceStorage).getPtr();
620+
}
614621
return new PySequenceArrayWrapper(object, 1);
615622
}
616623

617624
@Specialization(guards = "eq(OB_START, key)")
618-
Object doObStart(PByteArray object, @SuppressWarnings("unused") String key) {
625+
Object doObStart(PByteArray object, @SuppressWarnings("unused") String key,
626+
@Cached("createClassProfile()") ValueProfile classProfile) {
627+
SequenceStorage sequenceStorage = classProfile.profile(object.getSequenceStorage());
628+
if (sequenceStorage instanceof NativeSequenceStorage) {
629+
return ((NativeSequenceStorage) sequenceStorage).getPtr();
630+
}
619631
return new PySequenceArrayWrapper(object, 1);
620632
}
621633

@@ -632,7 +644,12 @@ Object doObFval(Object object, @SuppressWarnings("unused") String key,
632644
}
633645

634646
@Specialization(guards = "eq(OB_ITEM, key)")
635-
Object doObItem(PSequence object, @SuppressWarnings("unused") String key) {
647+
Object doObItem(PSequence object, @SuppressWarnings("unused") String key,
648+
@Cached("createClassProfile()") ValueProfile classProfile) {
649+
SequenceStorage sequenceStorage = classProfile.profile(object.getSequenceStorage());
650+
if (sequenceStorage instanceof NativeSequenceStorage) {
651+
return ((NativeSequenceStorage) sequenceStorage).getPtr();
652+
}
636653
return new PySequenceArrayWrapper(object, 4);
637654
}
638655

0 commit comments

Comments
 (0)