Skip to content

Commit ab3293c

Browse files
committed
Optimize pos check and change exception type
1 parent 5da315d commit ab3293c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/Lucene.Net/Support/Store/UnsafeChunkIndexInput.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,24 @@ protected void EnsureOpen()
187187

188188
public override void Seek(long pos)
189189
{
190-
if (pos < 0 || pos > length)
190+
if ((uint)pos > (uint)length)
191191
{
192-
throw new IOException("Seek position is out of bounds: " + pos);
192+
throw new ArgumentOutOfRangeException(nameof(pos), $"Seek position is out of bounds: {pos}");
193193
}
194+
194195
if (Volatile.Read(ref instanceClosed) != 0)
195196
{
196197
throw AlreadyClosedException.Create(this.GetType().FullName, "Already disposed: " + this);
197198
}
199+
198200
// If the seek stays inside the cached chunk, keep the cached pointer and
199201
// just move the cursor; otherwise invalidate so the next read reacquires.
200202
if (currentChunkIndex != NO_CHUNK && pos >= currentStart && pos < currentEnd)
201203
{
202204
position = pos;
203205
return;
204206
}
207+
205208
ReleaseCurrentChunk();
206209
position = pos;
207210
}

0 commit comments

Comments
 (0)