Skip to content

Commit 81459fb

Browse files
committed
Simplify and fix bugs in ANTLRInputStream
1 parent a4e5bfb commit 81459fb

File tree

1 file changed

+3
-39
lines changed

1 file changed

+3
-39
lines changed

runtime/CSharp/Antlr4.Runtime/ANTLRInputStream.cs

+3-39
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,9 @@ public virtual void Load(StreamReader r, int size, int readChunkSize)
130130
{
131131
return;
132132
}
133-
if (size <= 0)
134-
{
135-
size = InitialBufferSize;
136-
}
137-
if (readChunkSize <= 0)
138-
{
139-
readChunkSize = ReadBufferSize;
140-
}
141-
// System.out.println("load "+size+" in chunks of "+readChunkSize);
142-
try
143-
{
144-
// alloc initial buffer size.
145-
data = new char[size];
146-
// read all the data in chunks of readChunkSize
147-
int numRead = 0;
148-
int p = 0;
149-
do
150-
{
151-
if (p + readChunkSize > data.Length)
152-
{
153-
// overflow?
154-
// System.out.println("### overflow p="+p+", data.length="+data.length);
155-
data = Arrays.CopyOf(data, data.Length * 2);
156-
}
157-
numRead = r.Read(data, p, readChunkSize);
158-
// System.out.println("read "+numRead+" chars; p was "+p+" is now "+(p+numRead));
159-
p += numRead;
160-
}
161-
while (numRead != -1);
162-
// while not EOF
163-
// set the actual size of the data available;
164-
// EOF subtracted one above in p+=numRead; add one back
165-
n = p + 1;
166-
}
167-
finally
168-
{
169-
//System.out.println("n="+n);
170-
r.Dispose();
171-
}
133+
134+
data = r.ReadToEnd().ToCharArray();
135+
n = data.Length;
172136
}
173137

174138
/// <summary>

0 commit comments

Comments
 (0)