Author: atsushi
Date: 2005-03-22 07:32:31 -0500 (Tue, 22 Mar 2005)
New Revision: 42101
Modified:
trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
trunk/mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs
trunk/mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs
trunk/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
trunk/mcs/class/System.XML/Mono.Xml.Xsl/MSXslScriptManager.cs
trunk/mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
trunk/mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs
Log:
2005-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
* IdPattern.cs, LocationPathPattern.cs :
Use XsltCompiledContext.GetNavCache() that returns reusable
navigator cache for each pattern, to avoid Clone() and not to leave
reference to already-done instance navigator.
* XslTransformProcessor.cs : now it looks safe to remove SetContext()
from each EvaluateXXX() methods.
* MsxslScriptManager.cs : not to leave reference to stylesheet
navigator, pass current node to Compile().
* XslCompiledContext.cs : Added GetNavCache() that returns reusable
navigator cache for each pattern, to avoid Clone() and not to leave
reference to already-done instance navigator.
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-03-22 11:26:13 UTC
(rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-03-22 12:32:31 UTC
(rev 42101)
@@ -1,3 +1,10 @@
+2005-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * IdPattern.cs, LocationPathPattern.cs :
+ Use XsltCompiledContext.GetNavCache() that returns reusable
+ navigator cache for each pattern, to avoid Clone() and not to leave
+ reference to already-done instance navigator.
+
2004-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
* Pattern.cs : Pattern.Compile() now uses XSLT pattern parser instead
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs 2005-03-22
11:26:13 UTC (rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs 2005-03-22
12:32:31 UTC (rev 42101)
@@ -35,6 +35,7 @@
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
+using Mono.Xml.Xsl;
namespace Mono.Xml.XPath {
internal class IdPattern : LocationPathPattern {
@@ -49,7 +50,7 @@
public override bool Matches (XPathNavigator node, XsltContext
ctx)
{
- XPathNavigator tmp = node.Clone ();
+ XPathNavigator tmp = ((XsltCompiledContext)
ctx).GetNavCache (this, node);
for (int i = 0; i < ids.Length; i++)
if (tmp.MoveToId (ids [i]) &&
tmp.IsSamePosition (node))
return true;
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs
2005-03-22 11:26:13 UTC (rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs
2005-03-22 12:32:31 UTC (rev 42101)
@@ -35,6 +35,7 @@
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
+using Mono.Xml.Xsl;
namespace Mono.Xml.XPath {
internal class LocationPathPattern : Pattern {
@@ -43,7 +44,6 @@
bool isAncestor;
NodeTest nodeTest;
ExprFilter filter;
- XPathNavigator previousNavigator;
public LocationPathPattern (NodeTest nodeTest)
{
@@ -100,19 +100,19 @@
if (filter == null && patternPrevious == null)
return true;
+ XPathNavigator tmpNav;
if (patternPrevious != null) {
+ tmpNav = ((XsltCompiledContext)
ctx).GetNavCache (this, node);
if (!isAncestor) {
- XPathNavigator parent = node.Clone ();
- parent.MoveToParent ();
- if (!patternPrevious.Matches (parent,
ctx))
+ tmpNav.MoveToParent ();
+ if (!patternPrevious.Matches (tmpNav,
ctx))
return false;
} else {
- XPathNavigator anc = node.Clone ();
while (true) {
- if (!anc.MoveToParent ())
+ if (!tmpNav.MoveToParent ())
return false;
- if (patternPrevious.Matches
(anc, ctx))
+ if (patternPrevious.Matches
(tmpNav, ctx))
break;
}
}
@@ -127,17 +127,10 @@
return filter.pred.EvaluateBoolean (new
NullIterator (node, ctx));
}
- XPathNavigator p = null;
- if (previousNavigator == node) {
- p = previousNavigator;
- p.MoveTo (node);
- } else {
- p = node.Clone ();
- previousNavigator = p;
- }
- p.MoveToParent ();
+ tmpNav = ((XsltCompiledContext) ctx).GetNavCache (this,
node);
+ tmpNav.MoveToParent ();
- BaseIterator matches = filter.EvaluateNodeSet (new
NullIterator (p, ctx));
+ BaseIterator matches = filter.EvaluateNodeSet (new
NullIterator (tmpNav, ctx));
while (matches.MoveNext ()) {
if (node.IsSamePosition (matches.Current))
Modified: trunk/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog 2005-03-22 11:26:13 UTC
(rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog 2005-03-22 12:32:31 UTC
(rev 42101)
@@ -1,5 +1,15 @@
2005-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XslTransformProcessor.cs : now it looks safe to remove SetContext()
+ from each EvaluateXXX() methods.
+ * MsxslScriptManager.cs : not to leave reference to stylesheet
+ navigator, pass current node to Compile().
+ * XslCompiledContext.cs : Added GetNavCache() that returns reusable
+ navigator cache for each pattern, to avoid Clone() and not to leave
+ reference to already-done instance navigator.
+
+2005-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* Compiler.cs : Now it holds XPath parser and XSLT pattern parser.
* XslKey.cs : Use XSLT pattern parser for match.
UsePattern is now "Use" (it is not a pattern).
Modified: trunk/mcs/class/System.XML/Mono.Xml.Xsl/MSXslScriptManager.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.Xsl/MSXslScriptManager.cs
2005-03-22 11:26:13 UTC (rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.Xsl/MSXslScriptManager.cs
2005-03-22 12:32:31 UTC (rev 42101)
@@ -55,7 +55,7 @@
string ns = c.Input.GetNamespace (s.ImplementsPrefix);
if (ns == null)
throw new XsltCompileException ("Specified
prefix for msxsl:script was not found: " + s.ImplementsPrefix, null, c.Input);
- scripts.Add (ns, s.Compile ());
+ scripts.Add (ns, s.Compile (c.Input));
}
enum ScriptingLanguage {
@@ -75,12 +75,10 @@
ScriptingLanguage language = ScriptingLanguage.JScript;
// default = JScript.
string implementsPrefix = null;
string code = null;
- XPathNavigator node;
Evidence evidence;
public MSXslScript (XPathNavigator nav, Evidence
evidence)
{
- node = nav.Clone ();
this.evidence = evidence;
code = nav.Value;
if (nav.MoveToFirstAttribute ()) {
@@ -127,7 +125,7 @@
get { return code; }
}
- public object Compile ()
+ public object Compile (XPathNavigator node)
{
string suffix = Guid.NewGuid ().ToString
().Replace ("-", String.Empty);
switch (this.language) {
Modified: trunk/mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
2005-03-22 11:26:13 UTC (rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
2005-03-22 12:32:31 UTC (rev 42101)
@@ -466,8 +466,6 @@
public object Evaluate (XPathExpression expr)
{
expr = CompiledStyle.ExpressionStore.PrepForExecution
(expr, this);
- expr.SetContext (XPathContext);
-
XPathNodeIterator itr = CurrentNodeset;
return itr.Current.Evaluate (expr, itr, XPathContext);
}
@@ -475,8 +473,6 @@
public string EvaluateString (XPathExpression expr)
{
expr = CompiledStyle.ExpressionStore.PrepForExecution
(expr, this);
- expr.SetContext (XPathContext);
-
XPathNodeIterator itr = CurrentNodeset;
return itr.Current.EvaluateString (expr, itr,
XPathContext);
}
@@ -484,8 +480,6 @@
public bool EvaluateBoolean (XPathExpression expr)
{
expr = CompiledStyle.ExpressionStore.PrepForExecution
(expr, this);
- expr.SetContext (XPathContext);
-
XPathNodeIterator itr = CurrentNodeset;
return itr.Current.EvaluateBoolean (expr, itr,
XPathContext);
}
@@ -493,8 +487,6 @@
public double EvaluateNumber (XPathExpression expr)
{
expr = CompiledStyle.ExpressionStore.PrepForExecution
(expr, this);
- expr.SetContext (XPathContext);
-
XPathNodeIterator itr = CurrentNodeset;
return itr.Current.EvaluateNumber (expr, itr,
XPathContext);
}
@@ -502,7 +494,6 @@
public XPathNodeIterator Select (XPathExpression expr)
{
expr = CompiledStyle.ExpressionStore.PrepForExecution
(expr, this);
- expr.SetContext (XPathContext);
return CurrentNodeset.Current.Select (expr,
XPathContext);
}
Modified: trunk/mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs
2005-03-22 11:26:13 UTC (rev 42100)
+++ trunk/mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs
2005-03-22 12:32:31 UTC (rev 42101)
@@ -59,6 +59,7 @@
Hashtable keyNameCache = new Hashtable ();
Hashtable keyIndexTables = new Hashtable ();
+ Hashtable patternNavCaches = new Hashtable ();
XslTransformProcessor p;
XsltContextInfo [] scopes = new XsltContextInfo [40];
@@ -74,6 +75,17 @@
public override string DefaultNamespace { get { return
String.Empty; }}
+ public XPathNavigator GetNavCache (Mono.Xml.XPath.Pattern p,
XPathNavigator node)
+ {
+ XPathNavigator nav =
+ patternNavCaches [p] as XPathNavigator;
+ if (nav == null || !nav.MoveTo (node)) {
+ nav = node.Clone ();
+ patternNavCaches [p] = nav;
+ }
+ return nav;
+ }
+
public object EvaluateKey (IStaticXsltContext staticContext,
BaseIterator iter,
Expression nameExpr, Expression valueExpr)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches