Browse Source

2004-01-07 Atsushi Enomoto <[email protected]>

	* DTDObjectModel.cs, DTDReader.cs, XmlSecureResolver.cs :
	  avoiding obvious exception.
	* DTDReader.cs, XmlTextReader.cs : Some optimization.
	  Avoided extraneous PeekChar() and reduced name string creation.

svn path=/trunk/mcs/; revision=21797
Atsushi Eno 22 years ago
parent
commit
65b863c896

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

@@ -1,3 +1,10 @@
+2004-01-07  Atsushi Enomoto  <[email protected]>
+
+	* DTDObjectModel.cs, DTDReader.cs, XmlSecureResolver.cs :
+	  avoiding obvious exception.
+	* DTDReader.cs, XmlTextReader.cs : Some optimization. 
+	  Avoided extraneous PeekChar() and reduced name string creation.
+
 2004-01-05  David Sheldon <[email protected]>
   
   * XmlTextReader.cs: Fixed constructors taking string url to not

+ 2 - 1
mcs/class/System.XML/System.Xml/DTDObjectModel.cs

@@ -1057,7 +1057,8 @@ namespace Mono.Xml
 
 			Uri baseUri = null;
 			try {
-				baseUri = new Uri (BaseURI);
+//				if (BaseURI != null && BaseURI.Length > 0)
+					baseUri = new Uri (BaseURI);
 			} catch (UriFormatException) {
 			}
 

+ 31 - 33
mcs/class/System.XML/System.Xml/DTDReader.cs

@@ -137,7 +137,7 @@ namespace System.Xml
 		private bool ProcessDTDSubset ()
 		{
 			SkipWhitespace ();
-			switch(PeekChar ())
+			switch(ReadChar ())
 			{
 			case -1:
 				return false;
@@ -145,7 +145,6 @@ namespace System.Xml
 				// It affects on entity references' well-formedness
 				if (this.parserInputStack.Count == 0)
 					DTD.InternalSubsetHasPEReference = true;
-				ReadChar ();
 				string peName = ReadName ();
 				Expect (';');
 				currentInput.InsertParameterEntityBuffer (" ");
@@ -161,7 +160,6 @@ namespace System.Xml
 						"Incorrectly nested parameter entity.");
 				break;
 			case '<':
-				ReadChar ();
 				int c = ReadChar ();
 				switch(c)
 				{
@@ -182,7 +180,7 @@ namespace System.Xml
 				if (dtdIncludeSect == 0)
 					throw new XmlException (this as IXmlLineInfo, "Unbalanced end of INCLUDE/IGNORE section.");
 				// End of inclusion
-				Expect ("]]>");
+				Expect ("]>");
 				dtdIncludeSect--;
 				SkipWhitespace ();
 //				return false;
@@ -254,13 +252,11 @@ namespace System.Xml
 				// conditional sections
 				SkipWhitespace ();
 				TryExpandPERef ();
-				SkipWhitespace ();
-				Expect ('I');
+				ExpectAfterWhitespace ('I');
 				switch (ReadChar ()) {
 				case 'N':
 					Expect ("CLUDE");
-					SkipWhitespace ();
-					Expect ('[');
+					ExpectAfterWhitespace ('[');
 					dtdIncludeSect++;
 					break;
 				case 'G':
@@ -277,8 +273,7 @@ namespace System.Xml
 		private void ReadIgnoreSect ()
 		{
 			bool skip = false;
-			SkipWhitespace ();
-			Expect ('[');
+			ExpectAfterWhitespace ('[');
 			int dtdIgnoreSect = 1;
 			while (dtdIgnoreSect > 0) {
 				switch (skip ? PeekChar () : ReadChar ()) {
@@ -319,8 +314,7 @@ namespace System.Xml
 			SkipWhitespace ();
 			// This expanding is only allowed as a non-validating parser.
 			TryExpandPERef ();
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 			return decl;
 		}
 
@@ -329,19 +323,18 @@ namespace System.Xml
 		{
 			TryExpandPERef ();
 			SkipWhitespace ();
-			switch(PeekChar ())
+			switch(ReadChar ())
 			{
 			case 'E':
 				decl.IsEmpty = true;
-				Expect ("EMPTY");
+				Expect ("MPTY");
 				break;
 			case 'A':
 				decl.IsAny = true;
-				Expect ("ANY");
+				Expect ("NY");
 				break;
 			case '(':
 				DTDContentModel model = decl.ContentModel;
-				ReadChar ();
 				SkipWhitespace ();
 				TryExpandPERef ();
 				SkipWhitespace ();
@@ -478,8 +471,7 @@ namespace System.Xml
 						break;
 				}
 				while(true);
-				SkipWhitespace ();
-				Expect (')');
+				ExpectAfterWhitespace (')');
 			}
 			else {
 				TryExpandPERef ();
@@ -594,8 +586,7 @@ namespace System.Xml
 				decl.LiteralEntityValue = CreateValueString (); // currentTag.ToString (start, currentTag.Length - start - 1);
 				ClearValueBuffer ();
 			}
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 			if (DTD.PEDecls [decl.Name] == null) {
                                 DTD.PEDecls.Add (decl.Name, decl);
 			}
@@ -676,8 +667,7 @@ namespace System.Xml
 			SkipWhitespace ();
 			// This expanding is only allowed as a non-validating parser.
 			TryExpandPERef ();
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 			return decl;
 		}
 
@@ -763,8 +753,7 @@ namespace System.Xml
 			SkipWhitespace ();
 			// This expanding is only allowed as a non-validating parser.
 			TryExpandPERef ();
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 			return decl;
 		}
 
@@ -853,8 +842,7 @@ namespace System.Xml
 			default:	// Enumerated Values
 				def.Datatype = XmlSchemaDatatype.FromName ("NMTOKEN");
 				TryExpandPERef ();
-				SkipWhitespace ();
-				Expect ('(');
+				ExpectAfterWhitespace ('(');
 				SkipWhitespace ();
 				def.EnumeratedAttributeDeclaration.Add (
 					def.Datatype.Normalize (ReadNmToken ()));	// enum value
@@ -1010,8 +998,7 @@ namespace System.Xml
 				throw new XmlException ("public or system declaration required for \"NOTATION\" declaration.");
 			// This expanding is only allowed as a non-validating parser.
 			TryExpandPERef ();
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 			return decl;
 		}
 
@@ -1138,6 +1125,18 @@ namespace System.Xml
 				Expect (expected[i]);
 		}
 
+		private void ExpectAfterWhitespace (char c)
+		{
+			while (true) {
+				int i = ReadChar ();
+				if (XmlChar.IsWhitespace (i))
+					continue;
+				if (c != i)
+					throw new XmlException (String.Join (String.Empty, new string [] {"Expected ", c.ToString (), ", but found " + (char) i, "[", i.ToString (), "]"}));
+				break;
+			}
+		}
+
 		// Does not consume the first non-whitespace character.
 		private bool SkipWhitespace ()
 		{
@@ -1301,8 +1300,7 @@ namespace System.Xml
 			// version decl
 			if (PeekChar () == 'v') {
 				Expect ("version");
-				SkipWhitespace ();
-				Expect ('=');
+				ExpectAfterWhitespace ('=');
 				SkipWhitespace ();
 				int quoteChar = ReadChar ();
 				char [] expect1_0 = new char [3];
@@ -1336,8 +1334,7 @@ namespace System.Xml
 
 			if (PeekChar () == 'e') {
 				Expect ("encoding");
-				SkipWhitespace ();
-				Expect ('=');
+				ExpectAfterWhitespace ('=');
 				SkipWhitespace ();
 				int quoteChar = ReadChar ();
 				switch (quoteChar) {
@@ -1503,7 +1500,8 @@ namespace System.Xml
 		{
 			Uri baseUri = null;
 			try {
-				baseUri = new Uri (DTD.BaseURI);
+				if (DTD.BaseURI != null && DTD.BaseURI.Length > 0)
+					baseUri = new Uri (DTD.BaseURI);
 			} catch (UriFormatException) {
 			}
 

+ 17 - 13
mcs/class/System.XML/System.Xml/XmlSecureResolver.cs

@@ -28,19 +28,23 @@ namespace System.Xml
 			Zone zone = null;
 			Site site = null;
 
-			try {
-				url = new Url (securityUrl);
-			} catch (ArgumentException) {
-			}
-
-			try {
-				zone = Zone.CreateFromUrl (securityUrl);
-			} catch (ArgumentException) {
-			}
-
-			try {
-				site = Site.CreateFromUrl (securityUrl);
-			} catch (ArgumentException) {
+			if (securityUrl != null) {
+				try {
+					if (securityUrl.Length > 0)
+						url = new Url (securityUrl);
+				} catch (ArgumentException) {
+				}
+
+				try {
+					zone = Zone.CreateFromUrl (securityUrl);
+				} catch (ArgumentException) {
+				}
+
+				try {
+					if (securityUrl.Length > 0)
+						site = Site.CreateFromUrl (securityUrl);
+				} catch (ArgumentException) {
+				}
 			}
 
 			if (url != null)

+ 31 - 18
mcs/class/System.XML/System.Xml/XmlTextReader.cs

@@ -809,8 +809,13 @@ namespace System.Xml
 						Prefix = String.Empty;
 						LocalName = Name;
 					} else {
-						Prefix = Reader.NameTable.Add (Name.Substring (0, indexOfColon));
-						LocalName = Reader.NameTable.Add (Name.Substring (indexOfColon + 1));
+						// This improves speed by at least nearly 5%, but eats more memory at least nearly 0.3%
+						// However, this might be reverted if NameTable is got improved.
+						char [] nameArr = Name.ToCharArray ();
+						Prefix = Reader.NameTable.Add (nameArr, 0, indexOfColon);
+						LocalName = Reader.NameTable.Add (nameArr, indexOfColon + 1, nameArr.Length - indexOfColon - 1);
+//						Prefix = Reader.NameTable.Add (Name.Substring (0, indexOfColon));
+//						LocalName = Reader.NameTable.Add (Name.Substring (indexOfColon + 1));
 					}
 
 					// NamespaceURI
@@ -1061,7 +1066,7 @@ namespace System.Xml
 					XmlSpace.None);
 			}
 
-			if (url != null && url != String.Empty) {
+			if (url != null && url.Length > 0) {
 				Uri uri = null;
 				try {
 					uri = new Uri (url);
@@ -1380,8 +1385,7 @@ namespace System.Xml
 				throw new XmlException (this as IXmlLineInfo,String.Format ("unmatched closing element: expected {0} but found {1}", expected, name));
 			parserContext.PopScope ();
 
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 
 			--depth;
 
@@ -1604,8 +1608,7 @@ namespace System.Xml
 				currentAttributeToken.LinePosition = column;
 
 				currentAttributeToken.Name = ReadName ();
-				SkipWhitespace ();
-				Expect ('=');
+				ExpectAfterWhitespace ('=');
 				SkipWhitespace ();
 				ReadAttributeValueTokens (-1);
 				attributeCount++;
@@ -1691,7 +1694,12 @@ namespace System.Xml
 			bool incrementToken = false;
 			bool isNewToken = true;
 			bool loop = true;
-			while (loop && PeekChar () != quoteChar) {
+			int ch = 0;
+			while (loop) {
+				ch = ReadChar ();
+				if (ch == quoteChar)
+					break;
+
 				if (incrementToken) {
 					IncrementAttributeValueToken ();
 					currentAttributeValueToken.LineNumber = line;
@@ -1700,8 +1708,6 @@ namespace System.Xml
 					isNewToken = true;
 				}
 
-				int ch = ReadChar ();
-
 				switch (ch)
 				{
 				case '<':
@@ -1762,8 +1768,6 @@ namespace System.Xml
 			}
 			currentAttributeToken.ValueTokenEndIndex = currentAttributeValue;
 
-			if (dummyQuoteChar < 0)
-				ReadChar (); // quoteChar
 		}
 
 		// The reader is positioned on the first character
@@ -1894,8 +1898,7 @@ namespace System.Xml
 			// version decl
 			if (PeekChar () == 'v') {
 				Expect ("version");
-				SkipWhitespace ();
-				Expect ('=');
+				ExpectAfterWhitespace ('=');
 				SkipWhitespace ();
 				int quoteChar = ReadChar ();
 				char [] expect1_0 = new char [3];
@@ -1929,8 +1932,7 @@ namespace System.Xml
 
 			if (PeekChar () == 'e') {
 				Expect ("encoding");
-				SkipWhitespace ();
-				Expect ('=');
+				ExpectAfterWhitespace ('=');
 				SkipWhitespace ();
 				int quoteChar = ReadChar ();
 				switch (quoteChar) {
@@ -2114,8 +2116,7 @@ namespace System.Xml
 				parserContext.InternalSubset = currentTag.ToString (startPos, endPos - startPos);
 			}
 			// end of DOCTYPE decl.
-			SkipWhitespace ();
-			Expect ('>');
+			ExpectAfterWhitespace ('>');
 
 			GenerateDTDObjectModel (doctypeName, publicId,
 				systemId, parserContext.InternalSubset,
@@ -2431,6 +2432,18 @@ namespace System.Xml
 				Expect (expected[i]);
 		}
 
+		private void ExpectAfterWhitespace (char c)
+		{
+			while (true) {
+				int i = ReadChar ();
+				if (XmlChar.IsWhitespace (i))
+					continue;
+				if (c != i)
+					throw new XmlException (String.Join (String.Empty, new string [] {"Expected ", c.ToString (), ", but found " + (char) i, "[", i.ToString (), "]"}));
+				break;
+			}
+		}
+
 		// Does not consume the first non-whitespace character.
 		private bool SkipWhitespace ()
 		{