From a85906c75683de95a8a999552822fd86870ab2b7 Mon Sep 17 00:00:00 2001 From: "J.W. Schultz" Date: Fri, 6 Feb 2004 10:00:33 +0000 Subject: [PATCH] Start flist with a more reasonable size, grow it linearly once it reaches a largish size (16 million files) and make it actually match the comments so it may be used to initialize flists of known size (create_flist_from_batch()). --- batch.c | 7 ++----- flist.c | 58 ++++++++++++++++++++++++++++++++------------------------- rsync.h | 7 ++++++- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/batch.c b/batch.c index aa601306..d90c87b9 100644 --- a/batch.c +++ b/batch.c @@ -144,11 +144,8 @@ struct file_list *create_flist_from_batch(void) save_pv = protocol_version; protocol_version = read_int(f); - batch_flist->count = batch_flist->malloced = read_int(f); - batch_flist->files = new_array(struct file_struct *, - batch_flist->malloced); - if (!batch_flist->files) - out_of_memory("create_flist_from_batch"); + batch_flist->count = read_int(f); + flist_expand(batch_flist); for (i = 0; (flags = read_byte(f)) != 0; i++) { if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS)) diff --git a/flist.c b/flist.c index 8505b9ba..f21adb7f 100644 --- a/flist.c +++ b/flist.c @@ -279,37 +279,45 @@ static int flist_dir_len; * Make sure @p flist is big enough to hold at least @p flist->count * entries. **/ -static void flist_expand(struct file_list *flist) +void flist_expand(struct file_list *flist) { - if (flist->count >= flist->malloced) { - void *new_ptr; + void *new_ptr; - if (flist->malloced < 1000) - flist->malloced += 1000; - else - flist->malloced *= 2; + if (flist->count < flist->malloced) + return; - if (flist->files) { - new_ptr = realloc_array(flist->files, - struct file_struct *, - flist->malloced); - } else { - new_ptr = new_array(struct file_struct *, - flist->malloced); - } + if (flist->malloced < FLIST_START) + flist->malloced = FLIST_START; + else if (flist->malloced >= FLIST_LINEAR) + flist->malloced += FLIST_LINEAR; + else + flist->malloced *= 2; + + /* + * In case count jumped or we are starting the list + * with a known size just set it. + */ + if (flist->malloced < flist->count) + flist->malloced = flist->count; + + if (flist->files) { + new_ptr = realloc_array(flist->files, + struct file_struct *, flist->malloced); + } else { + new_ptr = new_array(struct file_struct *, flist->malloced); + } - if (verbose >= 2) { - rprintf(FINFO, "[%s] expand file_list to %.0f bytes, did%s move\n", - who_am_i(), - (double) sizeof flist->files[0] * flist->malloced, - (new_ptr == flist->files) ? " not" : ""); - } + if (verbose >= 2) { + rprintf(FINFO, "[%s] expand file_list to %.0f bytes, did%s move\n", + who_am_i(), + (double) sizeof flist->files[0] * flist->malloced, + (new_ptr == flist->files) ? " not" : ""); + } - flist->files = (struct file_struct **) new_ptr; + flist->files = (struct file_struct **) new_ptr; - if (!flist->files) - out_of_memory("flist_expand"); - } + if (!flist->files) + out_of_memory("flist_expand"); } void send_file_entry(struct file_struct *file, int f, unsigned short base_flags) diff --git a/rsync.h b/rsync.h index 61e5f06b..15066258 100644 --- a/rsync.h +++ b/rsync.h @@ -428,7 +428,12 @@ struct file_struct { uchar flags; /* this item MUST remain last */ }; -#define ARENA_SIZE (32 * 1024) +/* + * Start the flist array at FLIST_START entries and grow it + * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR + */ +#define FLIST_START (32 * 1024) +#define FLIST_LINEAR (FLIST_START * 512) struct string_area { char *base; -- 2.34.1