Skip to content
Snippets Groups Projects
Commit 40af54f3e718 authored by Nick Wellnhofer's avatar Nick Wellnhofer
Browse files

Don't cache direct evaluation of patterns with variables

The slow pattern matching path in xsltTestCompMatchDirect caches the
result of evaluating the pattern. But this can't be done if the pattern
contains variables which could evaluate to different values.

Only enable the cache for patterns like template matches that don't
allow variable references. Don't use the cache for "count" and "from"
patterns in xsl:number.

A more fine-grained approach would be nice, but most effort should be
spent on eliminating the slow path completely.

Thanks to Martin Honnen for the report.

Fixes #6.
parent ca070b2fa27a
Branches
No related tags found
No related merge requests found
......@@ -113,6 +113,7 @@
xmlNsPtr *nsList; /* the namespaces in scope */
int nsNr; /* the number of namespaces in scope */
xsltStepOpPtr steps; /* ops for computation */
int novar; /* doesn't contain variables */
};
typedef struct _xsltParserContext xsltParserContext;
......@@ -594,7 +595,8 @@
}
ix = 0;
if ((parent == NULL) || (node->doc == NULL) || isRVT)
if ((parent == NULL) || (node->doc == NULL) || isRVT ||
(comp->novar == 0))
nocache = 1;
if (nocache == 0) {
......@@ -1970,6 +1972,7 @@
j++;
}
element->nsNr = j;
element->novar = novar;
#ifdef WITH_XSLT_DEBUG_PATTERN
......
<root>
<element type="a"/>
<element type="b"/>
<element type="a"/>
</root>
<?xml version="1.0"?>
<root>
<element type="a" pos="1"/>
<element type="b" pos="1"/>
<element type="a" pos="2"/>
</root>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@type]">
<xsl:copy>
<xsl:variable name="type" select="@type"/>
<xsl:variable name="pos">
<xsl:number count="node()[@type = $type]"/>
</xsl:variable>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="pos">
<xsl:value-of select="$pos"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment