output: Cache the script ltr versus rtl direction.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 1 Jan 2019 05:50:16 +0000 (21:50 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 1 Jan 2019 06:19:40 +0000 (22:19 -0800)
A profiling run showed that about 10% of the rendering time was occupied
with repeated calls to render_direction_rtl().  This caches the result.

src/output/ascii.c
src/output/cairo.c
src/output/render.c
src/output/render.h

index fd580107e3be30a8df60ed7533fe69c966d25e9b..7c4e5244eaa97bdf16d58e4ce22fbb9202823b20 100644 (file)
@@ -202,6 +202,7 @@ struct ascii_driver
     struct u8_line *lines;      /* Page content. */
     int allocated_lines;        /* Number of lines allocated. */
     int chart_cnt;              /* Number of charts so far. */
+    struct render_params params;
   };
 
 static const struct output_driver_class ascii_driver_class;
@@ -278,6 +279,27 @@ ascii_create (struct  file_handle *fh, enum settings_output_devices device_type,
   a->allocated_lines = 0;
   a->chart_cnt = 1;
 
+  a->params.draw_line = ascii_draw_line;
+  a->params.measure_cell_width = ascii_measure_cell_width;
+  a->params.measure_cell_height = ascii_measure_cell_height;
+  a->params.adjust_break = NULL;
+  a->params.draw_cell = ascii_draw_cell;
+  a->params.aux = a;
+  a->params.size[H] = a->width;
+  a->params.size[V] = INT_MAX;
+  a->params.font_size[H] = 1;
+  a->params.font_size[V] = 1;
+  for (int i = 0; i < RENDER_N_LINES; i++)
+    {
+      int width = i == RENDER_LINE_NONE ? 0 : 1;
+      a->params.line_widths[H][i] = width;
+      a->params.line_widths[V][i] = width;
+    }
+  for (int i = 0; i < TABLE_N_AXES; i++)
+    a->params.min_break[i] = a->min_break[i];
+  a->params.supports_margins = false;
+  a->params.rtl = render_direction_rtl ();
+
   if (!update_page_size (a, true))
     goto error;
 
@@ -326,8 +348,8 @@ update_page_size (struct ascii_driver *a, bool issue_error)
 
   if (a->auto_width)
     {
-      a->width = settings_get_viewwidth ();
-      a->min_break[H] = a->width / 2;
+      a->params.size[H] = a->width = settings_get_viewwidth ();
+      a->params.min_break[H] = a->min_break[H] = a->width / 2;
     }
 
   if (a->width < MIN_WIDTH)
@@ -339,7 +361,7 @@ update_page_size (struct ascii_driver *a, bool issue_error)
                MIN_WIDTH,
                a->width);
       if (a->width < MIN_WIDTH)
-        a->width = MIN_WIDTH;
+        a->params.size[H] = a->width = MIN_WIDTH;
       return false;
     }
 
@@ -390,38 +412,16 @@ static void
 ascii_output_table_item (struct ascii_driver *a,
                          const struct table_item *table_item)
 {
-  struct render_params params;
   struct render_pager *p;
-  int i;
 
   update_page_size (a, false);
 
-  params.draw_line = ascii_draw_line;
-  params.measure_cell_width = ascii_measure_cell_width;
-  params.measure_cell_height = ascii_measure_cell_height;
-  params.adjust_break = NULL;
-  params.draw_cell = ascii_draw_cell;
-  params.aux = a;
-  params.size[H] = a->width;
-  params.size[V] = INT_MAX;
-  params.font_size[H] = 1;
-  params.font_size[V] = 1;
-  for (i = 0; i < RENDER_N_LINES; i++)
-    {
-      int width = i == RENDER_LINE_NONE ? 0 : 1;
-      params.line_widths[H][i] = width;
-      params.line_widths[V][i] = width;
-    }
-  for (i = 0; i < TABLE_N_AXES; i++)
-    params.min_break[i] = a->min_break[i];
-  params.supports_margins = false;
-
   if (a->file)
     putc ('\n', a->file);
   else if (!ascii_open_page (a))
     return;
 
-  p = render_pager_create (&params, table_item);
+  p = render_pager_create (&a->params, table_item);
   for (int i = 0; render_pager_has_next (p); i++)
     {
       if (i)
index 147b83e647d2fe7482afe2800ea841ca21d07097..61944624a7ee088f040349e591ada53edd4468ba 100644 (file)
@@ -425,6 +425,7 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
       for (i = 0; i < TABLE_N_AXES; i++)
         xr->params->min_break[i] = xr->min_break[i];
       xr->params->supports_margins = true;
+      xr->params->rtl = render_direction_rtl ();
     }
 
   cairo_set_source_rgb (xr->cairo, xr->fg.red, xr->fg.green, xr->fg.blue);
index 23ef9927275be3f119077075d46e98efcc078dff..239d0c68ad5c9581e8d7411feec54617daec5382 100644 (file)
@@ -952,7 +952,7 @@ render_rule (const struct render_page *page, const int ofs[TABLE_N_AXES],
 
       bb[H][0] = ofs[H] + page->cp[H][d[H]];
       bb[H][1] = ofs[H] + page->cp[H][d[H] + 1];
-      if (render_direction_rtl ())
+      if (page->params->rtl)
        {
          int temp = bb[H][0];
          bb[H][0] = render_page_get_size (page, H) - bb[H][1];
@@ -974,7 +974,7 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES],
 
   bb[H][0] = clip[H][0] = ofs[H] + page->cp[H][cell->d[H][0] * 2 + 1];
   bb[H][1] = clip[H][1] = ofs[H] + page->cp[H][cell->d[H][1] * 2];
-  if (render_direction_rtl ())
+  if (page->params->rtl)
     {
       int temp = bb[H][0];
       bb[H][0] = clip[H][0] = render_page_get_size (page, H) - bb[H][1];
index 600bfd93449982e3608b717e029a787964a6ad10..c10f23716060924897da482dc106128fbd5cdcf3 100644 (file)
@@ -125,7 +125,14 @@ struct render_params
        points.) */
     int min_break[TABLE_N_AXES];
 
+    /* True if the driver supports cell margins.  (If false, the rendering
+       engine will insert a small space betweeen adjacent cells that don't have
+       an intervening rule.)  */
     bool supports_margins;
+
+    /* True if the local language has a right-to-left direction, otherwise
+       false.  (Use render_direction_rtl() to find out.) */
+    bool rtl;
   };
 
 /* An iterator for breaking render_pages into smaller chunks. */