diff options
author | Guido van Rossum <guido@python.org> | 1995-01-26 22:59:43 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-26 22:59:43 (GMT) |
commit | a46d51d9a44663c7fa0dac7a3b5f0d13ad44cae2 (patch) | |
tree | 569f354372857c5e1f48b34497c6e6fe3a114470 | |
parent | 69785032358a007fbcf56e62c0acea59db79431f (diff) | |
download | cpython-a46d51d9a44663c7fa0dac7a3b5f0d13ad44cae2.zip cpython-a46d51d9a44663c7fa0dac7a3b5f0d13ad44cae2.tar.gz cpython-a46d51d9a44663c7fa0dac7a3b5f0d13ad44cae2.tar.bz2 |
round up list item counts to improve realloc performance
-rw-r--r-- | Objects/listobject.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index ecf4645..f0eab0b 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -33,6 +33,20 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <sys/types.h> /* For size_t */ #endif +#define ROUNDUP(n, block) ((((n)+(block)-1)/(block))*(block)) + +static int +roundup(n) + int n; +{ + if (n < 500) + return ROUNDUP(n, 10); + else + return ROUNDUP(n, 100); +} + +#define NRESIZE(var, type, nitems) RESIZE(var, type, roundup(nitems)) + object * newlistobject(size) int size; @@ -135,7 +149,7 @@ ins1(self, where, v) return -1; } items = self->ob_item; - RESIZE(items, object *, self->ob_size+1); + NRESIZE(items, object *, self->ob_size+1); if (items == NULL) { err_nomem(); return -1; @@ -421,12 +435,12 @@ list_ass_slice(a, ilow, ihigh, v) for (/*k = ihigh*/; k < a->ob_size; k++) item[k+d] = item[k]; a->ob_size += d; - RESIZE(item, object *, a->ob_size); /* Can't fail */ + NRESIZE(item, object *, a->ob_size); /* Can't fail */ a->ob_item = item; } } else { /* Insert d items; recycle ihigh-ilow items */ - RESIZE(item, object *, a->ob_size + d); + NRESIZE(item, object *, a->ob_size + d); if (item == NULL) { XDEL(recycle); err_nomem(); |