texinfo-commits
[Top][All Lists]
Advanced

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

[5565] remove closure argument of process_node_text


From: Gavin D. Smith
Subject: [5565] remove closure argument of process_node_text
Date: Wed, 14 May 2014 16:13:12 +0000

Revision: 5565
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5565
Author:   gavin
Date:     2014-05-14 16:13:10 +0000 (Wed, 14 May 2014)
Log Message:
-----------
remove closure argument of process_node_text

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/display.c
    trunk/info/info.h
    trunk/info/window.c
    trunk/info/window.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-14 14:48:22 UTC (rev 5564)
+++ trunk/ChangeLog     2014-05-14 16:13:10 UTC (rev 5565)
@@ -1,5 +1,19 @@
 2014-05-14  Gavin Smith  <address@hidden>
 
+       * info/window.c (process_node_text): First argument changed from
+       void * to WINDOW *.  Callers updated.
+       * info/display.c (display_node_text):
+       * info/window.c (_calc_line_starts): Receive WINDOW * argument.
+       * info/window.h (WINDOW): New field line_slots.
+
+       * info/info.h (add_pointer_to_array): Work for integer types.
+       * info/info.h (add_element_to_array): Synonym for add_pointer_to_array.
+
+       * info/display.c (struct display_node_closure): Removed.
+       * info/window.c (struct calc_closure, calc_closure_expand): Removed.
+
+2014-05-14  Gavin Smith  <address@hidden>
+
        * info/window.h (WINDOW): line_starts changed to pointer to
        (array of) offsets.  This stops the need to write expressions like
        "win->line_starts[line] - win->node->contents" in many places.  All

Modified: trunk/info/display.c
===================================================================
--- trunk/info/display.c        2014-05-14 14:48:22 UTC (rev 5564)
+++ trunk/info/display.c        2014-05-14 16:13:10 UTC (rev 5565)
@@ -88,11 +88,6 @@
   display_update_one_window (the_echo_area);
 }
 
-struct display_node_closure {
-  WINDOW *win;
-  DISPLAY_LINE **display;
-};
-
 static int
 find_diff (const char *a, size_t alen, const char *b, size_t blen, int *ppos)
 {
@@ -112,14 +107,13 @@
   return i;
 }
 
+/* Called by process_node_text. */
 int
-display_node_text (void *closure, size_t pl_num, size_t ll_num,
+display_node_text (WINDOW *win, size_t pl_num, size_t ll_num,
                    size_t pl_start, char *printed_line,
                    size_t pl_bytes, size_t pl_chars)
 {
-  struct display_node_closure *dn = closure;
-  WINDOW *win = dn->win;
-  DISPLAY_LINE **display = dn->display;
+  DISPLAY_LINE **display = the_display;
   DISPLAY_LINE *entry = display[win->first_row + pl_num];
 
   /* We have the exact line as it should appear on the screen.
@@ -230,17 +224,11 @@
 
   if (win->node && win->line_starts)
     {
-      struct display_node_closure dnc;
-
-      dnc.win = win;
-      dnc.display = the_display;
-      
       line_index = process_node_text (win,
                                      win->node->contents
                                         + win->line_starts[win->pagetop],
                                      1,
-                                     display_node_text,
-                                     &dnc);
+                                     display_node_text);
       if (display_was_interrupted_p)
        return;
     }

Modified: trunk/info/info.h
===================================================================
--- trunk/info/info.h   2014-05-14 14:48:22 UTC (rev 5564)
+++ trunk/info/info.h   2014-05-14 16:13:10 UTC (rev 5565)
@@ -57,11 +57,11 @@
 #  define whitespace_or_newline(c) (whitespace (c) || (c == '\n'))
 #endif /* !whitespace_or_newline */
 
-/* Add POINTER to the list of pointers found in ARRAY.  SLOTS is the number
+/* Add ELT to the list of elements found in ARRAY.  SLOTS is the number
    of slots that have already been allocated.  INDEX is the index into the
-   array where POINTER should be added.  MINSLOTS is the number of slots to
+   array where ELT should be added.  MINSLOTS is the number of slots to
    start the array with in case it is empty. */
-#define add_pointer_to_array(pointer, idx, array, slots, minslots)     \
+#define add_pointer_to_array(elt, idx, array, slots, minslots) \
   do                                                                   \
     {                                                                  \
        if (idx + 2 >= slots)                                           \
@@ -70,11 +70,13 @@
             slots = minslots;                                          \
           array = x2nrealloc (array, &slots, sizeof(array[0]));        \
         }                                                              \
-       array[idx++] = pointer;                                         \
-       array[idx] = NULL;                                              \
+       array[idx++] = elt;                                             \
+       array[idx] = 0; /* null pointer for pointer types */            \
     }                                                                  \
   while (0)
 
+#define add_element_to_array add_pointer_to_array
+
 #if !defined (zero_mem) && defined (HAVE_MEMSET)
 #  define zero_mem(mem, length) memset (mem, 0, length)
 #endif /* !zero_mem && HAVE_MEMSET */

Modified: trunk/info/window.c
===================================================================
--- trunk/info/window.c 2014-05-14 14:48:22 UTC (rev 5564)
+++ trunk/info/window.c 2014-05-14 16:13:10 UTC (rev 5565)
@@ -817,60 +817,36 @@
 }
 
 
-struct calc_closure {
-  WINDOW *win;
-  size_t line_starts_slots;
-};
-
-static void
-calc_closure_expand (struct calc_closure *cp)
-{
-  if (cp->win->line_count == cp->line_starts_slots)
-    {
-      if (cp->line_starts_slots == 0)
-       cp->line_starts_slots = 100;
-      cp->win->line_starts = x2nrealloc (cp->win->line_starts,
-                                        &cp->line_starts_slots,
-                                        sizeof (cp->win->line_starts[0]));
-      cp->win->log_line_no = xrealloc (cp->win->log_line_no,
-                                    cp->line_starts_slots *
-                                    sizeof (cp->win->log_line_no[0]));
-    }
-}
-
+/* Called by process_node_text. */
 static int
-_calc_line_starts (void *closure, size_t pl_num, size_t ll_num,
+_calc_line_starts (WINDOW *win, size_t pl_num, size_t ll_num,
                    size_t pl_start, char *printed_line,
                    size_t pl_bytes, size_t pl_chars)
 {
-  struct calc_closure *cp = closure;
+  add_element_to_array (pl_start, win->line_count,
+                        win->line_starts, win->line_slots, 2);
 
-  calc_closure_expand (cp);
-  cp->win->line_starts[cp->win->line_count] = pl_start;
-  cp->win->log_line_no[cp->win->line_count] = ll_num;
-  cp->win->line_count++;
+  /* We cannot do add_element_to_array for this, as this would lead
+     to incrementing cp->win->line_count twice. */
+  win->log_line_no = xrealloc (win->log_line_no,
+                               win->line_slots * sizeof (long));
+  win->log_line_no[win->line_count - 1] = ll_num;
   return 0;
 }
 
 void
 calculate_line_starts (WINDOW *window)
 {
-  struct calc_closure closure;
-
   window->line_starts = NULL;
-  window->log_line_no  = NULL;
+  window->log_line_no = NULL;
   window->line_count = 0;
+  window->line_slots = 0;
 
   if (!window->node)
     return;
   
-  closure.win = window;
-  closure.line_starts_slots = 0;
-  process_node_text (window, window->node->contents, 0,
-                    _calc_line_starts, &closure);
-  calc_closure_expand (&closure);
-  window->line_starts[window->line_count] = 0;
-  window->log_line_no[window->line_count] = 0;
+  process_node_text (window, window->node->contents, 0, _calc_line_starts);
+
   window_line_map_init (window);
 }
 
@@ -1452,11 +1428,11 @@
 
    FUN is called for every line collected from the node. Its arguments:
 
-     int (*fun) (void *closure, size_t pl_num, size_t ll_num,
+     int (*fun) (WINDOW *win, size_t pl_num, size_t ll_num,
                   size_t pl_start, char *printed_line,
                  size_t pl_bytes, size_t pl_chars)
 
-     closure  -- An opaque pointer passed as 5th parameter to 
process_node_text;
+     win -- WINDOW argument passed to process_node_text;
      pl_num  -- Number of processed physical lines (starts from 0);
      ll_num -- Number of processed logical lines (starts from 0);
      pl_start -- Offset of start of physical line from START;
@@ -1475,9 +1451,8 @@
 size_t
 process_node_text (WINDOW *win, char *start,
                   int do_tags,
-                  int (*fun) (void *, size_t, size_t,
-                              size_t, char *, size_t, size_t),
-                  void *closure)
+                  int (*fun) (WINDOW *, size_t, size_t,
+                              size_t, char *, size_t, size_t))
 {
   char *printed_line;      /* Buffer for a printed line. */
   size_t pl_chars = 0;     /* Number of *characters* written to PRINTED_LINE */
@@ -1614,8 +1589,7 @@
               printed_line[pl_bytes] = '\0';
             }
 
-         finish = fun (closure, pl_num, ll_num,
-                       pl_start,
+         finish = fun (win, pl_num, ll_num, pl_start,
                        printed_line, pl_bytes, pl_chars);
 
           ++pl_num;
@@ -1661,9 +1635,7 @@
     }
 
   if (pl_chars)
-    fun (closure, pl_num, ll_num,
-         pl_start,
-        printed_line, pl_bytes, pl_chars);
+    fun (win, pl_num, ll_num, pl_start, printed_line, pl_bytes, pl_chars);
 
   free (printed_line);
   return ll_num; /* needed? */

Modified: trunk/info/window.h
===================================================================
--- trunk/info/window.h 2014-05-14 14:48:22 UTC (rev 5564)
+++ trunk/info/window.h 2014-05-14 16:13:10 UTC (rev 5565)
@@ -80,6 +80,7 @@
   long *log_line_no;    /* Number of logical line corresponding to each
                            physical one. */
   long line_count;      /* Number of elements in LINE_STARTS and LOG_LINE_NO.*/
+  size_t line_slots;    /* Allocated space in LINE_STARTS and LOG_LINE_NO. */
 
   int flags;            /* See below for details. */
 } WINDOW;
@@ -274,12 +275,9 @@
 
 extern size_t process_node_text
         (WINDOW *win, char *start, int do_tags,
-         int (*fun) (void *, size_t, size_t, size_t, char *,
-                    size_t, size_t),
-        void *closure);
+         int (*fun) (WINDOW *, size_t, size_t, size_t, char *,
+                    size_t, size_t));
 
-extern void clean_manpage (char *manpage);
-
 extern void window_compute_line_map (WINDOW *win);
 
 extern int window_point_to_column (WINDOW *win, long point, long *np);




reply via email to

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