Skip to content

Commit 8062a74

Browse files
committed
Remove profile in CompactHashStore#insertIntoIndex
* I tried making that a node but some Truffle DSL bug prevents using the node in PackedHashStoreLibrary.
1 parent 8c9072c commit 8062a74

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/main/java/org/truffleruby/core/hash/library/CompactHashStore.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ private static int indexPosToValuePos(int[] index, int indexPos) {
160160
return index[indexPos + 1];
161161
}
162162

163-
// For promoting from packed to compact
164-
public void putHashKeyValue(int hashcode, Object key, Object value) {
165-
int pos = kvStoreInsertionPos;
166-
SetKvAtNode.insertIntoKv(this, key, value);
167-
SetKvAtNode.insertIntoIndex(hashcode, pos + 1, index,
168-
InlinedLoopConditionProfile.getUncached(), null);
169-
}
170-
171163
@ExportMessage
172164
Object lookupOrDefault(Frame frame, RubyHash hash, Object key, PEBiFunction defaultNode,
173165
@Cached @Shared GetIndexPosForKeyNode getIndexPosForKeyNode,
@@ -586,7 +578,7 @@ static boolean keyDoesntExist(
586578
}
587579

588580
keyPos = store.kvStoreInsertionPos;
589-
insertIntoKv(store, key, value);
581+
insertIntoKv(store, keyPos, key, value);
590582

591583
assert store.index[indexPos + 1] <= 0;
592584
store.index[indexPos] = keyHash;
@@ -596,43 +588,42 @@ static boolean keyDoesntExist(
596588

597589
if (indexResizingIsNeeded.profile(node, hash.size >= store.indexGrowthThreshold)) {
598590
// Resize the index array after insertion, as it invalidates indexPos
599-
resizeIndex(store, node);
591+
resizeIndex(store);
600592
}
601593

602594
return true;
603595
}
604596

605-
private static void insertIntoIndex(int keyHash, int kvPos, int[] index,
606-
InlinedLoopConditionProfile unavailableSlot, Node node) {
607-
int pos = indexPosFromHashCode(keyHash, index.length);
597+
private static void insertIntoIndex(int hashCode, int valuePos, int[] index) {
598+
int pos = indexPosFromHashCode(hashCode, index.length);
608599

609-
while (unavailableSlot.profile(node, index[pos + 1] > INDEX_SLOT_UNUSED)) {
600+
while (index[pos + 1] > INDEX_SLOT_UNUSED) {
610601
pos = incrementIndexPos(pos, index.length);
611602
}
612603

613-
index[pos] = keyHash;
614-
index[pos + 1] = kvPos;
604+
index[pos] = hashCode;
605+
index[pos + 1] = valuePos;
615606
}
616607

617-
private static void insertIntoKv(CompactHashStore store, Object key, Object value) {
618-
store.kvStore[store.kvStoreInsertionPos] = key;
619-
store.kvStore[store.kvStoreInsertionPos + 1] = value;
620-
store.kvStoreInsertionPos += 2;
608+
private static void insertIntoKv(CompactHashStore store, int keyPos, Object key, Object value) {
609+
store.kvStore[keyPos] = key;
610+
store.kvStore[keyPos + 1] = value;
611+
store.kvStoreInsertionPos = keyPos + 2;
621612
}
622613

623614
@TruffleBoundary
624-
private static void resizeIndex(CompactHashStore store, Node node) {
615+
private static void resizeIndex(CompactHashStore store) {
625616
int[] oldIndex = store.index;
626617
int[] newIndex = new int[2 * oldIndex.length];
627618
int newIndexCapacity = newIndex.length >> 1;
628619

629620
int i = 0;
630621
for (; i < oldIndex.length; i += 2) {
631622
int hash = oldIndex[i];
632-
int kvPos = oldIndex[i + 1];
623+
int valuePos = oldIndex[i + 1];
633624

634-
if (kvPos > INDEX_SLOT_UNUSED) {
635-
insertIntoIndex(hash, kvPos, newIndex, InlinedLoopConditionProfile.getUncached(), node);
625+
if (valuePos > INDEX_SLOT_UNUSED) {
626+
insertIntoIndex(hash, valuePos, newIndex);
636627
}
637628
}
638629

@@ -645,6 +636,14 @@ private static void resizeKvStore(CompactHashStore store) {
645636
}
646637
}
647638

639+
/** For promoting from packed to compact */
640+
void insertHashKeyValue(int hashCode, Object key, Object value) {
641+
int keyPos = kvStoreInsertionPos;
642+
int valuePos = keyPos + 1;
643+
SetKvAtNode.insertIntoKv(this, keyPos, key, value);
644+
SetKvAtNode.insertIntoIndex(hashCode, valuePos, index);
645+
}
646+
648647
public static final class CompactHashLiteralNode extends HashLiteralNode {
649648

650649
@Child HashStoreLibrary hashes;

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private static void promoteToBuckets(RubyHash hash, Object[] store, int size) {
158158
private static void promoteToCompact(RubyHash hash, Object[] store) {
159159
CompactHashStore newStore = new CompactHashStore(MAX_ENTRIES);
160160
for (int n = 0; n < MAX_ENTRIES; n++) {
161-
newStore.putHashKeyValue(getHashed(store, n), getKey(store, n), getValue(store, n));
161+
newStore.insertHashKeyValue(getHashed(store, n), getKey(store, n), getValue(store, n));
162162
}
163163
hash.store = newStore;
164164
hash.size = MAX_ENTRIES;

0 commit comments

Comments
 (0)