[issue2159] dbmmodule inquiry function is performance prohibitive

Eric Olson report at bugs.python.org
Wed Apr 30 06:02:11 CEST 2014


Eric Olson added the comment:

Hi Jesús,

I believe the patch should have this behavior:
  a) If the database is closed, raise an exception.
  b) If database is empty, return False.
  c) If database has any entry, return True. Fast and simply checking if the database has at least a single record.

The 0/1 appears to be converted to Py_TRUE/Py_FALSE in PyObject_IsTrue() in boolobject.c.
  

For background, here's the code path I'm seeing:

bool_new(...)                        (in Objects/boolobject.c)
  ...
  ok = PyObject_IsTrue(obj)          (in Objects/object.c)
  ...
  return PyBool_FromLong(ok)


Looking at PyObject_IsTrue is informative.  It shows that since tp_as_number->nb_bool is defined (as dbm_bool), it is used instead of the old default of tp_as_mapping->mp_length.


I'm still learning CPython, and I'm not sure if everything goes through bool_new(), but I think this makes sense.  If you see more places I can/should look for details here, let me know.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2159>
_______________________________________


More information about the Python-bugs-list mailing list