summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-07-05 23:27:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-07-05 23:27:44 (GMT)
commitb48d6a63ffdba18a0fab80f3458632dcf01e2bea (patch)
tree1f81296828298fce6cd8ec72b2b59b2623c9c359 /Objects
parent73799b181ea13949be2e008f431fdd0fab15d7f1 (diff)
downloadcpython-b48d6a63ffdba18a0fab80f3458632dcf01e2bea.zip
cpython-b48d6a63ffdba18a0fab80f3458632dcf01e2bea.tar.gz
cpython-b48d6a63ffdba18a0fab80f3458632dcf01e2bea.tar.bz2
Bring related functions add/contains/discard together in the code.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index fd10008..307f19e 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -366,17 +366,14 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
}
static int
-set_add_key(PySetObject *so, PyObject *key)
+set_contains_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
{
- Py_hash_t hash;
+ setentry *entry;
- if (!PyUnicode_CheckExact(key) ||
- (hash = ((PyASCIIObject *) key)->hash) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
- }
- return set_add_entry(so, key, hash);
+ entry = set_lookkey(so, key, hash);
+ if (entry != NULL)
+ return entry->key != NULL;
+ return -1;
}
#define DISCARD_NOTFOUND 0
@@ -402,11 +399,37 @@ set_discard_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
}
static int
-set_discard_key(PySetObject *so, PyObject *key)
+set_add_key(PySetObject *so, PyObject *key)
{
Py_hash_t hash;
- assert (PyAnySet_Check(so));
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyASCIIObject *) key)->hash) == -1) {
+ hash = PyObject_Hash(key);
+ if (hash == -1)
+ return -1;
+ }
+ return set_add_entry(so, key, hash);
+}
+
+static int
+set_contains_key(PySetObject *so, PyObject *key)
+{
+ Py_hash_t hash;
+
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyASCIIObject *) key)->hash) == -1) {
+ hash = PyObject_Hash(key);
+ if (hash == -1)
+ return -1;
+ }
+ return set_contains_entry(so, key, hash);
+}
+
+static int
+set_discard_key(PySetObject *so, PyObject *key)
+{
+ Py_hash_t hash;
if (!PyUnicode_CheckExact(key) ||
(hash = ((PyASCIIObject *) key)->hash) == -1) {
@@ -653,35 +676,6 @@ set_merge(PySetObject *so, PyObject *otherset)
return 0;
}
-static int
-set_contains_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
-{
- setentry *lu_entry;
-
- lu_entry = set_lookkey(so, key, hash);
- if (lu_entry != NULL)
- return lu_entry->key != NULL;
- return -1;
-}
-
-static int
-set_contains_key(PySetObject *so, PyObject *key)
-{
- setentry *entry;
- Py_hash_t hash;
-
- if (!PyUnicode_CheckExact(key) ||
- (hash = ((PyASCIIObject *) key)->hash) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
- }
- entry = set_lookkey(so, key, hash);
- if (entry == NULL)
- return -1;
- return entry->key != NULL;
-}
-
static PyObject *
set_pop(PySetObject *so)
{