Skip to content

Commit

Permalink
Remove ArrayWithFind's callback parameter
Browse files Browse the repository at this point in the history
This was down to being used in one place, and that one place wasn't actually
using it to avoid a virtual call per row. In addition, how it was being used (a
lambda inside of a templated function) resulted in a very large number of
instantiations of the ArrayWithFind functions rather than the expected two.

find_action_pattern() has been unused for several years,
  • Loading branch information
tgoyne committed Oct 30, 2023
1 parent 218d06f commit 9a33838
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 290 deletions.
6 changes: 2 additions & 4 deletions src/realm/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@
using namespace realm;
using namespace realm::util;

void QueryStateBase::dyncast() {}

size_t Array::bit_width(int64_t v)
{
// FIXME: Assuming there is a 64-bit CPU reverse bitscan
Expand Down Expand Up @@ -1032,7 +1030,7 @@ MemRef Array::create(Type type, bool context_flag, WidthType width_type, size_t
template <class cond, size_t bitwidth>
bool Array::find_vtable(int64_t value, size_t start, size_t end, size_t baseindex, QueryStateBase* state) const
{
return ArrayWithFind(*this).find_optimized<cond, bitwidth>(value, start, end, baseindex, state, nullptr);
return ArrayWithFind(*this).find_optimized<cond, bitwidth>(value, start, end, baseindex, state);
}


Expand Down Expand Up @@ -1297,7 +1295,7 @@ bool QueryStateFindAll<std::vector<ObjKey>>::match(size_t index, Mixed) noexcept
{
++m_match_count;

int64_t key_value = (m_key_values ? m_key_values->get(index) : index) + m_key_offset;
int64_t key_value = (key_values ? key_values->get(index) : index) + key_offset;
m_keys.push_back(ObjKey(key_value));

return (m_limit > m_match_count);
Expand Down
2 changes: 1 addition & 1 deletion src/realm/array_integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void ArrayIntNull::find_all(IntegerColumn* result, value_type value, size_t col_

bool ArrayIntNull::find(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const
{
return find_impl(cond, value, start, end, state, nullptr);
return find_impl(cond, value, start, end, state);
}

size_t ArrayIntNull::find_first(value_type value, size_t begin, size_t end) const
Expand Down
16 changes: 7 additions & 9 deletions src/realm/array_integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class ArrayInteger : public Array, public ArrayPayload {
{
return false;
}
template <class cond, class Callback>
bool find(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const;
template <class cond>
bool find(value_type value, size_t start, size_t end, QueryStateBase* state) const;
};

class ArrayIntNull : public Array, public ArrayPayload {
Expand Down Expand Up @@ -125,8 +125,8 @@ class ArrayIntNull : public Array, public ArrayPayload {

bool find(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const;

template <class cond, class Callback>
bool find(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const;
template <class cond>
bool find(value_type value, size_t start, size_t end, QueryStateBase* state) const;

// Wrappers for backwards compatibility and for simple use without
// setting up state initialization etc
Expand All @@ -147,11 +147,9 @@ class ArrayIntNull : public Array, public ArrayPayload {
void replace_nulls_with(int64_t new_null);
bool can_use_as_null(int64_t value) const;

template <class Callback>
bool find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state,
Callback callback) const;
template <class cond, class Callback>
bool find_impl(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const;
bool find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const;
template <class cond>
bool find_impl(value_type value, size_t start, size_t end, QueryStateBase* state) const;
};


Expand Down
40 changes: 18 additions & 22 deletions src/realm/array_integer_tpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,34 @@

namespace realm {

template <class cond, class Callback>
bool ArrayInteger::find(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const
template <class cond>
bool ArrayInteger::find(value_type value, size_t start, size_t end, QueryStateBase* state) const
{
return ArrayWithFind(*this).find<cond, Callback>(value, start, end, 0, state, callback);
return ArrayWithFind(*this).find<cond>(value, start, end, 0, state);
}

template <class Callback>
inline bool ArrayIntNull::find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state,
Callback callback) const
inline bool ArrayIntNull::find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const
{
switch (cond) {
case cond_Equal:
return find_impl<Equal>(value, start, end, state, callback);
return find_impl<Equal>(value, start, end, state);
case cond_NotEqual:
return find_impl<NotEqual>(value, start, end, state, callback);
return find_impl<NotEqual>(value, start, end, state);
case cond_Greater:
return find_impl<Greater>(value, start, end, state, callback);
return find_impl<Greater>(value, start, end, state);
case cond_Less:
return find_impl<Less>(value, start, end, state, callback);
return find_impl<Less>(value, start, end, state);
case cond_None:
return find_impl<None>(value, start, end, state, callback);
return find_impl<None>(value, start, end, state);
case cond_LeftNotNull:
return find_impl<NotNull>(value, start, end, state, callback);
return find_impl<NotNull>(value, start, end, state);
}
REALM_ASSERT_DEBUG(false);
return false;
}

template <class cond, class Callback>
bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, QueryStateBase* state,
Callback callback) const
template <class cond>
bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, QueryStateBase* state) const
{
int64_t null_value = Array::get(0);
bool find_null = !bool(opt_value);
Expand All @@ -79,7 +76,7 @@ bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, Que
}

// Fall back to plain Array find.
return ArrayWithFind(*this).find<cond>(value, start2, end2, baseindex2, state, callback);
return ArrayWithFind(*this).find<cond>(value, start2, end2, baseindex2, state);
}
else {
cond c;
Expand All @@ -96,7 +93,7 @@ bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, Que
bool value_is_null = (v == null_value);
if (c(v, value, value_is_null, find_null)) {
util::Optional<int64_t> v2 = value_is_null ? util::none : util::make_optional(v);
if (!ArrayWithFind(*this).find_action(i + baseindex2, v2, state, callback)) {
if (!state->match(i + baseindex2, v2)) {
return false; // tell caller to stop aggregating/search
}
}
Expand All @@ -109,19 +106,18 @@ template <class cond>
size_t ArrayIntNull::find_first(value_type value, size_t start, size_t end) const
{
QueryStateFindFirst state;
find_impl<cond>(value, start, end, &state, nullptr);
find_impl<cond>(value, start, end, &state);

if (state.match_count() > 0)
return to_size_t(state.m_state);
else
return not_found;
}

template <class cond, class Callback>
inline bool ArrayIntNull::find(value_type value, size_t start, size_t end, QueryStateBase* state,
Callback callback) const
template <class cond>
inline bool ArrayIntNull::find(value_type value, size_t start, size_t end, QueryStateBase* state) const
{
return find_impl<cond, Callback>(value, start, end, state, callback);
return find_impl<cond>(value, start, end, state);
}

} // namespace realm
Expand Down
14 changes: 7 additions & 7 deletions src/realm/array_with_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ArrayWithFind::find_all(IntegerColumn* result, int64_t value, size_t col_of
end = m_array.m_size;

QueryStateFindAll state(*result);
REALM_TEMPEX2(find_optimized, Equal, m_array.m_width, (value, begin, end, col_offset, &state, nullptr));
REALM_TEMPEX2(find_optimized, Equal, m_array.m_width, (value, begin, end, col_offset, &state));

return;
}
Expand All @@ -39,22 +39,22 @@ bool ArrayWithFind::find(int cond, int64_t value, size_t start, size_t end, size
QueryStateBase* state) const
{
if (cond == cond_Equal) {
return find<Equal>(value, start, end, baseindex, state, nullptr);
return find<Equal>(value, start, end, baseindex, state);
}
if (cond == cond_NotEqual) {
return find<NotEqual>(value, start, end, baseindex, state, nullptr);
return find<NotEqual>(value, start, end, baseindex, state);
}
if (cond == cond_Greater) {
return find<Greater>(value, start, end, baseindex, state, nullptr);
return find<Greater>(value, start, end, baseindex, state);
}
if (cond == cond_Less) {
return find<Less>(value, start, end, baseindex, state, nullptr);
return find<Less>(value, start, end, baseindex, state);
}
if (cond == cond_None) {
return find<None>(value, start, end, baseindex, state, nullptr);
return find<None>(value, start, end, baseindex, state);
}
else if (cond == cond_LeftNotNull) {
return find<NotNull>(value, start, end, baseindex, state, nullptr);
return find<NotNull>(value, start, end, baseindex, state);
}
REALM_ASSERT_DEBUG(false);
return false;
Expand Down
Loading

0 comments on commit 9a33838

Please sign in to comment.