[Python-Dev] Simple dicts (original) (raw)

Guido van Rossum guido@python.org
Thu, 15 May 2003 20:27:58 -0400


There seem to be two different ways to get/set/del from a dictionary.

The first is using PyDict[Get|Set|Del]Item()

This is the API that all C code uses (except code that doesn't know whether it's dealing with dicts or some other mapping, which has to use PyObject_GetItem() etc, which is even slower).

The second is using the embarssingly named dictasssub() and its partner dictsubscript().

This is what PyObject_GetItem() calls.

Which of these two access methods is most likely to be used?

That's a hard question. Maybe a profiler can answer. The thing is, there's a lot of C code that calls PyDict_GetItem() directly, e.g. the attribute lookup code. Bot of course there's also a lot of Python code using dicts.

Yet, I'd bet on PyDict_*().

--Guido van Rossum (home page: http://www.python.org/~guido/)