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

realm / realm-core / nicola.cabiddu_1040

26 Sep 2023 05:08PM UTC coverage: 91.056% (-1.9%) from 92.915%
nicola.cabiddu_1040

Pull #6766

Evergreen

nicola-cab
several fixes and final client reset algo for collection in mixed
Pull Request #6766: Client Reset for collections in mixed / nested collections

97128 of 178458 branches covered (0.0%)

1524 of 1603 new or added lines in 5 files covered. (95.07%)

4511 existing lines in 109 files now uncovered.

236619 of 259862 relevant lines covered (91.06%)

7169640.31 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,342,615✔
38
        return nullable ? StringData{} : StringData{""};
2,952,798✔
39
    }
3,342,615✔
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
    {
211,467✔
50
        return m_arr->is_attached();
211,467✔
51
    }
211,467✔
52

53
    ref_type get_ref() const
54
    {
313,503✔
55
        return m_arr->get_ref();
313,503✔
56
    }
313,503✔
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,629,241✔
67
        m_arr->set_parent(p, n);
15,629,241✔
68
    }
15,629,241✔
69
    bool need_spec() const override
70
    {
165,777✔
71
        return true;
165,777✔
72
    }
165,777✔
73
    void set_spec(Spec* spec, size_t col_ndx) const override
74
    {
11,034,918✔
75
        m_spec = spec;
11,034,918✔
76
        m_col_ndx = col_ndx;
11,034,918✔
77
    }
11,034,918✔
78

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

84
    void init_from_mem(MemRef mem) noexcept;
85
    void init_from_ref(ref_type ref) noexcept override
86
    {
17,957,184✔
87
        init_from_mem(MemRef(m_alloc.translate(ref), ref, m_alloc));
17,957,184✔
88
    }
17,957,184✔
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,357✔
99
        set(ndx, StringData{});
3,357✔
100
    }
3,357✔
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
{
8,996,145✔
149
    bool long_strings = Array::get_hasrefs_from_header(header);
8,996,145✔
150
    if (!long_strings) {
8,996,145✔
151
        return ArrayStringShort::get(header, ndx, true);
4,150,260✔
152
    }
4,150,260✔
153
    else {
4,845,885✔
154
        bool is_big = Array::get_context_flag_from_header(header);
4,845,885✔
155
        if (!is_big) {
4,845,885✔
156
            return ArraySmallBlobs::get_string(header, ndx, alloc);
178,953✔
157
        }
178,953✔
158
        else {
4,666,932✔
159
            return ArrayBigBlobs::get_string(header, ndx, alloc);
4,666,932✔
160
        }
4,666,932✔
161
    }
4,845,885✔
162
}
8,996,145✔
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