Micro optimizations after staring at gprof output for a while.
This commit is contained in:
parent
54cf12b625
commit
4d0277233e
|
@ -566,8 +566,8 @@ PyDict_GetItem(PyObject *op, PyObject *key)
|
||||||
PyThreadState *tstate;
|
PyThreadState *tstate;
|
||||||
if (!PyDict_Check(op))
|
if (!PyDict_Check(op))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!PyString_CheckExact(key) ||
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
(hash = ((PyStringObject *) key)->ob_shash) == -1)
|
(hash = ((PyUnicodeObject *) key)->hash) == -1)
|
||||||
{
|
{
|
||||||
hash = PyObject_Hash(key);
|
hash = PyObject_Hash(key);
|
||||||
if (hash == -1) {
|
if (hash == -1) {
|
||||||
|
@ -650,12 +650,9 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
|
||||||
assert(key);
|
assert(key);
|
||||||
assert(value);
|
assert(value);
|
||||||
mp = (dictobject *)op;
|
mp = (dictobject *)op;
|
||||||
if (PyString_CheckExact(key)) {
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
hash = ((PyStringObject *)key)->ob_shash;
|
(hash = ((PyUnicodeObject *) key)->hash) == -1)
|
||||||
if (hash == -1)
|
{
|
||||||
hash = PyObject_Hash(key);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hash = PyObject_Hash(key);
|
hash = PyObject_Hash(key);
|
||||||
if (hash == -1)
|
if (hash == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -6597,9 +6597,10 @@ unicode_hash(PyUnicodeObject *self)
|
||||||
/* Since Unicode objects compare equal to their UTF-8 string
|
/* Since Unicode objects compare equal to their UTF-8 string
|
||||||
counterparts, we hash the UTF-8 string. */
|
counterparts, we hash the UTF-8 string. */
|
||||||
PyObject *v = _PyUnicode_AsDefaultEncodedString((PyObject*)self, NULL);
|
PyObject *v = _PyUnicode_AsDefaultEncodedString((PyObject*)self, NULL);
|
||||||
long x = PyObject_Hash(v);
|
if (v == NULL)
|
||||||
self->hash = x;
|
return -1;
|
||||||
return x;
|
assert(PyString_CheckExact(v));
|
||||||
|
return self->hash = v->ob_type->tp_hash(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue