summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-26 08:37:28 +0000
committerRaymond Hettinger <python@rcn.com>2008-01-26 08:37:28 +0000
commit81dd0582903e9502870fa776e599531631218b34 (patch)
tree09d388bbde9f8f9a6b7b6fc5c0ebb2e3b309ccb7
parentbfe8b07a7936f4eb163fef0a3dc35d7f83e7da41 (diff)
downloadcpython-81dd0582903e9502870fa776e599531631218b34.tar.gz
Let marshal build-up sets and frozensets one element at a time.
Saves the unnecessary creation of a tuple as intermediate container.
-rw-r--r--Python/marshal.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 0c611b618c..1b88ff964d 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -860,7 +860,7 @@ r_object(RFILE *p)
retval = NULL;
break;
}
- v = PyTuple_New((int)n);
+ v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
if (v == NULL) {
retval = NULL;
break;
@@ -875,18 +875,14 @@ r_object(RFILE *p)
v = NULL;
break;
}
- PyTuple_SET_ITEM(v, (int)i, v2);
+ if (PySet_Add(v, v2) == -1) {
+ Py_DECREF(v);
+ Py_DECREF(v2);
+ v = NULL;
+ break;
+ }
}
- if (v == NULL) {
- retval = NULL;
- break;
- }
- if (type == TYPE_SET)
- v3 = PySet_New(v);
- else
- v3 = PyFrozenSet_New(v);
- Py_DECREF(v);
- retval = v3;
+ retval = (v == NULL) ? NULL : v;
break;
case TYPE_CODE: