From: Wei Liu Subject: Re: [PATCH v4 18/21] libxlu: rework internal representation of setting Date: Thu, 12 Feb 2015 10:58:40 +0000 Message-ID: <20150212105839.GE13644@zion.uk.xensource.com> References: <1422011632-22018-1-git-send-email-wei.liu2@citrix.com> <1422011632-22018-19-git-send-email-wei.liu2@citrix.com> <21723.32616.827387.488083@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <21723.32616.827387.488083@mariner.uk.xensource.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: Ian Jackson Cc: Wei Liu , ian.campbell@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, xen-devel@lists.xen.org, JBeulich@suse.com, ufimtseva@gmail.com List-Id: xen-devel@lists.xenproject.org On Wed, Feb 11, 2015 at 04:12:24PM +0000, Ian Jackson wrote: > 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. > No problem. > Apart from that this all looks good to me. Thanks. Wei. > > Thanks, > Ian.