Skip to content

Commit

Permalink
Remove some update_from_parent() functions
Browse files Browse the repository at this point in the history
It is a long time since there was a difference in how init_from_parent()
and update_from_parent() should work.
  • Loading branch information
jedelbo committed Aug 26, 2024
1 parent 7101d7c commit 2b1c3d4
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 87 deletions.
9 changes: 0 additions & 9 deletions src/realm/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ void Array::init_from_mem(MemRef mem) noexcept
update_width_cache_from_header();
}

void Array::update_from_parent() noexcept
{
REALM_ASSERT_DEBUG(is_attached());
ArrayParent* parent = get_parent();
REALM_ASSERT_DEBUG(parent);
ref_type new_ref = get_ref_from_parent();
init_from_ref(new_ref);
}

void Array::set_type(Type type)
{
REALM_ASSERT(is_attached());
Expand Down
6 changes: 0 additions & 6 deletions src/realm/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ class Array : public Node, public ArrayParent {
init_from_ref(ref);
}

/// Called in the context of Group::commit() to ensure that attached
/// accessors stay valid across a commit. Please note that this works only
/// for non-transactional commits. Accessors obtained during a transaction
/// are always detached when the transaction ends.
void update_from_parent() noexcept;

/// Change the type of an already attached array node.
///
/// The effect of calling this function on an unattached accessor is
Expand Down
8 changes: 2 additions & 6 deletions src/realm/array_blobs_small.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ void ArraySmallBlobs::init_from_mem(MemRef mem) noexcept
Array::init_from_mem(mem);
ref_type offsets_ref = get_as_ref(0);
ref_type blob_ref = get_as_ref(1);
ref_type nulls_ref = get_as_ref(2);

m_offsets.init_from_ref(offsets_ref);
m_blob.init_from_ref(blob_ref);

// In theory you could have an array that survived from ancient days where this array was not present
if (Array::size() > 2) {
ref_type nulls_ref = get_as_ref(2);
m_nulls.init_from_ref(nulls_ref);
}
m_nulls.init_from_ref(nulls_ref);
}

void ArraySmallBlobs::add(BinaryData value, bool add_zero_term)
Expand Down
10 changes: 0 additions & 10 deletions src/realm/array_blobs_small.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class ArraySmallBlobs : public Array {
/// initialization value).
static MemRef create_array(size_t size, Allocator&, BinaryData defaults);

void update_from_parent() noexcept;

private:
friend class ArrayString;
Array m_offsets;
Expand Down Expand Up @@ -258,14 +256,6 @@ inline size_t ArraySmallBlobs::get_size_from_header(const char* header, Allocato
return Array::get_size_from_header(offsets_header);
}

inline void ArraySmallBlobs::update_from_parent() noexcept
{
Array::update_from_parent();
m_blob.update_from_parent();
m_offsets.update_from_parent();
m_nulls.update_from_parent();
}

} // namespace realm

#endif // REALM_ARRAY_BINARY_HPP
2 changes: 1 addition & 1 deletion src/realm/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void Cluster::init(MemRef mem)

void Cluster::update_from_parent() noexcept
{
Array::update_from_parent();
Array::init_from_parent();
auto rot = Array::get_as_ref_or_tagged(0);
if (!rot.is_tagged()) {
m_keys.update_from_parent();
Expand Down
2 changes: 1 addition & 1 deletion src/realm/cluster_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void ClusterNodeInner::init(MemRef mem)

void ClusterNodeInner::update_from_parent() noexcept
{
Array::update_from_parent();
Array::init_from_parent();
ref_type ref = Array::get_as_ref(s_key_ref_index);
if (ref) {
m_keys.update_from_parent();
Expand Down
4 changes: 2 additions & 2 deletions src/realm/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,8 @@ void Group::update_refs(ref_type top_ref) noexcept
m_top.init_from_ref(top_ref);

// Now we can update it's child arrays
m_table_names.update_from_parent();
m_tables.update_from_parent();
m_table_names.init_from_parent();
m_tables.init_from_parent();

// Update all attached table accessors.
for (auto& table_accessor : m_table_accessors) {
Expand Down
2 changes: 1 addition & 1 deletion src/realm/search_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ inline size_t SearchIndex::get_ndx_in_parent() const noexcept

inline void SearchIndex::update_from_parent() noexcept
{
m_root_array->update_from_parent();
m_root_array->init_from_parent();
}

} // namespace realm
Expand Down
34 changes: 4 additions & 30 deletions src/realm/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ void Spec::detach() noexcept
m_top.detach();
}

bool Spec::init(ref_type ref) noexcept
void Spec::init(ref_type ref) noexcept
{
MemRef mem(ref, get_alloc());
init(mem);
return true;
}

void Spec::init(MemRef mem) noexcept
Expand All @@ -44,9 +43,9 @@ void Spec::init(MemRef mem) noexcept
// Since Core6 we will always have the column keys array
REALM_ASSERT(top_size == s_spec_max_size);

m_types.init_from_ref(m_top.get_as_ref(s_types_ndx));
m_names.init_from_ref(m_top.get_as_ref(s_names_ndx));
m_attr.init_from_ref(m_top.get_as_ref(s_attributes_ndx));
m_types.init_from_parent();
m_names.init_from_parent();
m_attr.init_from_parent();

// Enumkeys array is only there when there are StringEnum columns
if (auto ref = m_top.get_as_ref(s_enum_keys_ndx)) {
Expand All @@ -58,11 +57,6 @@ void Spec::init(MemRef mem) noexcept

m_keys.init_from_parent();

update_internals();
}

void Spec::update_internals() noexcept
{
size_t n = m_types.size();
m_num_public_columns = n;
// We normally have fewer backlink columns than public columns, so quicker to go backwards
Expand All @@ -75,26 +69,6 @@ void Spec::update_internals() noexcept
}
}

void Spec::update_from_parent() noexcept
{
m_top.update_from_parent();
m_types.update_from_parent();
m_names.update_from_parent();
m_attr.update_from_parent();

if (m_top.get_as_ref(s_enum_keys_ndx) != 0) {
m_enumkeys.update_from_parent();
}
else {
m_enumkeys.detach();
}

m_keys.update_from_parent();

update_internals();
}


MemRef Spec::create_empty_spec(Allocator& alloc)
{
// The 'spec_set' contains the specification (types and names) of
Expand Down
20 changes: 4 additions & 16 deletions src/realm/spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,13 @@ class Spec {

Spec(Allocator&) noexcept; // Unattached

bool init(ref_type) noexcept;
void init(ref_type) noexcept;
void init(MemRef) noexcept;
void update_internals() noexcept;

// Returns true in case the ref has changed.
bool init_from_parent() noexcept;
void init_from_parent() noexcept;

ref_type get_ref() const noexcept;

/// Called in the context of Group::commit() to ensure that
/// attached table accessors stay valid across a commit. Please
/// note that this works only for non-transactional commits. Table
/// accessors obtained during a transaction are always detached
/// when the transaction ends.
void update_from_parent() noexcept;

void set_parent(ArrayParent*, size_t ndx_in_parent) noexcept;

void set_column_attr(size_t column_ndx, ColumnAttrMask attr);
Expand Down Expand Up @@ -160,10 +151,9 @@ inline Spec::Spec(Allocator& alloc) noexcept
m_keys.set_parent(&m_top, s_col_keys_ndx);
}

inline bool Spec::init_from_parent() noexcept
inline void Spec::init_from_parent() noexcept
{
ref_type ref = m_top.get_ref_from_parent();
return init(ref);
init(m_top.get_ref_from_parent());
}

inline void Spec::destroy() noexcept
Expand Down Expand Up @@ -235,8 +225,6 @@ inline void Spec::set_column_attr(size_t column_ndx, ColumnAttrMask attr)
// so setting it will overwrite existing. In the future
// we will allow combinations.
m_attr.set(column_ndx, attr.m_value);

update_internals();
}

inline StringData Spec::get_column_name(size_t ndx) const noexcept
Expand Down
10 changes: 5 additions & 5 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,18 +1952,18 @@ void Table::update_from_parent() noexcept
{
// There is no top for sub-tables sharing spec
if (m_top.is_attached()) {
m_top.update_from_parent();
m_spec.update_from_parent();
m_top.init_from_parent();
m_spec.init_from_parent();
m_clusters.update_from_parent();
m_index_refs.update_from_parent();
m_index_refs.init_from_parent();
for (auto&& index : m_index_accessors) {
if (index != nullptr) {
index->update_from_parent();
}
}

m_opposite_table.update_from_parent();
m_opposite_column.update_from_parent();
m_opposite_table.init_from_parent();
m_opposite_column.init_from_parent();
if (m_top.size() > top_position_for_flags) {
uint64_t flags = m_top.get_as_ref_or_tagged(top_position_for_flags).get_as_int();
m_table_type = Type(flags & table_type_mask);
Expand Down

0 comments on commit 2b1c3d4

Please sign in to comment.