changeset 980:11c6f887d649

reduce number of styleEngine::style0() calls Rearrange code, so that for each new element, StyleEngine::setNonCssHints() is called before the first call to StyleEngine::style() or StyleEngine::wordStyle(). This avoids unnecessary CSS style computations which are expensive. Add an assertion to ensure this.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 05 Mar 2009 14:43:11 +0100
parents b3987cabf220
children 99e2a3ee8cd9
files ChangeLog src/html.cc src/styleengine.cc src/table.cc
diffstat 4 files changed, 36 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 04 18:28:34 2009 -0300
+++ b/ChangeLog	Thu Mar 05 14:43:11 2009 +0100
@@ -63,6 +63,7 @@
  - Add support for font-size and font-weight enum values.
  - Added "font_max_size", "font_min_size" dillorc options.
  - Add workaround for fltk bug #2062.
+ - Reduce number of styleEngine::style0() calls.
    Patches: Johannes Hofmann
 +- Updated the GPL copyright note in the source files.
    Patch: Detlef Riekenberg
--- a/src/html.cc	Wed Mar 04 18:28:34 2009 -0300
+++ b/src/html.cc	Thu Mar 05 14:43:11 2009 +0100
@@ -1712,6 +1712,9 @@
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "vlink")))
       html->visited_color = a_Html_color_parse(html, attrbuf, -1);
 
+   html->styleEngine->setNonCssHints (&props);
+   html->dw->setStyle (html->styleEngine->style ());
+
    if (prefs.contrast_visited_color) {
       /* get a color that has a "safe distance" from text, link and bg */
       html->visited_color =
@@ -1721,9 +1724,6 @@
                        S_TOP(html)->current_bg_color);
    }
 
-   html->styleEngine->setNonCssHints (&props);
-   html->dw->setStyle (html->styleEngine->style ());
-
    S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_BODY;
 }
 
@@ -1747,15 +1747,16 @@
 {
    CssPropertyList props;
 
+   a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+   html->styleEngine->inheritBackgroundColor ();
+   html->styleEngine->setNonCssHints (&props);
+
    if ((html->InFlags & IN_LI) && !html->WordAfterLI) {
       /* ignore first parbreak after an empty <LI> */
       html->WordAfterLI = true;
    } else {
       DW2TB(html->dw)->addParbreak (9, html->styleEngine->wordStyle ());
    }
-   a_Html_tag_set_align_attr (html, &props, tag, tagsize);
-   html->styleEngine->inheritBackgroundColor ();
-   html->styleEngine->setNonCssHints (&props);
 }
 
 /*
@@ -2660,9 +2661,10 @@
                  size_bottom);
    }
 
+   html->styleEngine->setNonCssHints (&props);
+
    DW2TB(html->dw)->addParbreak (5, html->styleEngine->wordStyle ());
 
-   html->styleEngine->setNonCssHints (&props);
    hruler = new Ruler();
    hruler->setStyle (html->styleEngine->style ());
    DW2TB(html->dw)->addWidget (hruler, html->styleEngine->style ());
@@ -3337,7 +3339,6 @@
       Html_check_name_val(html, attrbuf, "id");
 
       html->styleEngine->setId(attrbuf);
-      Html_add_anchor(html, attrbuf);
    }
 
    if (tagsize >= 11 && (prefs.parse_embedded_css || prefs.load_stylesheets)) {
@@ -3353,12 +3354,6 @@
          html->styleEngine->setStyle (attrbuf);
    }
 
-  if (S_TOP(html)->parse_mode != DILLO_HTML_PARSE_MODE_PRE &&
-      html->styleEngine->style ()->whiteSpace == WHITE_SPACE_PRE) {
-     S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_PRE;
-     html->pre_column = 0;
-     html->PreFirstChar = true;
-  }
 }
 
 /*
@@ -3420,6 +3415,16 @@
       if (html->stop_parser)
          break;
 
+      if (S_TOP(html)->parse_mode != DILLO_HTML_PARSE_MODE_PRE &&
+         html->styleEngine->style ()->whiteSpace == WHITE_SPACE_PRE) {
+         S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_PRE;
+         html->pre_column = 0;
+         html->PreFirstChar = true;
+      }
+
+      if (html->styleEngine->getId ())
+         Html_add_anchor(html, html->styleEngine->getId ());
+
       /* Request inmediate close for elements with forbidden close tag. */
       /* TODO: XHTML always requires close tags. A simple implementation
        * of the commented clause below will make it work. */
--- a/src/styleengine.cc	Wed Mar 04 18:28:34 2009 -0300
+++ b/src/styleengine.cc	Thu Mar 05 14:43:11 2009 +0100
@@ -488,9 +488,17 @@
    CssPropertyList props, *styleAttributeProps = NULL;
    const char *styleAttribute =
       stack->getRef (stack->size () - 1)->styleAttribute;
-
    // get previous style from the stack
    StyleAttrs attrs = *stack->getRef (stack->size () - 2)->style;
+
+   // Ensure that StyleEngine::style0() has not been called before for
+   // this element.
+   // Style computation is expensive so limit it as much as possible.
+   // If this assertion is hit, you need to rearrange the code that is 
+   // doing styleEngine calls to call setNonCssHints() before calling
+   // style() or wordStyle() for each new element.
+   assert (stack->getRef (stack->size () - 1)->style == NULL);
+
    // reset values that are not inherited according to CSS
    attrs.resetValues ();
 
--- a/src/table.cc	Wed Mar 04 18:28:34 2009 -0300
+++ b/src/table.cc	Thu Mar 05 14:43:11 2009 +0100
@@ -48,7 +48,6 @@
    int cssLength;
 #endif
 
-   DW2TB(html->dw)->addParbreak (0, html->styleEngine->wordStyle ());
 
 #ifdef USE_TABLES
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "border")))
@@ -101,6 +100,8 @@
 
    html->styleEngine->setNonCssHints (&props);
 
+   DW2TB(html->dw)->addParbreak (0, html->styleEngine->wordStyle ());
+
    /* The style for the cells */
    table_cell_props = new CssPropertyList ();
    if (border > 0) {
@@ -172,17 +173,16 @@
          }
       }
 
+      if (a_Html_get_attr (html, tag, tagsize, "align")) {
+         S_TOP(html)->cell_text_align_set = TRUE;
+         a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+      }
+
       html->styleEngine->inheritBackgroundColor ();
       html->styleEngine->setNonCssHints (&props);
 
       ((dw::Table*)S_TOP(html)->table)->addRow (html->styleEngine->style ());
 
-      if (a_Html_get_attr (html, tag, tagsize, "align")) {
-         S_TOP(html)->cell_text_align_set = TRUE;
-         a_Html_tag_set_align_attr (html, &props, tag, tagsize);
-         html->styleEngine->setNonCssHints (&props);
-      }
-
       table_cell_props = new CssPropertyList (*S_TOP(html)->table_cell_props);
       if (bgcolor != -1) {
          table_cell_props->set (CSS_PROPERTY_BACKGROUND_COLOR,