-
Notifications
You must be signed in to change notification settings - Fork 186
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
Fix rehash functionality #2266
Fix rehash functionality #2266
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -845,6 +845,7 @@ protected int sizePackedArray(RubyHash hash) { | |
public abstract static class InternalRehashNode extends RubyContextNode { | ||
|
||
@Child private HashingNodes.ToHash hashNode = HashingNodes.ToHash.create(); | ||
@Child private CompareHashKeysNode compareHashKeysNode = new CompareHashKeysNode(); | ||
|
||
public static InternalRehashNode create() { | ||
return InternalRehashNodeGen.create(); | ||
|
@@ -866,14 +867,8 @@ protected RubyHash rehashPackedArray(RubyHash hash, | |
final Object[] store = (Object[]) hash.store; | ||
final int size = hash.size; | ||
|
||
for (int n = 0; n < getLanguage().options.HASH_PACKED_ARRAY_MAX; n++) { | ||
if (n < size) { | ||
PackedArrayStrategy.setHashed( | ||
store, | ||
n, | ||
hashNode.execute(PackedArrayStrategy.getKey(store, n), compareByIdentity)); | ||
} | ||
} | ||
PackedArrayStrategy.promoteToBuckets(getContext(), hash, store, size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fairly inefficient, it means There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We weren't sure the best way to solve this - multiple nested loops? Could get pretty verbose when exploded? Or a temporary set to see if a value has already been included? Seemed like that was basically the bucket strategy anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A nested loop seems OK, there is already no |
||
rehashBuckets(hash, byIdentityProfile); | ||
|
||
assert HashOperations.verifyStore(getContext(), hash); | ||
|
||
|
@@ -890,6 +885,7 @@ protected RubyHash rehashBuckets(RubyHash hash, | |
Arrays.fill(entries, null); | ||
|
||
Entry entry = hash.firstInSequence; | ||
Entry previousEntry = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
while (entry != null) { | ||
final int newHash = hashNode.execute(entry.getKey(), compareByIdentity); | ||
|
@@ -900,14 +896,37 @@ protected RubyHash rehashBuckets(RubyHash hash, | |
|
||
if (bucketEntry == null) { | ||
entries[index] = entry; | ||
previousEntry = entry; | ||
} else { | ||
boolean encounteredDuplicateKey = false; | ||
while (bucketEntry.getNextInLookup() != null) { | ||
if (compareHashKeysNode.equalKeys( | ||
compareByIdentity, | ||
entry.getKey(), | ||
entry.getHashed(), | ||
bucketEntry.getKey(), | ||
bucketEntry.getHashed())) { | ||
encounteredDuplicateKey = true; | ||
break; | ||
} | ||
bucketEntry = bucketEntry.getNextInLookup(); | ||
} | ||
if (encounteredDuplicateKey || compareHashKeysNode.equalKeys( | ||
compareByIdentity, | ||
entry.getKey(), | ||
entry.getHashed(), | ||
bucketEntry.getKey(), | ||
bucketEntry.getHashed())) { // If the bucket contains a single entry, we never set the flag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you avoid this duplicated call by changing the loop above to be a |
||
if (previousEntry != null) { | ||
previousEntry.setNextInSequence(entry.getNextInSequence()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use |
||
} | ||
hash.size--; | ||
} else { | ||
bucketEntry.setNextInLookup(entry); | ||
previousEntry = entry; | ||
} | ||
|
||
bucketEntry.setNextInLookup(entry); | ||
} | ||
|
||
entry = entry.getNextInSequence(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken empty line here.