diff options
author | Guido van Rossum <guido@python.org> | 1991-06-04 19:35:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-06-04 19:35:24 (GMT) |
commit | b8393da8f845ff4018781d926f157bdb7bff7c1c (patch) | |
tree | 1bcaa240a6170e55ff3cf6ec86333c0f3e5a8a95 /Objects | |
parent | 85e3b01f3b2c4cf8b217b5238d1ee4e9269969d0 (diff) | |
download | cpython-b8393da8f845ff4018781d926f157bdb7bff7c1c.zip cpython-b8393da8f845ff4018781d926f157bdb7bff7c1c.tar.gz cpython-b8393da8f845ff4018781d926f157bdb7bff7c1c.tar.bz2 |
Finally implement tuple*number. From now on all sequence types
must (pretend to) support all operations except assignments;
if you don't want to support an operation you have to provide
a dummy function that raises an exception...
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/tupleobject.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 02d77a2..de242b1 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -259,10 +259,42 @@ tupleconcat(a, bb) #undef b } +static object * +tuplerepeat(a, n) + tupleobject *a; + int n; +{ + int i, j; + int size; + tupleobject *np; + object **p; + if (n < 0) + n = 0; + if (a->ob_size*n == a->ob_size) { + /* Since tuples are immutable, we can return a shared + copy in this case */ + INCREF(a); + return (object *)a; + } + size = a->ob_size * n; + np = (tupleobject *) newtupleobject(size); + if (np == NULL) + return NULL; + p = np->ob_item; + for (i = 0; i < n; i++) { + for (j = 0; j < a->ob_size; j++) { + *p = a->ob_item[j]; + INCREF(*p); + p++; + } + } + return (object *) np; +} + static sequence_methods tuple_as_sequence = { tuplelength, /*sq_length*/ tupleconcat, /*sq_concat*/ - 0, /*sq_repeat*/ + tuplerepeat, /*sq_repeat*/ tupleitem, /*sq_item*/ tupleslice, /*sq_slice*/ 0, /*sq_ass_item*/ |