Skip to content

Commit 4ff773d

Browse files
committed
Refactor local slow methods
1 parent 1d8e520 commit 4ff773d

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

src/Lucene.Net/Support/UnsafeChunkIndexInput.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,19 @@ public override short ReadInt16()
257257
position = pos + 2;
258258
return (short)(BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(raw) : raw);
259259
}
260-
// Slow path: bytes straddle a chunk boundary. Fill via ReadBytes (which
261-
// handles the crossing) and decode big-endian to match the fast path;
262-
// avoids the per-byte virtcall round-trip through base.ReadInt16.
263-
Span<byte> buf = stackalloc byte[2];
264-
ReadBytes(buf);
265-
return BinaryPrimitives.ReadInt16BigEndian(buf);
260+
261+
return ReadInt16Slow();
262+
263+
[MethodImpl(MethodImplOptions.NoInlining)]
264+
short ReadInt16Slow()
265+
{
266+
// Slow path: bytes straddle a chunk boundary. Fill via ReadBytes (which
267+
// handles the crossing) and decode big-endian to match the fast path;
268+
// avoids the per-byte virtcall round-trip through base.ReadInt16.
269+
Span<byte> buf = stackalloc byte[2];
270+
ReadBytes(buf);
271+
return BinaryPrimitives.ReadInt16BigEndian(buf);
272+
}
266273
}
267274

268275
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -277,10 +284,17 @@ public override int ReadInt32()
277284
position = pos + 4;
278285
return (int)(BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(raw) : raw);
279286
}
280-
// Slow path: see ReadInt16.
281-
Span<byte> buf = stackalloc byte[4];
282-
ReadBytes(buf);
283-
return BinaryPrimitives.ReadInt32BigEndian(buf);
287+
288+
return ReadInt32Slow();
289+
290+
[MethodImpl(MethodImplOptions.NoInlining)]
291+
int ReadInt32Slow()
292+
{
293+
// Slow path: see ReadInt16.
294+
Span<byte> buf = stackalloc byte[4];
295+
ReadBytes(buf);
296+
return BinaryPrimitives.ReadInt32BigEndian(buf);
297+
}
284298
}
285299

286300
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -295,10 +309,17 @@ public override long ReadInt64()
295309
position = pos + 8;
296310
return (long)(BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(raw) : raw);
297311
}
298-
// Slow path: see ReadInt16.
299-
Span<byte> buf = stackalloc byte[8];
300-
ReadBytes(buf);
301-
return BinaryPrimitives.ReadInt64BigEndian(buf);
312+
313+
return ReadInt64Slow();
314+
315+
[MethodImpl(MethodImplOptions.NoInlining)]
316+
long ReadInt64Slow()
317+
{
318+
// Slow path: see ReadInt16.
319+
Span<byte> buf = stackalloc byte[8];
320+
ReadBytes(buf);
321+
return BinaryPrimitives.ReadInt64BigEndian(buf);
322+
}
302323
}
303324

304325
public override void ReadBytes(byte[] b, int offset, int len)

0 commit comments

Comments
 (0)