Skip to content

Commit 7030a07

Browse files
authored
Refactor postgetattr calls (#226)
1 parent 1f2a89a commit 7030a07

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

atom/src/postgetattrbehavior.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,23 @@ delegate_handler( Member* member, CAtom* atom, PyObject* value )
6363
PyObject*
6464
object_method_value_handler( Member* member, CAtom* atom, PyObject* value )
6565
{
66-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_getattr_context ) );
67-
if( !callable )
68-
return 0;
69-
cppy::ptr args( PyTuple_New( 1 ) );
70-
if( !args )
71-
return 0;
72-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( value ) );
73-
return callable.call( args );
66+
return PyObject_CallMethodOneArg( pyobject_cast( atom ), member->post_getattr_context, value );
7467
}
7568

7669

7770
PyObject*
7871
object_method_name_value_handler( Member* member, CAtom* atom, PyObject* value )
7972
{
80-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_getattr_context ) );
81-
if( !callable )
82-
return 0;
83-
cppy::ptr args( PyTuple_New( 2 ) );
84-
if( !args )
85-
return 0;
86-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( member->name ) );
87-
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( value ) );
88-
return callable.call( args );
73+
PyObject* args[] = { pyobject_cast( atom ), member->name, value };
74+
return PyObject_VectorcallMethod( member->post_getattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 );
8975
}
9076

9177

9278
PyObject*
9379
member_method_object_value_handler( Member* member, CAtom* atom, PyObject* value )
9480
{
95-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( member ), member->post_getattr_context ) );
96-
if( !callable )
97-
return 0;
98-
cppy::ptr args( PyTuple_New( 2 ) );
99-
if( !args )
100-
return 0;
101-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( pyobject_cast( atom ) ) );
102-
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( value ) );
103-
return callable.call( args );
81+
PyObject* args[] = { pyobject_cast( member ), pyobject_cast( atom ), value };
82+
return PyObject_VectorcallMethod( member->post_getattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 );
10483
}
10584

10685

0 commit comments

Comments
 (0)