Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 73628 invoked by uid 500); 2 Dec 2001 04:22:06 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 73616 invoked from network); 2 Dec 2001 04:22:05 -0000 Date: Sat, 01 Dec 2001 20:18:58 -0800 From: Brian Pane Subject: [PATCH] optimization for apr_array_copy To: dev@apr.apache.org Message-id: <3C09ABB2.1070701@pacbell.net> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_GzqEdZxYvB6b8iUUN5Ac/Q)" X-Accept-Language: en-us User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.6) Gecko/20011120 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --Boundary_(ID_GzqEdZxYvB6b8iUUN5Ac/Q) Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT apr_array_copy() makes a new array, fills it with null bytes, and then overwrites it with a copy of the source array. This patch optimizes away the zero-fill of the part of the array that's about to be overwritten. --Brian --Boundary_(ID_GzqEdZxYvB6b8iUUN5Ac/Q) Content-type: text/plain; name=array_patch.txt Content-transfer-encoding: 7BIT Content-disposition: inline; filename=array_patch.txt Index: srclib/apr/tables/apr_tables.c =================================================================== RCS file: /home/cvspublic/apr/tables/apr_tables.c,v retrieving revision 1.19 diff -u -r1.19 apr_tables.c --- srclib/apr/tables/apr_tables.c 2001/11/26 23:17:09 1.19 +++ srclib/apr/tables/apr_tables.c 2001/12/02 03:56:52 @@ -167,10 +167,14 @@ APR_DECLARE(apr_array_header_t *) apr_array_copy(apr_pool_t *p, const apr_array_header_t *arr) { - apr_array_header_t *res = apr_array_make(p, arr->nalloc, arr->elt_size); + apr_array_header_t *res = + (apr_array_header_t *) apr_palloc(p, sizeof(apr_array_header_t)); + make_array_core(res, p, arr->nalloc, arr->elt_size, 0); memcpy(res->elts, arr->elts, arr->elt_size * arr->nelts); res->nelts = arr->nelts; + memset(res->elts + res->elt_size * res->nelts, 0, + res->elt_size * (res->nalloc - res->nelts)); return res; } --Boundary_(ID_GzqEdZxYvB6b8iUUN5Ac/Q)--