Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Debugging.Assert usage to not allocate due to lambda capture #372

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Lucene.Net/Util/FixedBitSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public int Cardinality()

public bool Get(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, () => "index=" + index + ", numBits=" + numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int i = index >> 6; // div 64
// signed shift will keep a negative index and force an
// array-index-out-of-bounds-exception, removing the need for an explicit check.
Expand All @@ -270,7 +270,7 @@ public bool Get(int index)

public void Set(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, () => "index=" + index + ", numBits=" + numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int wordNum = index >> 6; // div 64
int bit = index & 0x3f; // mod 64
long bitmask = 1L << bit;
Expand All @@ -279,7 +279,7 @@ public void Set(int index)

public bool GetAndSet(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int wordNum = index >> 6; // div 64
int bit = index & 0x3f; // mod 64
long bitmask = 1L << bit;
Expand All @@ -290,7 +290,7 @@ public bool GetAndSet(int index)

public void Clear(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int wordNum = index >> 6;
int bit = index & 0x03f;
long bitmask = 1L << bit;
Expand All @@ -299,7 +299,7 @@ public void Clear(int index)

public bool GetAndClear(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int wordNum = index >> 6; // div 64
int bit = index & 0x3f; // mod 64
long bitmask = 1L << bit;
Expand All @@ -314,7 +314,7 @@ public bool GetAndClear(int index)
/// </summary>
public int NextSetBit(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, () => "index=" + index + ", numBits=" + numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index}, numBits={numBits}");
int i = index >> 6;
int subIndex = index & 0x3f; // index within the word
long word = bits[i] >> subIndex; // skip all the bits to the right of index
Expand Down Expand Up @@ -342,7 +342,7 @@ public int NextSetBit(int index)
/// </summary>
public int PrevSetBit(int index)
{
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, () => "index=" + index + " numBits=" + numBits);
if (Debugging.AssertsEnabled) Debugging.Assert(index >= 0 && index < numBits, $"index={index} numBits={numBits}");
int i = index >> 6;
int subIndex = index & 0x3f; // index within the word
long word = (bits[i] << (63 - subIndex)); // skip all the bits to the left of index
Expand Down Expand Up @@ -405,7 +405,7 @@ public void Or(FixedBitSet other)

private void Or(long[] otherArr, int otherNumWords)
{
if (Debugging.AssertsEnabled) Debugging.Assert(otherNumWords <= numWords, () => "numWords=" + numWords + ", otherNumWords=" + otherNumWords);
if (Debugging.AssertsEnabled) Debugging.Assert(otherNumWords <= numWords, $"numWords={numWords}, otherNumWords={otherNumWords}");
long[] thisArr = this.bits;
int pos = Math.Min(numWords, otherNumWords);
while (--pos >= 0)
Expand All @@ -418,7 +418,7 @@ private void Or(long[] otherArr, int otherNumWords)
/// this = this XOR other </summary>
public void Xor(FixedBitSet other)
{
if (Debugging.AssertsEnabled) Debugging.Assert(other.numWords <= numWords, () => "numWords=" + numWords + ", other.numWords=" + other.numWords);
if (Debugging.AssertsEnabled) Debugging.Assert(other.numWords <= numWords, $"numWords={numWords}, other.numWords={other.numWords}");
long[] thisBits = this.bits;
long[] otherBits = other.bits;
int pos = Math.Min(numWords, other.numWords);
Expand Down Expand Up @@ -663,8 +663,8 @@ public void Clear(int startIndex, int endIndex)
{
if (Debugging.AssertsEnabled)
{
Debugging.Assert(startIndex >= 0 && startIndex < numBits, () => "startIndex=" + startIndex + ", numBits=" + numBits);
Debugging.Assert(endIndex >= 0 && endIndex <= numBits, () => "endIndex=" + endIndex + ", numBits=" + numBits);
Debugging.Assert(startIndex >= 0 && startIndex < numBits, $"startIndex={startIndex}, numBits={numBits}");
Debugging.Assert(endIndex >= 0 && endIndex <= numBits, $"endIndex={endIndex}, numBits={numBits}");
}
if (endIndex <= startIndex)
{
Expand Down