[Python-checkins] r52962 - python/trunk/Objects/setobject.c

raymond.hettinger python-checkins at python.org
Fri Dec 8 04:17:20 CET 2006


Author: raymond.hettinger
Date: Fri Dec 8 04:17:18 2006
New Revision: 52962
Modified:
 python/trunk/Objects/setobject.c
Log:
Eliminate two redundant calls to PyObject_Hash().
Modified: python/trunk/Objects/setobject.c
==============================================================================
--- python/trunk/Objects/setobject.c	(original)
+++ python/trunk/Objects/setobject.c	Fri Dec 8 04:17:18 2006
@@ -1164,7 +1164,19 @@
 	}
 
 	while ((key = PyIter_Next(it)) != NULL) {
-		int rv = set_contains_key(so, key);
+		int rv;
+		setentry entry;
+		long hash = PyObject_Hash(key);
+
+		if (hash == -1) {
+			Py_DECREF(it);
+			Py_DECREF(result);
+			Py_DECREF(key);
+			return NULL;
+		}
+		entry.hash = hash;
+		entry.key = key;
+		rv = set_contains_entry(so, &entry);
 		if (rv == -1) {
 			Py_DECREF(it);
 			Py_DECREF(result);
@@ -1172,7 +1184,7 @@
 			return NULL;
 		}
 		if (rv) {
-			if (set_add_key(result, key) == -1) {
+			if (set_add_entry(result, &entry) == -1) {
 				Py_DECREF(it);
 				Py_DECREF(result);
 				Py_DECREF(key);
@@ -1383,11 +1395,18 @@
 		PyObject *value;
 		int rv;
 		while (PyDict_Next(other, &pos, &key, &value)) {
-			rv = set_discard_key(so, key);
+			setentry an_entry;
+			long hash = PyObject_Hash(key);
+
+			if (hash == -1)
+				return NULL;
+			an_entry.hash = hash;
+			an_entry.key = key;
+			rv = set_discard_entry(so, &an_entry);
 			if (rv == -1)
 				return NULL;
 			if (rv == DISCARD_NOTFOUND) {
-				if (set_add_key(so, key) == -1)
+				if (set_add_entry(so, &an_entry) == -1)
 					return NULL;
 			}
 		}


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /