Skip to content

Commit a2261a4

Browse files
committed
8382196: Clean up C++ iterator style in compactHashtable.hpp and trainingData.hpp
Reviewed-by: kvn, qamai
1 parent 533a8a8 commit a2261a4

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

src/hotspot/share/classfile/compactHashtable.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,9 @@ class CompactHashtable : public SimpleCompactHashtable {
307307
template <class ITER>
308308
inline void iterate(ITER* iter) const { iterate([&](V v) { iter->do_value(v); }); }
309309

310-
template<typename Function>
311-
inline void iterate(const Function& function) const { // lambda enabled API
312-
iterate(const_cast<Function&>(function));
313-
}
314-
315310
// Iterate through the values in the table, stopping when the lambda returns false.
316311
template<typename Function>
317-
inline void iterate(Function& function) const { // lambda enabled API
312+
inline void iterate(Function function) const { // lambda enabled API
318313
for (u4 i = 0; i < _bucket_count; i++) {
319314
u4 bucket_info = _buckets[i];
320315
u4 bucket_offset = BUCKET_OFFSET(bucket_info);

src/hotspot/share/oops/trainingData.hpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, 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
@@ -217,11 +217,7 @@ class TrainingData : public Metadata {
217217
return *prior;
218218
}
219219
template<typename Function>
220-
void iterate(const Function& fn) const { // lambda enabled API
221-
iterate(const_cast<Function&>(fn));
222-
}
223-
template<typename Function>
224-
void iterate(Function& fn) const { // lambda enabled API
220+
void iterate(Function fn) const { // lambda enabled API
225221
return _table.iterate_all([&](const TrainingData::Key* k, TrainingData* td) { fn(td); });
226222
}
227223
int size() const { return _table.number_of_entries(); }
@@ -304,10 +300,7 @@ class TrainingData : public Metadata {
304300
}
305301

306302
template<typename Function>
307-
static void iterate(const Function& fn) { iterate(const_cast<Function&>(fn)); }
308-
309-
template<typename Function>
310-
static void iterate(Function& fn) { // lambda enabled API
303+
static void iterate(Function fn) { // lambda enabled API
311304
TrainingDataLocker l;
312305
if (have_data()) {
313306
archived_training_data_dictionary()->iterate_all(fn);

0 commit comments

Comments
 (0)