• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 1794

31 Oct 2023 10:48PM UTC coverage: 91.584% (+0.02%) from 91.565%
1794

push

Evergreen

web-flow
remove unnecessary callback use for ArrayWithFind::find_action() (#7095)

* remove unnecessary callback use for ArrayWithFind::find_action()

* remove find_action_pattern which hasn't been used in years

* add changeloge note

* lint and address comments

92898 of 170898 branches covered (0.0%)

107 of 126 new or added lines in 10 files covered. (84.92%)

47 existing lines in 13 files now uncovered.

230666 of 251863 relevant lines covered (91.58%)

6855264.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/realm/array_integer_tpl.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2021 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#ifndef REALM_ARRAY_INTEGER_TPL_HPP
20
#define REALM_ARRAY_INTEGER_TPL_HPP
21

22
#include <realm/array_integer.hpp>
23
#include <realm/array_with_find.hpp>
24

25
namespace realm {
26

27
template <class cond>
28
bool ArrayInteger::find(value_type value, size_t start, size_t end, QueryStateBase* state) const
29
{
4,893,144✔
30
    return ArrayWithFind(*this).find<cond>(value, start, end, 0, state);
4,893,144✔
31
}
4,893,144✔
32

33
inline bool ArrayIntNull::find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const
UNCOV
34
{
×
35
    switch (cond) {
×
36
        case cond_Equal:
×
NEW
37
            return find_impl<Equal>(value, start, end, state);
×
38
        case cond_NotEqual:
×
NEW
39
            return find_impl<NotEqual>(value, start, end, state);
×
40
        case cond_Greater:
×
NEW
41
            return find_impl<Greater>(value, start, end, state);
×
42
        case cond_Less:
×
NEW
43
            return find_impl<Less>(value, start, end, state);
×
44
        case cond_None:
×
NEW
45
            return find_impl<None>(value, start, end, state);
×
46
        case cond_LeftNotNull:
×
NEW
47
            return find_impl<NotNull>(value, start, end, state);
×
48
    }
×
49
    REALM_ASSERT_DEBUG(false);
×
50
    return false;
×
51
}
×
52

53
template <class cond>
54
bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, QueryStateBase* state) const
55
{
232,164✔
56
    int64_t null_value = Array::get(0);
232,164✔
57
    bool find_null = !bool(opt_value);
232,164✔
58
    int64_t value;
232,164✔
59

116,082✔
60
    size_t end2 = (end == npos ? size() : end) + 1;
220,182!
61
    size_t start2 = start + 1;
232,164✔
62
    size_t baseindex2 = size_t(-1);
232,164✔
63

116,082✔
64
    if constexpr (std::is_same_v<cond, Equal>) {
232,164✔
65
        if (find_null) {
121,446✔
66
            value = null_value;
7,488✔
67
        }
7,488✔
68
        else {
113,958✔
69
            if (*opt_value == null_value) {
113,958✔
70
                // If the value to search for is equal to the null value, the value cannot be in the array
71
                return true;
×
72
            }
×
73
            else {
113,958✔
74
                value = *opt_value;
113,958✔
75
            }
113,958✔
76
        }
113,958✔
77

55,356✔
78
        // Fall back to plain Array find.
55,356✔
79
        return ArrayWithFind(*this).find<cond>(value, start2, end2, baseindex2, state);
121,446✔
80
    }
121,446✔
81
    else {
110,712✔
82
        cond c;
110,712✔
83

55,356✔
84
        if (opt_value) {
110,712!
85
            value = *opt_value;
89,796✔
86
        }
89,796✔
87
        else {
20,916✔
88
            value = null_value;
20,916✔
89
        }
20,916✔
90

55,356✔
91
        for (size_t i = start2; i < end2; ++i) {
18,491,598✔
92
            int64_t v = Array::get(i);
18,417,492✔
93
            bool value_is_null = (v == null_value);
18,417,492✔
94
            if (c(v, value, value_is_null, find_null)) {
18,417,492!
95
                if (!state->match(i + baseindex2)) {
18,381,537✔
96
                    return false; // tell caller to stop aggregating/search
36,606✔
97
                }
36,606✔
98
            }
18,381,537✔
99
        }
18,417,492✔
100
        return true; // tell caller to continue aggregating/search (on next array leafs)
92,409✔
101
    }
110,712✔
102
}
232,164✔
103

104
template <class cond>
105
size_t ArrayIntNull::find_first(value_type value, size_t start, size_t end) const
106
{
85,578✔
107
    QueryStateFindFirst state;
85,578✔
108
    find_impl<cond>(value, start, end, &state);
85,578✔
109

42,789✔
110
    if (state.match_count() > 0)
85,578✔
111
        return to_size_t(state.m_state);
48,126✔
112
    else
37,452✔
113
        return not_found;
37,452✔
114
}
85,578✔
115

116
template <class cond>
117
inline bool ArrayIntNull::find(value_type value, size_t start, size_t end, QueryStateBase* state) const
118
{
146,586✔
119
    return find_impl<cond>(value, start, end, state);
146,586✔
120
}
146,586✔
121

122
} // namespace realm
123

124
#endif /* REALM_ARRAY_INTEGER_TPL_HPP */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc