internalize all text node content from stylesheet documents with the
authorDaniel Veillard <veillard@src.gnome.org>
Sat, 22 Jan 2005 10:26:08 +0000 (10:26 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Sat, 22 Jan 2005 10:26:08 +0000 (10:26 +0000)
* libxslt/xslt.c: internalize all text node content from
  stylesheet documents with the stylesheet dictionnary
Daniel

ChangeLog
libxslt/xslt.c

index e0641b1..2df345b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jan 22 11:24:43 CET 2005 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/xslt.c: internalize all text node content from
+         stylesheet documents with the stylesheet dictionnary
+
 Fri Jan 21 12:04:18 HKT 2005 William Brack <wbrack@mmm.com.hk>
 
        * tests/plugins/Makefile.am: Applied patch 11 (with small
index e8dc26c..2e501da 100644 (file)
@@ -1178,6 +1178,11 @@ xsltParseStylesheetExcludePrefix(xsltStylesheetPtr style, xmlNodePtr cur) {
 static void
 xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
     xmlNodePtr delete;
+    int internalize = 0;
+
+    if ((style != NULL) && (cur != NULL) && (cur->doc != NULL) &&
+        (style->dict != NULL) && (cur->doc->dict == style->dict))
+       internalize = 1;
 
     /*
      * This content comes from the stylesheet
@@ -1198,6 +1203,33 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
        if (cur->type == XML_ELEMENT_NODE) {
            int exclPrefixes;
 
+           /*
+            * Internalize attributes values.
+            */
+           if ((internalize) && (cur->properties != NULL)) {
+               xmlAttrPtr prop = cur->properties;
+               xmlNodePtr txt;
+
+               while (prop != NULL) {
+                   txt = prop->children;
+                   if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
+                       (txt->content != NULL) &&
+                       (!xmlDictOwns(style->dict, txt->content))) {
+                       xmlChar *old = (xmlChar *) txt->content;
+
+                       /*
+                        * internalize the text string, goal is to speed
+                        * up operations and minimize used space by compiled
+                        * stylesheets.
+                        */
+                       txt->content = (xmlChar *)
+                                      xmlDictLookup(style->dict, old, -1);
+                       xmlFree(old);
+                   }
+                   prop = prop->next;
+               }
+           }
+
            exclPrefixes = xsltParseStylesheetExcludePrefix(style, cur);
            if (IS_XSLT_ELEM(cur)) {
                xsltStylePreCompute(style, cur);
@@ -1264,6 +1296,17 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur) {
                if (xmlNodeGetSpacePreserve(cur) != 1) {
                    delete = cur;
                }
+           } else if ((cur->content != NULL) && (internalize) &&
+                      (!xmlDictOwns(style->dict, cur->content))) {
+               xmlChar *old = (xmlChar *) cur->content;
+
+               /*
+                * internalize the text string, goal is to speed
+                * up operations and minimize used space by compiled
+                * stylesheets.
+                */
+               cur->content = (xmlChar *) xmlDictLookup(style->dict, old, -1);
+               xmlFree(old);
            }
        } else if ((cur->type != XML_ELEMENT_NODE) &&
                   (cur->type != XML_CDATA_SECTION_NODE)) {