Преглед на файлове

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.


svn path=/trunk/mcs/; revision=42101
Atsushi Eno преди 21 години
родител
ревизия
e6503839bb

+ 7 - 0
mcs/class/System.XML/Mono.Xml.XPath/ChangeLog

@@ -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

+ 2 - 1
mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs

@@ -35,6 +35,7 @@ using System.Xml;
 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 @@ namespace Mono.Xml.XPath {
 		
 		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;

+ 10 - 17
mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs

@@ -35,6 +35,7 @@ using System.Xml;
 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 @@ namespace Mono.Xml.XPath {
 		bool isAncestor;
 		NodeTest nodeTest;
 		ExprFilter filter;
-		XPathNavigator previousNavigator;
 		
 		public LocationPathPattern (NodeTest nodeTest)
 		{
@@ -100,19 +100,19 @@ namespace Mono.Xml.XPath {
 			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 @@ namespace Mono.Xml.XPath {
 				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))

+ 10 - 0
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog

@@ -1,3 +1,13 @@
+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.

+ 2 - 4
mcs/class/System.XML/Mono.Xml.Xsl/MSXslScriptManager.cs

@@ -55,7 +55,7 @@ namespace Mono.Xml.Xsl {
 			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 @@ namespace Mono.Xml.Xsl {
 			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 @@ namespace Mono.Xml.Xsl {
 				get { return code; }
 			}
 			
-			public object Compile ()
+			public object Compile (XPathNavigator node)
 			{
 				string suffix = Guid.NewGuid ().ToString ().Replace ("-", String.Empty);
 				switch (this.language) {

+ 0 - 9
mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs

@@ -466,8 +466,6 @@ namespace Mono.Xml.Xsl {
 		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 @@ namespace Mono.Xml.Xsl {
 		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 @@ namespace Mono.Xml.Xsl {
 		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 @@ namespace Mono.Xml.Xsl {
 		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 @@ namespace Mono.Xml.Xsl {
 		public XPathNodeIterator Select (XPathExpression expr)
 		{
 			expr = CompiledStyle.ExpressionStore.PrepForExecution (expr, this);
-			expr.SetContext (XPathContext);
 			return CurrentNodeset.Current.Select (expr, XPathContext);
 		}
 		

+ 12 - 0
mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs

@@ -59,6 +59,7 @@ namespace Mono.Xml.Xsl
 
 		Hashtable keyNameCache = new Hashtable ();
 		Hashtable keyIndexTables = new Hashtable ();
+		Hashtable patternNavCaches = new Hashtable ();
 
 		XslTransformProcessor p;
 		XsltContextInfo [] scopes = new XsltContextInfo [40];
@@ -74,6 +75,17 @@ namespace Mono.Xml.Xsl
 
 		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)