STINNER Victor added the comment:

"Reuse _Py_hashtable for the methods cache is not trivial, the API doesn't fit 
exactly. I didn't spend much time to try to adapt _Py_hashtable API or the 
methods cache."

I don't understand which part is the key and which part is the enetry data in 
method_cache_entry structure:

struct method_cache_entry {
    unsigned int version;
    PyObject *name;             /* reference to exactly a str or None */
    PyObject *value;            /* borrowed */
};

_PyType_Lookup() compares name and version. Does it mean that version is part 
of the key?

If it's possible to only store name as the key and store version and value in 
the data, it would be simple to reuse _Py_hashtable. I guess that it would be 
possible to get a cache entry using the name and later compare the version, it 
the version doesn't match: don't use the cache. It would require to copy the 
data (version+value: short structure, a few bytes) from the hash table entry to 
a local variable (allocated in the stack).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18874>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to