lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject git commit: Fixed performance issue with IOException in FastCharStream.
Date Sun, 01 Jun 2014 02:33:48 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 7d5014310 -> ac8c9fa80


Fixed performance issue with IOException in FastCharStream.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ac8c9fa8
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ac8c9fa8
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ac8c9fa8

Branch: refs/heads/master
Commit: ac8c9fa809110ddb180bf7b2ce93e86270b39ff6
Parents: 7d50143
Author: Christopher Haws <christopher.haws@spiralgames.net>
Authored: Sun May 25 22:11:03 2014 -0700
Committer: Christopher Haws <christopher.haws@spiralgames.net>
Committed: Sun May 25 22:11:03 2014 -0700

----------------------------------------------------------------------
 src/core/QueryParser/FastCharStream.cs          |  33 ++-
 src/core/QueryParser/QueryParserTokenManager.cs | 216 ++++++++++---------
 2 files changed, 142 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ac8c9fa8/src/core/QueryParser/FastCharStream.cs
----------------------------------------------------------------------
diff --git a/src/core/QueryParser/FastCharStream.cs b/src/core/QueryParser/FastCharStream.cs
index 27bd5fd..17f934a 100644
--- a/src/core/QueryParser/FastCharStream.cs
+++ b/src/core/QueryParser/FastCharStream.cs
@@ -46,14 +46,27 @@ namespace Lucene.Net.QueryParsers
             input = r;
         }
         
+		/// <summary>
+		/// Read a single character from the stream.
+		/// </summary>
+		/// <returns>If the end of the stream has been reached then <see cref="Char.MinValue"/>;
otherwise the next character in the stream.</returns>
         public char ReadChar()
         {
-            if (bufferPosition >= bufferLength)
-                Refill();
+			if (bufferPosition >= bufferLength)
+			{
+				if (!Refill())
+				{
+					return Char.MinValue;
+				}
+			}
             return buffer[bufferPosition++];
         }
         
-        private void  Refill()
+		/// <summary>
+		/// Refills the stream.
+		/// </summary>
+		/// <returns>False if the end of the stream has been reached; otherwise true;</returns>
+        private bool Refill()
         {
             int newPosition = bufferLength - tokenStart;
             
@@ -85,10 +98,14 @@ namespace Lucene.Net.QueryParsers
             tokenStart = 0;
             
             int charsRead = input.Read(buffer, newPosition, buffer.Length - newPosition);
-            if (charsRead <= 0)
-                throw new System.IO.IOException("read past eof");
-            else
-                bufferLength += charsRead;
+			if (charsRead <= 0)
+			{
+				return false;
+			}
+	        
+			bufferLength += charsRead;
+
+	        return true;
         }
         
         public char BeginToken()
@@ -97,7 +114,7 @@ namespace Lucene.Net.QueryParsers
             return ReadChar();
         }
         
-        public void  Backup(int amount)
+        public void Backup(int amount)
         {
             bufferPosition -= amount;
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ac8c9fa8/src/core/QueryParser/QueryParserTokenManager.cs
----------------------------------------------------------------------
diff --git a/src/core/QueryParser/QueryParserTokenManager.cs b/src/core/QueryParser/QueryParserTokenManager.cs
index 5d20404..17583d2 100644
--- a/src/core/QueryParser/QueryParserTokenManager.cs
+++ b/src/core/QueryParser/QueryParserTokenManager.cs
@@ -17,6 +17,8 @@
 
 /* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */
 
+using System;
+
 namespace Lucene.Net.QueryParsers
 {
     
@@ -99,14 +101,16 @@ namespace Lucene.Net.QueryParsers
         {
             jjmatchedKind = kind;
             jjmatchedPos = pos;
-            try
-            {
-                curChar = input_stream.ReadChar();
-            }
-            catch (System.IO.IOException)
-            {
-                return pos + 1;
-            }
+
+			var nextCharacter = input_stream.ReadChar();
+
+			if (nextCharacter == Char.MinValue)
+			{
+				return pos + 1;
+			}
+
+			curChar = nextCharacter;
+
             return JjMoveNfa_3(state, pos + 1);
         }
         internal static readonly ulong[] jjbitVec0 = new ulong[]{0x1L, 0x0L, 0x0L, 0x0L};
@@ -599,14 +603,15 @@ namespace Lucene.Net.QueryParsers
                 ++curPos;
                 if ((i = jjnewStateCnt) == (startsAt = 36 - (jjnewStateCnt = startsAt)))
                     return curPos;
-                try
-                {
-                    curChar = input_stream.ReadChar();
-                }
-                catch (System.IO.IOException)
-                {
-                    return curPos;
-                }
+
+				var nextCharacter = input_stream.ReadChar();
+
+				if (nextCharacter == Char.MinValue)
+				{
+					return curPos;
+				}
+
+				curChar = nextCharacter;
             }
         }
         private int JjStopStringLiteralDfa_1(int pos, long active0)
@@ -649,15 +654,16 @@ namespace Lucene.Net.QueryParsers
         }
         private int JjMoveStringLiteralDfa1_1(long active0)
         {
-            try
-            {
-                curChar = input_stream.ReadChar();
-            }
-            catch (System.IO.IOException)
-            {
-                JjStopStringLiteralDfa_1(0, active0);
+			var nextCharacter = input_stream.ReadChar();
+
+			if (nextCharacter == Char.MinValue)
+			{
+				JjStopStringLiteralDfa_1(0, active0);
                 return 1;
-            }
+			}
+
+			curChar = nextCharacter;
+
             switch (curChar)
             {
                 
@@ -676,14 +682,16 @@ namespace Lucene.Net.QueryParsers
         {
             jjmatchedKind = kind;
             jjmatchedPos = pos;
-            try
-            {
-                curChar = input_stream.ReadChar();
-            }
-            catch (System.IO.IOException)
-            {
-                return pos + 1;
-            }
+
+			var nextCharacter = input_stream.ReadChar();
+
+			if (nextCharacter == Char.MinValue)
+			{
+				return pos + 1;
+			}
+
+			curChar = nextCharacter;
+
             return JjMoveNfa_1(state, pos + 1);
         }
         private int JjMoveNfa_1(int startState, int curPos)
@@ -841,14 +849,15 @@ namespace Lucene.Net.QueryParsers
                 ++curPos;
                 if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt)))
                     return curPos;
-                try
-                {
-                    curChar = input_stream.ReadChar();
-                }
-                catch (System.IO.IOException)
-                {
-                    return curPos;
-                }
+
+				var nextCharacter = input_stream.ReadChar();
+
+				if (nextCharacter == Char.MinValue)
+				{
+					return curPos;
+				}
+
+				curChar = nextCharacter;
             }
         }
         private int JjMoveStringLiteralDfa0_0()
@@ -942,14 +951,15 @@ namespace Lucene.Net.QueryParsers
                 ++curPos;
                 if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt)))
                     return curPos;
-                try
-                {
-                    curChar = input_stream.ReadChar();
-                }
-                catch (System.IO.IOException)
-                {
-                    return curPos;
-                }
+
+				var nextCharacter = input_stream.ReadChar();
+
+				if (nextCharacter != Char.MinValue)
+				{
+					return curPos;
+				}
+				
+				curChar = nextCharacter;
             }
         }
         private int JjStopStringLiteralDfa_2(int pos, long active0)
@@ -992,15 +1002,16 @@ namespace Lucene.Net.QueryParsers
         }
         private int JjMoveStringLiteralDfa1_2(long active0)
         {
-            try
-            {
-                curChar = input_stream.ReadChar();
-            }
-            catch (System.IO.IOException)
-            {
-                JjStopStringLiteralDfa_2(0, active0);
-                return 1;
-            }
+			var nextCharacter = input_stream.ReadChar();
+
+			if (nextCharacter == Char.MinValue)
+			{
+				JjStopStringLiteralDfa_2(0, active0);
+				return 1;
+			}
+
+			curChar = nextCharacter;
+
             switch (curChar)
             {
                 
@@ -1019,14 +1030,16 @@ namespace Lucene.Net.QueryParsers
         {
             jjmatchedKind = kind;
             jjmatchedPos = pos;
-            try
-            {
-                curChar = input_stream.ReadChar();
-            }
-            catch (System.IO.IOException)
-            {
-                return pos + 1;
-            }
+
+			var nextCharacter = input_stream.ReadChar();
+
+			if (nextCharacter == Char.MinValue)
+			{
+				return pos + 1;
+			}
+
+			curChar = nextCharacter;
+
             return JjMoveNfa_2(state, pos + 1);
         }
         private int JjMoveNfa_2(int startState, int curPos)
@@ -1184,14 +1197,15 @@ namespace Lucene.Net.QueryParsers
                 ++curPos;
                 if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt)))
                     return curPos;
-                try
-                {
-                    curChar = input_stream.ReadChar();
-                }
-                catch (System.IO.IOException)
-                {
-                    return curPos;
-                }
+
+				var nextCharacter = input_stream.ReadChar();
+
+				if (nextCharacter == Char.MinValue)
+				{
+					return curPos;
+				}
+
+				curChar = nextCharacter;
             }
         }
         internal static readonly int[] jjnextStates = new int[]{15, 16, 18, 29, 32, 23, 33,
30, 20, 21, 32, 23, 33, 31, 34, 27, 2, 4, 5, 0, 1};
@@ -1341,16 +1355,16 @@ namespace Lucene.Net.QueryParsers
             
             for (; ; )
             {
-                try
-                {
-                    curChar = input_stream.BeginToken();
-                }
-                catch (System.IO.IOException)
-                {
-                    jjmatchedKind = 0;
-                    matchedToken = JjFillToken();
-                    return matchedToken;
-                }
+				var nextCharacter = input_stream.BeginToken();
+
+				if (nextCharacter == Char.MinValue)
+				{
+					jjmatchedKind = 0;
+					matchedToken = JjFillToken();
+					return matchedToken;
+				}
+
+				curChar = nextCharacter;
                 
                 switch (curLexState)
                 {
@@ -1401,22 +1415,26 @@ namespace Lucene.Net.QueryParsers
                 int error_column = input_stream.EndColumn;
                 System.String error_after = null;
                 bool EOFSeen = false;
-                try
-                {
-                    input_stream.ReadChar(); input_stream.Backup(1);
-                }
-                catch (System.IO.IOException)
-                {
-                    EOFSeen = true;
-                    error_after = curPos <= 1?"":input_stream.Image;
-                    if (curChar == '\n' || curChar == '\r')
-                    {
-                        error_line++;
-                        error_column = 0;
-                    }
-                    else
-                        error_column++;
-                }
+
+				var nextCharacter2 = input_stream.ReadChar();
+
+				if (nextCharacter2 == Char.MinValue)
+				{
+					EOFSeen = true;
+					error_after = curPos <= 1 ? "" : input_stream.Image;
+					if (curChar == '\n' || curChar == '\r')
+					{
+						error_line++;
+						error_column = 0;
+					}
+					else
+						error_column++;
+				}
+				else
+				{
+					input_stream.Backup(1);
+				}
+
                 if (!EOFSeen)
                 {
                     input_stream.Backup(1);


Mime
View raw message