Skip to content

Commit

Permalink
Optimize Array::find_optimized in case of Equal on nullable array
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Aug 16, 2019
1 parent ed9e86a commit f1222a5
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/realm/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2219,19 +2219,32 @@ bool Array::find_optimized(int64_t value, size_t start, size_t end, size_t basei
end = nullable_array ? size() - 1 : size();

if (nullable_array) {
// We were called by find() of a nullable array. So skip first entry, take nulls in count, etc, etc. Fixme:
// Huge speed optimizations are possible here! This is a very simple generic method.
auto null_value = get(0);
for (; start2 < end; start2++) {
int64_t v = get<bitwidth>(start2 + 1);
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 (!find_action<action, Callback>(start2 + baseindex, v2, state, callback))
return false; // tell caller to stop aggregating/search
if (std::is_same<cond, Equal>::value) {
// In case of Equal it is safe to use the optimized logic. We just have to fetch the null value
// if this is what we are looking for. And we have to adjust the indexes to compensate for the
// null value at position 0.
if (find_null) {
value = get(0);
}
start2++;
end++;
baseindex--;
}
else {
// We were called by find() of a nullable array. So skip first entry, take nulls in count, etc, etc. Fixme:
// Huge speed optimizations are possible here! This is a very simple generic method.
auto null_value = get(0);
for (; start2 < end; start2++) {
int64_t v = get<bitwidth>(start2 + 1);
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 (!find_action<action, Callback>(start2 + baseindex, v2, state, callback))
return false; // tell caller to stop aggregating/search
}
}
return true; // tell caller to continue aggregating/search (on next array leafs)
}
return true; // tell caller to continue aggregating/search (on next array leafs)
}


Expand Down

0 comments on commit f1222a5

Please sign in to comment.