Skip to content

Commit 2beafa5

Browse files
committed
Move deleteLast and shift together in CompactHashStore as they are highly related
1 parent e5b2b65 commit 2beafa5

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ Object deleteLast(RubyHash hash, Object key,
240240
return deleteKvAndGetV(hash, indexPos, lastKeyPos);
241241
}
242242

243+
@ExportMessage
244+
RubyArray shift(RubyHash hash,
245+
@Cached @Shared HashingNodes.ToHash hashFunction,
246+
@Cached @Shared GetHashPosForKeyAtKvPosNode getHashPos,
247+
@Cached @Exclusive InlinedLoopConditionProfile nonNullKeyNotYetFound,
248+
@Bind("$node") Node node) {
249+
assert hash.size > 0;
250+
int firstKeyPos = firstNonNullKeyPosFromBeginning(nonNullKeyNotYetFound, node);
251+
252+
Object key = kvStore[firstKeyPos];
253+
int keyHash = hashFunction.execute(key, hash.compareByIdentity);
254+
int indexPos = getHashPos.execute(keyHash, firstKeyPos, index);
255+
Object val = deleteKvAndGetV(hash, indexPos, firstKeyPos);
256+
257+
return ArrayHelpers.createArray(RubyContext.get(node), RubyLanguage.get(node), new Object[]{ key, val });
258+
}
259+
243260
@ExportMessage
244261
Object eachEntry(RubyHash hash, EachEntryCallback callback, Object state,
245262
@Cached @Exclusive InlinedConditionProfile keyNotNull,
@@ -285,23 +302,6 @@ void replace(RubyHash hash, RubyHash dest,
285302
dest.defaultValue = hash.defaultValue;
286303
}
287304

288-
@ExportMessage
289-
RubyArray shift(RubyHash hash,
290-
@Cached @Shared HashingNodes.ToHash hashFunction,
291-
@Cached @Shared GetHashPosForKeyAtKvPosNode getHashPos,
292-
@Cached @Exclusive InlinedLoopConditionProfile nonNullKeyNotYetFound,
293-
@Bind("$node") Node node) {
294-
assert hash.size > 0;
295-
int firstKeyPos = firstNonNullKeyPosFromBeginning(nonNullKeyNotYetFound, node);
296-
297-
Object key = kvStore[firstKeyPos];
298-
int keyHash = hashFunction.execute(key, hash.compareByIdentity);
299-
int indexPos = getHashPos.execute(keyHash, firstKeyPos, index);
300-
Object val = deleteKvAndGetV(hash, indexPos, firstKeyPos);
301-
302-
return ArrayHelpers.createArray(RubyContext.get(node), RubyLanguage.get(node), new Object[]{ key, val });
303-
}
304-
305305
@TruffleBoundary
306306
@ExportMessage
307307
void rehash(RubyHash hash,

0 commit comments

Comments
 (0)