From: Daniel Drake <dsd@gentoo.org>

Tracing shows that the exception thrown inside Refill() is thrown hundreds of
times when indexing a small amount of files.

Reduce overhead by removing exceptions from handling of this particular error.

Index: Analysis/Standard/CharStream.cs
===================================================================
RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Analysis/Standard/CharStream.cs,v
retrieving revision 1.2
diff -u -B -p -r1.2 CharStream.cs
--- Analysis/Standard/CharStream.cs	17 Jan 2005 19:54:28 -0000	1.2
+++ Analysis/Standard/CharStream.cs	16 Oct 2005 20:09:02 -0000
@@ -25,7 +25,7 @@ namespace Lucene.Net.Analysis.Standard
 		/// of selecting the input is the responsibility of the class
 		/// implementing this interface.  Can throw any java.io.IOException.
 		/// </summary>
-		char ReadChar();
+		int ReadChar();
 		
 		/// <summary> Returns the column position of the character last read.</summary>
 		/// <deprecated> 
@@ -72,7 +72,7 @@ namespace Lucene.Net.Analysis.Standard
 		/// All characters must remain in the buffer between two successive calls
 		/// to this method to implement backup correctly.
 		/// </summary>
-		char BeginToken();
+		int BeginToken();
 		
 		/// <summary> Returns a string made up of characters from the marked token beginning 
 		/// to the current buffer position. Implementations have the choice of returning
@@ -100,4 +100,4 @@ namespace Lucene.Net.Analysis.Standard
 		/// </summary>
 		void  Done();
 	}
-}
\ No newline at end of file
+}
Index: Analysis/Standard/FastCharStream.cs
===================================================================
RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Analysis/Standard/FastCharStream.cs,v
retrieving revision 1.2
diff -u -B -p -r1.2 FastCharStream.cs
--- Analysis/Standard/FastCharStream.cs	17 Jan 2005 19:54:28 -0000	1.2
+++ Analysis/Standard/FastCharStream.cs	16 Oct 2005 20:09:02 -0000
@@ -40,14 +40,15 @@ namespace Lucene.Net.Analysis.Standard
 			input = r;
 		}
 		
-		public char ReadChar()
+		public int ReadChar()
 		{
 			if (bufferPosition >= bufferLength)
-				Refill();
+				if (!Refill())
+					return -1;
 			return buffer[bufferPosition++];
 		}
 		
-		private void  Refill()
+		private bool  Refill()
 		{
 			int newPosition = bufferLength - tokenStart;
 			
@@ -81,12 +82,13 @@ namespace Lucene.Net.Analysis.Standard
 
 			int charsRead = input.Read(buffer, newPosition, buffer.Length - newPosition);
 			if (charsRead <= 0)
-				throw new System.IO.IOException("read past eof");
-			else
-				bufferLength += charsRead;
+				return false;
+
+			bufferLength += charsRead;
+			return true;
 		}
 		
-		public char BeginToken()
+		public int BeginToken()
 		{
 			tokenStart = bufferPosition;
 			return ReadChar();
@@ -146,4 +148,4 @@ namespace Lucene.Net.Analysis.Standard
 			return 1;
 		}
 	}
-}
\ No newline at end of file
+}
Index: Analysis/Standard/StandardTokenizerTokenManager.cs
===================================================================
RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Analysis/Standard/StandardTokenizerTokenManager.cs,v
retrieving revision 1.3
diff -u -B -p -r1.3 StandardTokenizerTokenManager.cs
--- Analysis/Standard/StandardTokenizerTokenManager.cs	6 Oct 2005 19:29:55 -0000	1.3
+++ Analysis/Standard/StandardTokenizerTokenManager.cs	16 Oct 2005 20:09:04 -0000
@@ -1133,14 +1133,11 @@ namespace Lucene.Net.Analysis.Standard
 				++curPos;
 				if ((ii = jjnewStateCnt) == (startsAt = 73 - (jjnewStateCnt = startsAt)))
 					return curPos;
-				try
-				{
-					curChar = input_stream.ReadChar();
-				}
-				catch (System.IO.IOException)
-				{
+				int ret = input_stream.ReadChar();
+				if (ret != -1)
+					curChar = (char) ret;
+				else
 					return curPos;
-				}
 			}
 		}
 		internal static readonly int[] jjnextStates = new int[]{22, 23, 24, 26, 30, 31, 33, 34, 38, 39, 40, 41, 47, 48, 49, 50, 60, 61, 2, 3, 5, 6, 12, 13, 23, 24, 26, 24, 25, 26, 63, 64, 66, 67, 70, 71, 2, 3, 12, 13, 18, 19, 44, 45, 68, 69, 7, 8, 9, 10, 16, 17, 35, 36, 42, 43, 51, 52, 55, 56, 57, 58};
@@ -1284,11 +1281,11 @@ namespace Lucene.Net.Analysis.Standard
 			
 			for (; ; )
 			{
-				try
-				{
-					curChar = input_stream.BeginToken();
-				}
-				catch (System.IO.IOException)
+				
+				int ret = input_stream.BeginToken();
+				if (ret != -1)
+					curChar = (char) ret;
+				else
 				{
 					jjmatchedKind = 0;
 					matchedToken = JjFillToken();
@@ -1320,11 +1317,7 @@ namespace Lucene.Net.Analysis.Standard
 				int error_column = input_stream.GetEndColumn();
 				System.String error_after = null;
 				bool EOFSeen = false;
-				try
-				{
-					input_stream.ReadChar(); input_stream.Backup(1);
-				}
-				catch (System.IO.IOException)
+				if (input_stream.ReadChar() == -1)
 				{
 					EOFSeen = true;
 					error_after = curPos <= 1?"":input_stream.GetImage();
@@ -1336,6 +1329,9 @@ namespace Lucene.Net.Analysis.Standard
 					else
 						error_column++;
 				}
+				else
+					input_stream.Backup(1);
+
 				if (!EOFSeen)
 				{
 					input_stream.Backup(1);
@@ -1347,4 +1343,4 @@ EOFLoop: ;
 			}
 		}
 	}
-}
\ No newline at end of file
+}
