Skip to content

Commit a4c6c46

Browse files
committed
Optimize C API function 'PyTruffle_SetAttr'.
1 parent 5f2dd33 commit a4c6c46

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import com.oracle.graal.python.nodes.attributes.HasInheritedAttributeNode;
142142
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
143143
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
144+
import com.oracle.graal.python.nodes.attributes.WriteAttributeToDynamicObjectNode;
144145
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
145146
import com.oracle.graal.python.nodes.call.InvokeNode;
146147
import com.oracle.graal.python.nodes.call.PythonCallNode;
@@ -590,25 +591,25 @@ Object op5(VirtualFrame frame, Object a, Object b, @SuppressWarnings("unused") i
590591

591592
@Builtin(name = "PyTruffle_SetAttr", minNumOfPositionalArgs = 3)
592593
@GenerateNodeFactory
593-
abstract static class PyObject_Setattr extends PythonBuiltinNode {
594+
abstract static class PyObject_Setattr extends PythonTernaryBuiltinNode {
594595
@Specialization
595-
@TruffleBoundary
596-
Object setattr(PythonBuiltinClass object, String key, Object value) {
597-
object.setAttributeUnsafe(key, value);
596+
Object doBuiltinClass(PythonBuiltinClass object, String key, Object value,
597+
@Exclusive @Cached("createForceType()") WriteAttributeToObjectNode writeAttrNode) {
598+
writeAttrNode.execute(object, key, value);
598599
return PNone.NONE;
599600
}
600601

601-
@Specialization(guards = {"!isPythonBuiltinClass(object)"})
602-
@TruffleBoundary
603-
Object setattr(PythonObject object, String key, Object value) {
604-
object.getStorage().define(key, value);
602+
@Specialization
603+
Object doNativeClass(PythonNativeClass object, String key, Object value,
604+
@Exclusive @Cached("createForceType()") WriteAttributeToObjectNode writeAttrNode) {
605+
writeAttrNode.execute(object, key, value);
605606
return PNone.NONE;
606607
}
607608

608-
@Specialization
609-
Object setattr(PythonNativeClass object, String key, Object value,
610-
@Cached("createForceType()") WriteAttributeToObjectNode writeAttrNode) {
611-
writeAttrNode.execute(object, key, value);
609+
@Specialization(guards = {"!isPythonBuiltinClass(object)"})
610+
Object doObject(PythonObject object, String key, Object value,
611+
@Exclusive @Cached WriteAttributeToDynamicObjectNode writeAttrToDynamicObjectNode) {
612+
writeAttrToDynamicObjectNode.execute(object.getStorage(), key, value);
612613
return PNone.NONE;
613614
}
614615
}

0 commit comments

Comments
 (0)