Skip to content

Commit 662f0af

Browse files
committed
BREAKING: Lucene.Net.Store.DataInput: Added abstract overload of ReadBytes(Span<byte>) and made the ReadBytes(byte[], int, int) overload virtual.
1 parent 56ace91 commit 662f0af

25 files changed

Lines changed: 202 additions & 101 deletions

src/Lucene.Net.TestFramework/Index/MockIndexInput.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Lucene.Net.Support;
2+
using System;
23

34
namespace Lucene.Net.Index
45
{
@@ -39,8 +40,10 @@ public MockIndexInput(byte[] bytes)
3940
length = bytes.Length;
4041
}
4142

42-
protected override void ReadInternal(byte[] dest, int destOffset, int len)
43+
protected override void ReadInternal(Span<byte> destination)
4344
{
45+
int destOffset = 0;
46+
int len = destination.Length;
4447
int remainder = len;
4548
int start = pointer;
4649
while (remainder != 0)
@@ -49,7 +52,7 @@ protected override void ReadInternal(byte[] dest, int destOffset, int len)
4952
int bufferOffset = start % buffer.Length;
5053
int bytesInBuffer = buffer.Length - bufferOffset;
5154
int bytesToCopy = bytesInBuffer >= remainder ? remainder : bytesInBuffer;
52-
Arrays.Copy(buffer, bufferOffset, dest, destOffset, bytesToCopy);
55+
Arrays.Copy(buffer, bufferOffset, destination, destOffset, bytesToCopy);
5356
destOffset += bytesToCopy;
5457
start += bytesToCopy;
5558
remainder -= bytesToCopy;

src/Lucene.Net.TestFramework/Store/MockIndexInputWrapper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,18 @@ public override byte ReadByte()
129129
return @delegate.ReadByte();
130130
}
131131

132-
public override void ReadBytes(byte[] b, int offset, int len)
132+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
133+
public override void ReadBytes(Span<byte> destination)
133134
{
134135
EnsureOpen();
135-
@delegate.ReadBytes(b, offset, len);
136+
@delegate.ReadBytes(destination);
136137
}
137138

138-
public override void ReadBytes(byte[] b, int offset, int len, bool useBuffer)
139+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
140+
public override void ReadBytes(Span<byte> destination, bool useBuffer)
139141
{
140142
EnsureOpen();
141-
@delegate.ReadBytes(b, offset, len, useBuffer);
143+
@delegate.ReadBytes(destination, useBuffer);
142144
}
143145

144146
/// <summary>

src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,17 @@ public override byte ReadByte()
143143
return ii.ReadByte();
144144
}
145145

146-
public override void ReadBytes(byte[] b, int offset, int len)
146+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
147+
public override void ReadBytes(Span<byte> destination)
147148
{
149+
int len = destination.Length;
148150
if (numRead >= IO_SLEEP_THRESHOLD)
149151
{
150152
outerInstance.DoSleep(rand, len);
151153
numRead = 0;
152154
}
153155
numRead += len;
154-
ii.ReadBytes(b, offset, len);
156+
ii.ReadBytes(destination);
155157
}
156158

157159

src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ public override void ReadBytes(byte[] b, int offset, int len)
159159
throw new ArgumentException("The sum of offset and length exceeds the buffer length");
160160
}
161161

162+
ReadBytes(b.AsSpan(offset, len));
163+
}
164+
165+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
166+
public override void ReadBytes(Span<byte> destination)
167+
{
168+
int len = destination.Length;
162169
long available = length - position;
163170
if (available < len)
164171
{
@@ -169,7 +176,7 @@ public override void ReadBytes(byte[] b, int offset, int len)
169176
// Fill buffer with dummy data
170177
for (int i = 0; i < len; i++)
171178
{
172-
b[offset + i] = 0;
179+
destination[/*offset +*/ i] = 0;
173180
}
174181
}
175182

src/Lucene.Net.Tests/Index/TestFieldsReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ internal virtual void SimOutage()
187187
}
188188
}
189189

190-
protected override void ReadInternal(byte[] b, int offset, int length)
190+
protected override void ReadInternal(Span<byte> destination)
191191
{
192192
SimOutage();
193193
@delegate.Seek(Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream
194-
@delegate.ReadBytes(b, offset, length);
194+
@delegate.ReadBytes(destination);
195195
}
196196

197197
protected override void SeekInternal(long pos)

src/Lucene.Net.Tests/Index/TestLazyProxSkipping.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ public override byte ReadByte()
211211
return this.input.ReadByte();
212212
}
213213

214-
public override void ReadBytes(byte[] b, int offset, int len)
214+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
215+
public override void ReadBytes(Span<byte> destination)
215216
{
216-
this.input.ReadBytes(b, offset, len);
217+
this.input.ReadBytes(destination);
217218
}
218219

219220
protected override void Dispose(bool disposing)

src/Lucene.Net.Tests/Index/TestMultiLevelSkipList.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ public override byte ReadByte()
183183
return this.input.ReadByte();
184184
}
185185

186-
public override void ReadBytes(byte[] b, int offset, int len)
186+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
187+
public override void ReadBytes(Span<byte> destination)
187188
{
189+
int len = destination.Length;
188190
outerInstance.counter += len;
189-
this.input.ReadBytes(b, offset, len);
191+
this.input.ReadBytes(destination);
190192
}
191193

192194
protected override void Dispose(bool disposing)

src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ public MyBufferedIndexInput()
232232
// an infinite file
233233
}
234234

235-
protected override void ReadInternal(byte[] b, int offset, int length)
235+
protected override void ReadInternal(Span<byte> destination)
236236
{
237-
for (int i = offset; i < offset + length; i++)
237+
int length = destination.Length;
238+
for (int i = 0; i < length; i++)
238239
{
239-
b[i] = Byten(pos++);
240+
destination[i] = Byten(pos++);
240241
}
241242
}
242243

src/Lucene.Net/Codecs/Compressing/CompressingStoredFieldsReader.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,19 @@ public override byte ReadByte()
415415
return (byte)outerInstance.bytes.Bytes[outerInstance.bytes.Offset++];
416416
}
417417

418-
public override void ReadBytes(byte[] b, int offset, int len)
418+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
419+
public override void ReadBytes(Span<byte> destination)
419420
{
421+
int offset = 0;
422+
int len = destination.Length;
420423
while (len > outerInstance.bytes.Length)
421424
{
422-
Arrays.Copy(outerInstance.bytes.Bytes, outerInstance.bytes.Offset, b, offset, outerInstance.bytes.Length);
425+
Arrays.Copy(outerInstance.bytes.Bytes, outerInstance.bytes.Offset, destination, offset, outerInstance.bytes.Length);
423426
len -= outerInstance.bytes.Length;
424427
offset += outerInstance.bytes.Length;
425428
FillBuffer();
426429
}
427-
Arrays.Copy(outerInstance.bytes.Bytes, outerInstance.bytes.Offset, b, offset, len);
430+
Arrays.Copy(outerInstance.bytes.Bytes, outerInstance.bytes.Offset, destination, offset, len);
428431
outerInstance.bytes.Offset += len;
429432
outerInstance.bytes.Length -= len;
430433
}

src/Lucene.Net/Codecs/MultiLevelSkipListReader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,13 @@ public override byte ReadByte()
378378
return data[pos++];
379379
}
380380

381+
// LUCENENET: Use Span<byte> instead of byte[] for better compatibility.
381382
[MethodImpl(MethodImplOptions.AggressiveInlining)]
382-
public override void ReadBytes(byte[] b, int offset, int len)
383+
public override void ReadBytes(Span<byte> destination)
383384
{
384385
EnsureOpen(); // LUCENENET: Guard against disposed IndexInput
385-
Arrays.Copy(data, pos, b, offset, len);
386+
int len = destination.Length;
387+
Arrays.Copy(data, pos, destination, /*offset*/ 0, len);
386388
pos += len;
387389
}
388390

0 commit comments

Comments
 (0)