Maybe something like this in resourceHash.hpp:
template<class ITER>
void iterate(ITER* iter) const { // the old API
auto f = [&] (K& k, V& v) {
return iter->do_entry(k, v);
};
iterate(f);
}
template<typename F>
void iterate(F f) const { // lambda enabled API
Node* const* bucket = table();
const unsigned sz = table_size();
while (bucket < bucket_at(sz)) {
Node* node = *bucket;
while (node != NULL) {
bool cont = f(node->_key, node->_value);
if (!cont) { return; }
node = node->_next;
}
++bucket;
}
}
==================
Example usage in heapShared.cpp
int n = 0;
auto f = [&] (oop& k, oop& v) {
n++;
return true;
};
archived_object_cache()->iterate(f);
tty->print_cr("Counted = %d objects", n);
==================
Need to verify that there's no performance degradation in the code generated by modern C++ compilers (when either old or new API is used).
template<class ITER>
void iterate(ITER* iter) const { // the old API
auto f = [&] (K& k, V& v) {
return iter->do_entry(k, v);
};
iterate(f);
}
template<typename F>
void iterate(F f) const { // lambda enabled API
Node* const* bucket = table();
const unsigned sz = table_size();
while (bucket < bucket_at(sz)) {
Node* node = *bucket;
while (node != NULL) {
bool cont = f(node->_key, node->_value);
if (!cont) { return; }
node = node->_next;
}
++bucket;
}
}
==================
Example usage in heapShared.cpp
int n = 0;
auto f = [&] (oop& k, oop& v) {
n++;
return true;
};
archived_object_cache()->iterate(f);
tty->print_cr("Counted = %d objects", n);
==================
Need to verify that there's no performance degradation in the code generated by modern C++ compilers (when either old or new API is used).