bug-findutils
[Top][All Lists]
Advanced

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

Re: [Patch] Locate: Move counting and limit-checking into visitors.


From: Bas van Gompel
Subject: Re: [Patch] Locate: Move counting and limit-checking into visitors.
Date: Fri, 24 Jun 2005 20:14:41 +0200 (MET DST)
User-agent: slrn/0.9.8.1 (Win32) Hamster/2.0.6.0 KorrNews/4.2

Op Thu, 23 Jun 2005 06:06:28 +0100 schreef James Youngman
in <address@hidden>:
:  On Thu, Jun 23, 2005 at 05:47:47AM +0200, Buzz wrote:
:
: > I've since done some testing. The speed-gain is only ca. 0.5%.
: > The difference in binary-size is however also tiny.
: >
: > If, when you're back, you say you /still/ prefer to do without
: > visit_found, I'll prepare another patch.
:
:  That's what I would prefer, to be honest.

So here goes. (You /have/ taken note of my objections?)

:  (the hotel has an SSH client!)
Imagine that. :)


Another suggested ChangeLog-entry:

2005-06-24  Bas van Gompel  <address@hidden>

        * locate/locate.c (visit_count, visit_limit): New functions.
        (locate): Use visit_limit or visit_count. Simplify main loop.
        (main) Bail out early when limit is reached.


diff --exclude='*~' -Ndrup curr/findutils/locate/locate.c 
mine2/findutils/locate/locate.c
--- findutils/locate/locate.c   2005-06-13 01:12:56.000000000 +0200
+++ findutils/locate/locate.c   2005-06-24 16:07:02.000000000 +0200
@@ -748,6 +748,30 @@ visit_stats(struct process_data *procdat
 }
 
 
+static int
+visit_limit(struct process_data *procdata, void *context)
+{
+  struct locate_limits *p = context;
+
+  (void) procdata;
+
+  if (++p->items_accepted >= p->limit)
+    return VISIT_ABORT;
+  else
+    return VISIT_CONTINUE;
+}
+
+static int
+visit_count(struct process_data *procdata, void *context)
+{
+  struct locate_limits *p = context;
+
+  (void) procdata;
+
+  ++p->items_accepted;
+  return VISIT_CONTINUE;
+}
+
 /* Emit the statistics.
  */
 static void
@@ -785,8 +809,8 @@ print_stats(int argc, size_t database_fi
 }
 
 
-/* Print the entries in DBFILE that match shell globbing patterns in ARGV.
-   Return the number of entries printed.  */
+/* Print or count the entries in DBFILE that match shell globbing patterns in
+   ARGV. Return the number of entries matched. */
 
 static unsigned long
 locate (int argc,
@@ -798,6 +822,7 @@ locate (int argc,
        int use_limit,
        struct locate_limits *plimit,
        int stats,
+       int do_count,
        int op_and,
        int regex)
 {
@@ -989,7 +1014,13 @@ locate (int argc,
       else
        add_visitor(visit_justprint_unquoted, NULL);
     }
-  
+
+
+  if (use_limit)
+    add_visitor(visit_limit, plimit);
+  else
+    add_visitor(visit_count, plimit);
+
 
   if (argc > 1)
     {
@@ -1008,24 +1039,17 @@ locate (int argc,
               procdata.dbfile,
               old_format ? _("old") : "LOCATE02");
     }
-  
+
+
   procdata.c = getc (procdata.fp);
-  while ( (procdata.c != EOF) && (!use_limit || (plimit->limit > 0)) )
-    {
+  /* If we are searching for filename patterns, the inspector list 
+   * will contain an entry for each pattern for which we are searching.
+   */
+  while ( (procdata.c != EOF) &&
+          (VISIT_ABORT != (mainprocessor)(&procdata)) )
+    /* Do nothing */ ;
 
-      /* If we are searching for filename patterns, the inspector list 
-       * will contain an entry for each pattern for which we are searching.
-       */
-      if ((VISIT_ACCEPTED | VISIT_CONTINUE) & (mainprocessor)(&procdata))
-       {
-         if ((++plimit->items_accepted >= plimit->limit) && use_limit)
-           {
-             break;
-           }
-       }
-    }
 
-      
   if (stats)
     {
       print_stats(argc, st.st_size);
@@ -1251,7 +1275,10 @@ main (int argc, char **argv)
     stdout_is_a_tty = false;
 
   next_element (dbpath, 0);    /* Initialize.  */
-  while ((e = next_element ((char *) NULL, 0)) != NULL)
+
+  /* Bail out early if limit already reached. */
+  while ((e = next_element ((char *) NULL, 0)) != NULL  &&
+        (!use_limit || limits.limit > limits.items_accepted))
     {
       statistics.compressed_bytes = 
       statistics.total_filename_count = 
@@ -1269,7 +1296,7 @@ main (int argc, char **argv)
          e = LOCATE_DB;
        }
          
-      found = locate (argc - optind, &argv[optind], e, ignore_case, print, 
basename_only, use_limit, &limits, stats, op_and, regex);
+      found = locate (argc - optind, &argv[optind], e, ignore_case, print, 
basename_only, use_limit, &limits, stats, just_count, op_and, regex);
     }
   
   if (just_count)


L8r,

Buzz.
-- 
  ) |  | ---/ ---/  Yes, this | This message consists of true | I do not
--  |  |   /    /   really is |   and false bits entirely.    | mail for
  ) |  |  /    /    a 72 by 4 +-------------------------------+ any1 but
--  \--| /--- /---  .sigfile. |   |perl -pe "s.u(z)\1.as."    | me. 4^re




reply via email to

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