Skip to content

Commit 5cb71b2

Browse files
committed
Update catom to use fastcalls
1 parent 9b80362 commit 5cb71b2

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

atom/src/catom.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,18 @@ CAtom_get_member( PyObject* self, PyObject* name )
189189

190190

191191
PyObject*
192-
CAtom_observe( CAtom* self, PyObject* args )
192+
CAtom_observe( CAtom* self, PyObject*const *args, Py_ssize_t n )
193193
{
194-
const size_t n = PyTuple_GET_SIZE( args );
195194
if( n < 2 || n > 3)
196195
return cppy::type_error( "observe() takes exactly 2 or 3 arguments" );
197-
PyObject* topic = PyTuple_GET_ITEM( args, 0 );
198-
PyObject* callback = PyTuple_GET_ITEM( args, 1 );
196+
PyObject* topic = args[0];
197+
PyObject* callback = args[1];
199198
if( !PyCallable_Check( callback ) )
200199
return cppy::type_error( callback, "callable" );
201200
uint8_t change_types = ChangeType::Any;
202201
if ( n == 3 )
203202
{
204-
PyObject* types = PyTuple_GET_ITEM( args, 2 );
203+
PyObject* types = args[2];
205204
if( !PyLong_Check( types ) )
206205
return cppy::type_error( types, "int" );
207206
change_types = PyLong_AsLong( types ) & 0xFF;
@@ -300,17 +299,15 @@ _CAtom_unobserve_2( CAtom* self, PyObject* topic, PyObject* callback )
300299

301300

302301
PyObject*
303-
CAtom_unobserve( CAtom* self, PyObject* args )
302+
CAtom_unobserve( CAtom* self, PyObject*const *args, Py_ssize_t n_args )
304303
{
305-
Py_ssize_t n_args = PyTuple_GET_SIZE( args );
306-
if( n_args > 2 )
307-
return cppy::type_error( "unobserve() takes at most 2 arguments" );
308304
if( n_args == 0 )
309305
return _CAtom_unobserve_0( self );
310306
if( n_args == 1 )
311-
return _CAtom_unobserve_1( self, PyTuple_GET_ITEM( args, 0 ) );
312-
return _CAtom_unobserve_2( self, PyTuple_GET_ITEM( args, 0 ),
313-
PyTuple_GET_ITEM( args, 1 ) );
307+
return _CAtom_unobserve_1( self, args[0] );
308+
if ( n_args == 2)
309+
return _CAtom_unobserve_2( self, args[0], args[1] );
310+
return cppy::type_error( "unobserve() takes at most 2 arguments" );
314311
}
315312

316313

@@ -322,12 +319,12 @@ CAtom_has_observers( CAtom* self, PyObject* topic )
322319

323320

324321
PyObject*
325-
CAtom_has_observer( CAtom* self, PyObject* args )
322+
CAtom_has_observer( CAtom* self, PyObject*const *args, Py_ssize_t n )
326323
{
327-
if( PyTuple_GET_SIZE( args ) != 2 )
324+
if( n != 2 )
328325
return cppy::type_error( "has_observer() takes exactly 2 arguments" );
329-
PyObject* topic = PyTuple_GET_ITEM( args, 0 );
330-
PyObject* callback = PyTuple_GET_ITEM( args, 1 );
326+
PyObject* topic = args[0];
327+
PyObject* callback = args[1];
331328
if( !utils::str_check( topic ) )
332329
return cppy::type_error( topic, "str" );
333330
if( !PyCallable_Check( callback ) )
@@ -448,11 +445,8 @@ CAtom_getstate( CAtom* self )
448445
}
449446

450447
PyObject*
451-
CAtom_setstate( CAtom* self, PyObject* args )
448+
CAtom_setstate( CAtom* self, PyObject* state )
452449
{
453-
if( PyTuple_GET_SIZE( args ) != 1 )
454-
return cppy::type_error( "__setstate__() takes exactly one argument" );
455-
PyObject* state = PyTuple_GET_ITEM( args, 0 );
456450
cppy::ptr itemsptr = PyMapping_Items(state);
457451
if ( !itemsptr )
458452
return 0;
@@ -488,13 +482,13 @@ CAtom_methods[] = {
488482
"Enable or disable notifications for the atom." },
489483
{ "get_member", ( PyCFunction )CAtom_get_member, METH_O,
490484
"Get the named member for the atom." },
491-
{ "observe", ( PyCFunction )CAtom_observe, METH_VARARGS,
485+
{ "observe", ( PyCFunction )CAtom_observe, METH_FASTCALL,
492486
"Register an observer callback to observe changes on the given topic(s)." },
493-
{ "unobserve", ( PyCFunction )CAtom_unobserve, METH_VARARGS,
487+
{ "unobserve", ( PyCFunction )CAtom_unobserve, METH_FASTCALL,
494488
"Unregister an observer callback for the given topic(s)." },
495489
{ "has_observers", ( PyCFunction )CAtom_has_observers, METH_O,
496490
"Get whether the atom has observers for a given topic." },
497-
{ "has_observer", ( PyCFunction )CAtom_has_observer, METH_VARARGS,
491+
{ "has_observer", ( PyCFunction )CAtom_has_observer, METH_FASTCALL,
498492
"Get whether the atom has the given observer for a given topic." },
499493
{ "notify", ( PyCFunction )CAtom_notify, METH_VARARGS | METH_KEYWORDS,
500494
"Call the registered observers for a given topic with positional and keyword arguments." },
@@ -504,7 +498,7 @@ CAtom_methods[] = {
504498
"__sizeof__() -> size of object in memory, in bytes" },
505499
{ "__getstate__", ( PyCFunction )CAtom_getstate, METH_NOARGS,
506500
"The base implementation of the pickle getstate protocol." },
507-
{ "__setstate__", ( PyCFunction )CAtom_setstate, METH_VARARGS,
501+
{ "__setstate__", ( PyCFunction )CAtom_setstate, METH_O,
508502
"The base implementation of the pickle setstate protocol." },
509503
{ 0 } // sentinel
510504
};

0 commit comments

Comments
 (0)