From: Ian Jackson Subject: Re: [PATCH v4 18/21] libxlu: rework internal representation of setting Date: Wed, 11 Feb 2015 16:12:24 +0000 Message-ID: <21723.32616.827387.488083@mariner.uk.xensource.com> References: <1422011632-22018-1-git-send-email-wei.liu2@citrix.com> <1422011632-22018-19-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1422011632-22018-19-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.campbell@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, JBeulich@suse.com, ufimtseva@gmail.com List-Id: xen-devel@lists.xenproject.org Wei Liu writes ("[PATCH v4 18/21] libxlu: rework internal representation of setting"): > This patches does following things: ... > +void xlu__cfg_list_append(CfgParseContext *ctx, > + XLU_ConfigValue *list, > + char *atom) > +{ > + XLU_ConfigValue **new_val = NULL; > + XLU_ConfigValue *val = NULL; > if (ctx->err) return; ... > - if (set->nvalues >= set->avalues) { > - int new_avalues; > - char **new_values; > - > - if (set->avalues > INT_MAX / 100) { ctx->err= ERANGE; return; } > - new_avalues= set->avalues * 4; > - new_values= realloc(set->values, > - sizeof(*new_values) * new_avalues); > - if (!new_values) { ctx->err= errno; free(atom); return; } > - set->values= new_values; > - set->avalues= new_avalues; This is a standard expanding-array pattern which arranges not to realloc the array each time. > - } > - set->values[set->nvalues++]= atom; > + new_val = realloc(list->u.list.values, > + sizeof(*new_val) * (list->u.list.nvalues+1)); > + if (!new_val) goto xe; But you replace it here with one which has quadradic performance. I don't know whether people are going to specify lists with hundreds or thousands of elements, but it doesn't seem impossible. I think you should retain the existing avalues stuff. Apart from that this all looks good to me. Thanks, Ian.