Skip to content

Commit 0b9ff06

Browse files
author
Xin Liu
committed
8300184: Optimize ResourceHashtableBase::iterate_all using _number_of_entries
Reviewed-by: dholmes, rehn
1 parent 75b122f commit 0b9ff06

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/hotspot/share/utilities/resourceHash.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -228,12 +228,15 @@ class ResourceHashtableBase : public STORAGE {
228228
void iterate(Function function) const { // lambda enabled API
229229
Node* const* bucket = table();
230230
const unsigned sz = table_size();
231-
while (bucket < bucket_at(sz)) {
231+
int cnt = _number_of_entries;
232+
233+
while (cnt > 0 && bucket < bucket_at(sz)) {
232234
Node* node = *bucket;
233235
while (node != NULL) {
234236
bool cont = function(node->_key, node->_value);
235237
if (!cont) { return; }
236238
node = node->_next;
239+
--cnt;
237240
}
238241
++bucket;
239242
}

0 commit comments

Comments
 (0)