Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-cab committed Jun 20, 2023
1 parent 0f41ca2 commit 807ca5a
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/realm/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@ ColInfo get_col_info(const Table* table)
return cols;
}

void add_list_to_repl(CollectionBase& list, Replication& repl, util::UniqueFunction<void(Mixed)>& update_embedded);
void add_dictionary_to_repl(Dictionary& dict, Replication& repl, util::UniqueFunction<void(Mixed)>& update_embedded)
void add_list_to_repl(CollectionBase& list, Replication& repl, util::UniqueFunction<void(Mixed)> update_embedded);
void add_dictionary_to_repl(Dictionary& dict, Replication& repl, util::UniqueFunction<void(Mixed)> update_embedded)
{
size_t sz = dict.size();
for (size_t n = 0; n < sz; ++n) {
const auto& [key, val] = dict.get_pair(n);
repl.dictionary_insert(dict, n, key, val);
if (val.is_type(type_List)) {
auto n_list = dict.get_list({key.get_string()});
add_list_to_repl(*n_list, *dict.get_table()->get_repl(), update_embedded);
add_list_to_repl(*n_list, *dict.get_table()->get_repl(), nullptr);
}
else if (val.is_type(type_Dictionary)) {
repl.dictionary_insert(dict, n, key, val);
auto n_dict = dict.get_dictionary({key.get_string()});
add_dictionary_to_repl(*n_dict, *dict.get_table()->get_repl(), update_embedded);
add_dictionary_to_repl(*n_dict, *dict.get_table()->get_repl(), nullptr);
}
else {
else if (update_embedded) {
update_embedded(val);
}
}
}

void add_list_to_repl(CollectionBase& list, Replication& repl, util::UniqueFunction<void(Mixed)>& update_embedded)
void add_list_to_repl(CollectionBase& list, Replication& repl, util::UniqueFunction<void(Mixed)> update_embedded)
{
auto sz = list.size();
for (size_t n = 0; n < sz; n++) {
auto val = list.get_any(n);
repl.list_insert(list, n, val, n);
if (val.is_type(type_List)) {
auto n_list = list.get_list({n});
add_list_to_repl(*n_list, *list.get_table()->get_repl(), update_embedded);
add_list_to_repl(*n_list, *list.get_table()->get_repl(), nullptr);
}
else if (val.is_type(type_Dictionary)) {
auto n_dict = list.get_dictionary({n});
add_dictionary_to_repl(*n_dict, *list.get_table()->get_repl(), update_embedded);
add_dictionary_to_repl(*n_dict, *list.get_table()->get_repl(), nullptr);
}
else {
else if (update_embedded) {
update_embedded(val);
}
}
Expand All @@ -92,23 +92,23 @@ void generate_properties_for_obj(Replication& repl, const Obj& obj, const ColInf
auto col = elem.first;
auto embedded_table = elem.second;
auto cols_2 = get_col_info(embedded_table);
util::UniqueFunction<void(Mixed)> update_embedded = [&](Mixed val) {
if (auto embedded_table = elem.second) {
cols_2 = get_col_info(embedded_table);
util::UniqueFunction<void(Mixed)> update_embedded = nullptr;
if (embedded_table) {
update_embedded = [&](Mixed val) {
if (val.is_null()) {
return;
}
REALM_ASSERT(val.is_type(type_Link, type_TypedLink));
Obj embedded_obj = embedded_table->get_object(val.get<ObjKey>());
generate_properties_for_obj(repl, embedded_obj, cols_2);
}
return;
};
return;
};
}

if (col.is_list()) {
auto list = obj.get_listbase_ptr(col);
repl.list_clear(*list);
add_list_to_repl(*list, repl, update_embedded);
add_list_to_repl(*list, repl, std::move(update_embedded));
}
else if (col.is_set()) {
auto set = obj.get_setbase_ptr(col);
Expand All @@ -120,21 +120,22 @@ void generate_properties_for_obj(Replication& repl, const Obj& obj, const ColInf
}
else if (col.is_dictionary()) {
auto dict = obj.get_dictionary(col);
add_dictionary_to_repl(dict, repl, update_embedded);
add_dictionary_to_repl(dict, repl, std::move(update_embedded));
}
else {
auto val = obj.get_any(col);
if (!val.is_null() && val.get_type() == type_List) {
if (val.is_type(type_List)) {
Lst<Mixed> list(obj, col);
add_list_to_repl(list, repl, update_embedded);
add_list_to_repl(list, repl, std::move(update_embedded));
}
else if (!val.is_null() && val.get_type() == type_Dictionary) {
else if (val.is_type(type_Dictionary)) {
Dictionary dict(obj, col);
add_dictionary_to_repl(dict, repl, update_embedded);
add_dictionary_to_repl(dict, repl, std::move(update_embedded));
}
else {
repl.set(obj.get_table().unchecked_ptr(), col, obj.get_key(), val);
update_embedded(val);
if (update_embedded)
update_embedded(val);
}
}
}
Expand Down

0 comments on commit 807ca5a

Please sign in to comment.