Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 8 additions & 23 deletions src/java/org/apache/cassandra/cache/ChunkCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@
synchronousCache.invalidateAll(Iterables.filter(cache.asMap().keySet(), x -> (x.readerId & mask) == fileId));
}

static class Key implements Comparable<Key>
static class Key
{
final long readerId;
final long position;

Key(long readerId, long position)
private Key(long readerId, long position)
{
super();
this.position = position;
Expand All @@ -312,40 +312,25 @@
@Override
public int hashCode()
{
// Mix readerId and position into a single long using a large prime multiplier
// This constant is a mixing constant derived from the Golden Ratio
long mixed = (Long.rotateLeft(readerId, 16) + Long.rotateLeft(position, 16)) * 0x9E3779B97F4A7C15L;

// Spread the bits (XOR-shift) to ensure high bits affect low bits
mixed ^= (mixed >>> 32);
mixed ^= (mixed >>> 16);

return (int) mixed;
final int prime = 31;
int result = 1;
result = prime * result + Long.hashCode(readerId);
result = prime * result + Long.hashCode(position);
return result;
}

@Override
public boolean equals(Object obj)

Check warning on line 323 in src/java/org/apache/cassandra/cache/ChunkCache.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type test to this method.

See more on https://sonarcloud.io/project/issues?id=cassandra-stargazer&issues=AZ2R2eMRvF7Rms9sc2gt&open=AZ2R2eMRvF7Rms9sc2gt&pullRequest=2320
{
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
if (obj == null)
return false;

Key other = (Key) obj;
return (position == other.position)
&& readerId == other.readerId;
}

@Override
public int compareTo(Key other) {
// Compare readerId first
int cmp = Long.compare(this.readerId, other.readerId);
if (cmp != 0) {
return cmp;
}
// Then compare position
return Long.compare(this.position, other.position);
}
}

/**
Expand Down
Loading
Loading