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

realm / realm-core / nicola.cabiddu_1042

27 Sep 2023 06:04PM UTC coverage: 91.085% (-1.8%) from 92.915%
nicola.cabiddu_1042

Pull #6766

Evergreen

nicola-cab
Fix logic for dictionaries
Pull Request #6766: Client Reset for collections in mixed / nested collections

97276 of 178892 branches covered (0.0%)

1994 of 2029 new or added lines in 7 files covered. (98.28%)

4556 existing lines in 112 files now uncovered.

237059 of 260260 relevant lines covered (91.09%)

6321099.55 hits per line

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

82.69
/src/realm/array_string.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 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_STRING_HPP
20
#define REALM_ARRAY_STRING_HPP
21

22
#include <realm/array_string_short.hpp>
23
#include <realm/array_blobs_small.hpp>
24
#include <realm/array_blobs_big.hpp>
25

26
namespace realm {
27

28
class Spec;
29

30
class ArrayString : public ArrayPayload {
31
public:
32
    using value_type = StringData;
33

34
    explicit ArrayString(Allocator&);
35

36
    static StringData default_value(bool nullable)
37
    {
3,333,597✔
38
        return nullable ? StringData{} : StringData{""};
2,945,124✔
39
    }
3,333,597✔
40

41
    // This is only used in the upgrade process
42
    void set_nullability(bool n)
UNCOV
43
    {
×
UNCOV
44
        m_nullable = n;
×
UNCOV
45
    }
×
46
    void create();
47

48
    bool is_attached() const
49
    {
212,700✔
50
        return m_arr->is_attached();
212,700✔
51
    }
212,700✔
52

53
    ref_type get_ref() const
54
    {
312,996✔
55
        return m_arr->get_ref();
312,996✔
56
    }
312,996✔
57
    ArrayParent* get_parent() const
58
    {
×
59
        return m_arr->get_parent();
×
60
    }
×
61
    size_t get_ndx_in_parent() const
62
    {
×
63
        return m_arr->get_ndx_in_parent();
×
64
    }
×
65
    void set_parent(ArrayParent* p, size_t n) noexcept override
66
    {
15,643,437✔
67
        m_arr->set_parent(p, n);
15,643,437✔
68
    }
15,643,437✔
69
    bool need_spec() const override
70
    {
165,813✔
71
        return true;
165,813✔
72
    }
165,813✔
73
    void set_spec(Spec* spec, size_t col_ndx) const override
74
    {
11,088,909✔
75
        m_spec = spec;
11,088,909✔
76
        m_col_ndx = col_ndx;
11,088,909✔
77
    }
11,088,909✔
78

79
    void update_parent()
80
    {
54,927✔
81
        m_arr->update_parent();
54,927✔
82
    }
54,927✔
83

84
    void init_from_mem(MemRef mem) noexcept;
85
    void init_from_ref(ref_type ref) noexcept override
86
    {
18,099,006✔
87
        init_from_mem(MemRef(m_alloc.translate(ref), ref, m_alloc));
18,099,006✔
88
    }
18,099,006✔
89
    void init_from_parent();
90
    void destroy() noexcept;
91
    void detach() noexcept;
92

93
    size_t size() const;
94

95
    void add(StringData value);
96
    void set(size_t ndx, StringData value);
97
    void set_null(size_t ndx)
98
    {
3,006✔
99
        set(ndx, StringData{});
3,006✔
100
    }
3,006✔
101
    void insert(size_t ndx, StringData value);
102
    StringData get(size_t ndx) const;
103
    StringData get_legacy(size_t ndx) const;
104
    Mixed get_any(size_t ndx) const override;
105
    bool is_null(size_t ndx) const;
106
    void erase(size_t ndx);
107
    void move(ArrayString& dst, size_t ndx);
108
    void clear();
109

110
    size_t find_first(StringData value, size_t begin, size_t end) const noexcept;
111

112
    size_t lower_bound(StringData value);
113

114
    /// Get the specified element without the cost of constructing an
115
    /// array instance. If an array instance is already available, or
116
    /// you need to get multiple values, then this method will be
117
    /// slower.
118
    static StringData get(const char* header, size_t ndx, Allocator& alloc) noexcept;
119

120
    void verify() const;
121

122
private:
123
    static constexpr size_t small_string_max_size = 15;  // ArrayStringShort
124
    static constexpr size_t medium_string_max_size = 63; // ArrayStringLong
125
    union Storage {
126
        std::aligned_storage<sizeof(ArrayStringShort), alignof(ArrayStringShort)>::type m_string_short;
127
        std::aligned_storage<sizeof(ArraySmallBlobs), alignof(ArraySmallBlobs)>::type m_string_long;
128
        std::aligned_storage<sizeof(ArrayBigBlobs), alignof(ArrayBigBlobs)>::type m_big_blobs;
129
        std::aligned_storage<sizeof(Array), alignof(Array)>::type m_enum;
130
    };
131
    enum class Type { small_strings, medium_strings, big_strings, enum_strings };
132

133
    Type m_type = Type::small_strings;
134

135
    Allocator& m_alloc;
136
    Storage m_storage;
137
    Array* m_arr;
138
    mutable Spec* m_spec = nullptr;
139
    mutable size_t m_col_ndx = realm::npos;
140
    bool m_nullable = true;
141

142
    std::unique_ptr<ArrayString> m_string_enum_values;
143

144
    Type upgrade_leaf(size_t value_size);
145
};
146

147
inline StringData ArrayString::get(const char* header, size_t ndx, Allocator& alloc) noexcept
148
{
9,112,176✔
149
    bool long_strings = Array::get_hasrefs_from_header(header);
9,112,176✔
150
    if (!long_strings) {
9,112,176✔
151
        return ArrayStringShort::get(header, ndx, true);
4,270,098✔
152
    }
4,270,098✔
153
    else {
4,842,078✔
154
        bool is_big = Array::get_context_flag_from_header(header);
4,842,078✔
155
        if (!is_big) {
4,842,078✔
156
            return ArraySmallBlobs::get_string(header, ndx, alloc);
178,701✔
157
        }
178,701✔
158
        else {
4,663,377✔
159
            return ArrayBigBlobs::get_string(header, ndx, alloc);
4,663,377✔
160
        }
4,663,377✔
161
    }
4,842,078✔
162
}
9,112,176✔
163

164
}
165

166
#endif /* REALM_ARRAY_STRING_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

© 2025 Coveralls, Inc