bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23717: [PATCH 6/6] grep: do pagesize initialization and buffer alloc


From: Zev Weiss
Subject: bug#23717: [PATCH 6/6] grep: do pagesize initialization and buffer allocation earlier
Date: Tue, 7 Jun 2016 01:37:43 -0500

* src/grep.c (reset, main): We're going to need pagesize and buffer
initialized anyway, so we might as well do so unconditionally early on
rather than checking on every call to reset().
---
 src/grep.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index d01bc4f..302e4d7 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -769,16 +769,6 @@ all_zeros (char const *buf, size_t size)
 static bool
 reset (int fd, struct stat const *st)
 {
-  if (! pagesize)
-    {
-      pagesize = getpagesize ();
-      if (pagesize == 0 || 2 * pagesize + 1 <= pagesize)
-        abort ();
-      bufalloc = (ALIGN_TO (INITIAL_BUFSIZE, pagesize)
-                  + pagesize + sizeof (uword));
-      buffer = xmalloc (bufalloc);
-    }
-
   bufbeg = buflim = ALIGN_TO (buffer + 1, pagesize);
   bufbeg[-1] = eolbyte;
   bufdesc = fd;
@@ -2252,6 +2242,12 @@ main (int argc, char **argv)
   set_program_name (argv[0]);
   program_name = argv[0];
 
+  pagesize = getpagesize ();
+  if (pagesize == 0 || 2 * pagesize + 1 <= pagesize)
+    abort ();
+  bufalloc = (ALIGN_TO (INITIAL_BUFSIZE, pagesize) + pagesize + sizeof 
(uword));
+  buffer = xmalloc (bufalloc);
+
   keys = NULL;
   keycc = 0;
   with_filenames = false;
-- 
2.8.0.rc3






reply via email to

[Prev in Thread] Current Thread [Next in Thread]