From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A45C91F5AE for ; Sat, 12 Jun 2021 00:26:44 +0000 (UTC) Received: from localhost ([::1]:58764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrU3-0000Y3-81 for normalperson@yhbt.net; Fri, 11 Jun 2021 20:26:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTb-0008Jm-82 for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:15 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:39088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTY-0003lk-99 for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:14 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 16DC7160126 for ; Fri, 11 Jun 2021 17:26:11 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 11K8wci-90vW; Fri, 11 Jun 2021 17:26:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 13654160121; Fri, 11 Jun 2021 17:26:10 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Qt8I4nS1eu-m; Fri, 11 Jun 2021 17:26:09 -0700 (PDT) Received: from day.example.com (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id E1E6416011D; Fri, 11 Jun 2021 17:26:09 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH 05/13] exclude: prefer idx_t for most indexes Date: Fri, 11 Jun 2021 17:25:45 -0700 Message-Id: <20210612002553.1105537-5-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu> References: <20210612002553.1105537-1-eggert@cs.ucla.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * lib/exclude.c (struct exclude_pattern, free_exclude_segment) (file_pattern_matches, add_exclude, add_exclude_fp): Prefer idx_t to size_t for indexes, and use idx_t-related allocators. --- ChangeLog | 2 ++ lib/exclude.c | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index d02e4ce0d..1fca94c03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * lib/basename.c (base_name): * lib/dfa.c (mbs_to_wchar, state_index, dfaoptimize, dfaanalyze) (icatalloc, enlist, allocmust, dfamust): + * lib/exclude.c (struct exclude_pattern, free_exclude_segment) + (file_pattern_matches, add_exclude, add_exclude_fp): Prefer idx_t to size_t for indexes, and use idx_t-related allocators. * lib/basename.c: Do not include xstrndup.h. (basename): Simplify by always using memcpy. diff --git a/lib/exclude.c b/lib/exclude.c index 6287fbc68..417ab23d1 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -88,8 +88,8 @@ struct patopts struct exclude_pattern { struct patopts *exclude; - size_t exclude_alloc; - size_t exclude_count; + idx_t exclude_alloc; + idx_t exclude_count; }; =20 enum exclude_type @@ -281,12 +281,10 @@ new_exclude_segment (struct exclude *ex, enum exclu= de_type type, int options) static void free_exclude_segment (struct exclude_segment *seg) { - size_t i; - switch (seg->type) { case exclude_pattern: - for (i =3D 0; i < seg->v.pat.exclude_count; i++) + for (idx_t i =3D 0; i < seg->v.pat.exclude_count; i++) { if (seg->v.pat.exclude[i].options & EXCLUDE_REGEX) regfree (&seg->v.pat.exclude[i].v.re); @@ -407,11 +405,10 @@ exclude_patopts (struct patopts const *opts, char c= onst *f) static bool file_pattern_matches (struct exclude_segment const *seg, char const *f) { - size_t exclude_count =3D seg->v.pat.exclude_count; + idx_t exclude_count =3D seg->v.pat.exclude_count; struct patopts const *exclude =3D seg->v.pat.exclude; - size_t i; =20 - for (i =3D 0; i < exclude_count; i++) + for (idx_t i =3D 0; i < exclude_count; i++) { if (exclude_patopts (exclude + i, f)) return true; @@ -533,8 +530,8 @@ add_exclude (struct exclude *ex, char const *pattern,= int options) =20 pat =3D &seg->v.pat; if (pat->exclude_count =3D=3D pat->exclude_alloc) - pat->exclude =3D x2nrealloc (pat->exclude, &pat->exclude_alloc, - sizeof *pat->exclude); + pat->exclude =3D xpalloc (pat->exclude, &pat->exclude_alloc, 1, = -1, + sizeof *pat->exclude); patopts =3D &pat->exclude[pat->exclude_count++]; =20 patopts->options =3D options; @@ -547,7 +544,7 @@ add_exclude (struct exclude *ex, char const *pattern,= int options) if (options & FNM_LEADING_DIR) { char *tmp; - size_t len =3D strlen (pattern); + idx_t len =3D strlen (pattern); =20 while (len > 0 && ISSLASH (pattern[len-1])) --len; @@ -556,7 +553,7 @@ add_exclude (struct exclude *ex, char const *pattern,= int options) rc =3D 1; else { - tmp =3D xmalloc (len + 7); + tmp =3D ximalloc (len + 7); memcpy (tmp, pattern, len); strcpy (tmp + len, "(/.*)?"); rc =3D regcomp (&patopts->v.re, tmp, cflags); @@ -617,22 +614,22 @@ add_exclude_fp (void (*add_func) (struct exclude *,= char const *, int, void *), char *p; char *pattern; char const *lim; - size_t buf_alloc =3D 0; - size_t buf_count =3D 0; + idx_t buf_alloc =3D 0; + idx_t buf_count =3D 0; int c; int e =3D 0; =20 while ((c =3D getc (fp)) !=3D EOF) { if (buf_count =3D=3D buf_alloc) - buf =3D x2realloc (buf, &buf_alloc); + buf =3D xpalloc (buf, &buf_alloc, 1, -1, 1); buf[buf_count++] =3D c; } =20 if (ferror (fp)) e =3D errno; =20 - buf =3D xrealloc (buf, buf_count + 1); + buf =3D xirealloc (buf, buf_count + 1); buf[buf_count] =3D line_end; lim =3D buf + buf_count + ! (buf_count =3D=3D 0 || buf[buf_count - 1] = =3D=3D line_end); =20 --=20 2.30.2