bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH 05/13] exclude: prefer idx_t for most indexes
Date: Fri, 11 Jun 2021 17:25:45 -0700	[thread overview]
Message-ID: <20210612002553.1105537-5-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu>

* 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;
   };
 
 enum exclude_type
@@ -281,12 +281,10 @@ new_exclude_segment (struct exclude *ex, enum exclude_type type, int options)
 static void
 free_exclude_segment (struct exclude_segment *seg)
 {
-  size_t i;
-
   switch (seg->type)
     {
     case exclude_pattern:
-      for (i = 0; i < seg->v.pat.exclude_count; i++)
+      for (idx_t i = 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 const *f)
 static bool
 file_pattern_matches (struct exclude_segment const *seg, char const *f)
 {
-  size_t exclude_count = seg->v.pat.exclude_count;
+  idx_t exclude_count = seg->v.pat.exclude_count;
   struct patopts const *exclude = seg->v.pat.exclude;
-  size_t i;
 
-  for (i = 0; i < exclude_count; i++)
+  for (idx_t i = 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)
 
       pat = &seg->v.pat;
       if (pat->exclude_count == pat->exclude_alloc)
-        pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc,
-                                   sizeof *pat->exclude);
+        pat->exclude = xpalloc (pat->exclude, &pat->exclude_alloc, 1, -1,
+                                sizeof *pat->exclude);
       patopts = &pat->exclude[pat->exclude_count++];
 
       patopts->options = 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 = strlen (pattern);
+              idx_t len = strlen (pattern);
 
               while (len > 0 && ISSLASH (pattern[len-1]))
                 --len;
@@ -556,7 +553,7 @@ add_exclude (struct exclude *ex, char const *pattern, int options)
                 rc = 1;
               else
                 {
-                  tmp = xmalloc (len + 7);
+                  tmp = ximalloc (len + 7);
                   memcpy (tmp, pattern, len);
                   strcpy (tmp + len, "(/.*)?");
                   rc = 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 = 0;
-  size_t buf_count = 0;
+  idx_t buf_alloc = 0;
+  idx_t buf_count = 0;
   int c;
   int e = 0;
 
   while ((c = getc (fp)) != EOF)
     {
       if (buf_count == buf_alloc)
-        buf = x2realloc (buf, &buf_alloc);
+        buf = xpalloc (buf, &buf_alloc, 1, -1, 1);
       buf[buf_count++] = c;
     }
 
   if (ferror (fp))
     e = errno;
 
-  buf = xrealloc (buf, buf_count + 1);
+  buf = xirealloc (buf, buf_count + 1);
   buf[buf_count] = line_end;
   lim = buf + buf_count + ! (buf_count == 0 || buf[buf_count - 1] == line_end);
 
-- 
2.30.2



  parent reply	other threads:[~2021-06-12  0:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12  0:25 [PATCH 01/13] ialloc: new module Paul Eggert
2021-06-12  0:25 ` [PATCH 02/13] xalloc: new idx_t-based allocators Paul Eggert
2021-06-12  0:25 ` [PATCH 03/13] dirname: prefer idx_t for some indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 04/13] dfa: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` Paul Eggert [this message]
2021-06-12  0:25 ` [PATCH 06/13] getusershell: " Paul Eggert
2021-06-12  0:25 ` [PATCH 07/13] linebuffer: " Paul Eggert
2021-06-12  0:25 ` [PATCH 08/13] readtokens: " Paul Eggert
2021-06-12  0:25 ` [PATCH 09/13] readutmp: " Paul Eggert
2021-06-12  0:25 ` [PATCH 10/13] savedir: " Paul Eggert
2021-06-12  0:25 ` [PATCH 11/13] stack: " Paul Eggert
2021-06-13 10:19   ` Bruno Haible
2021-06-13 17:47     ` Paul Eggert
2021-06-12  0:25 ` [PATCH 12/13] userspec: " Paul Eggert
2021-06-12  0:25 ` [PATCH 13/13] xgethostname: " Paul Eggert
2021-06-13 10:05 ` [PATCH 01/13] ialloc: new module Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210612002553.1105537-5-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).