Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused stuff #7108

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions src/realm/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,135 +162,6 @@ MemRef Spec::create_empty_spec(Allocator& alloc)
return spec_set.get_mem();
}

ColKey Spec::update_colkey(ColKey existing_key, size_t spec_ndx, TableKey table_key)
{
auto attr = get_column_attr(spec_ndx);
// index and uniqueness are not passed on to the key, so clear them
attr.reset(col_attr_Indexed);
attr.reset(col_attr_Unique);
auto type = get_column_type(spec_ndx);
if (existing_key.get_type() != type || existing_key.get_attrs() != attr) {
unsigned upper = unsigned(table_key.value);

return ColKey(ColKey::Idx{existing_key.get_index().val}, type, attr, upper);
}
// Existing key is valid
return existing_key;
}

bool Spec::convert_column_attributes()
{
bool changes = false;
size_t enumkey_ndx = 0;

for (size_t column_ndx = 0; column_ndx < m_types.size(); column_ndx++) {
if (column_ndx < m_names.size()) {
StringData name = m_names.get(column_ndx);
if (name.size() == 0) {
auto new_name = std::string("col_") + util::to_string(column_ndx);
m_names.set(column_ndx, new_name);
changes = true;
}
else if (m_names.find_first(name) != column_ndx) {
auto new_name = std::string(name.data()) + '_' + util::to_string(column_ndx);
m_names.set(column_ndx, new_name);
changes = true;
}
}
ColumnType type = ColumnType(int(m_types.get(column_ndx)));
ColumnAttrMask attr = ColumnAttrMask(m_attr.get(column_ndx));
switch (type) {
case col_type_Link:
if (!attr.test(col_attr_Nullable)) {
attr.set(col_attr_Nullable);
m_attr.set(column_ndx, attr.m_value);
changes = true;
}
break;
case col_type_LinkList:
if (!attr.test(col_attr_List)) {
attr.set(col_attr_List);
m_attr.set(column_ndx, attr.m_value);
changes = true;
}
break;
default:
if (type == col_type_OldTable) {
Array subspecs(m_top.get_alloc());
subspecs.set_parent(&m_top, 3);
subspecs.init_from_parent();

Spec sub_spec(get_alloc());
size_t subspec_ndx = get_subspec_ndx(column_ndx);
ref_type ref = to_ref(subspecs.get(subspec_ndx)); // Throws
sub_spec.init(ref);
REALM_ASSERT(sub_spec.get_column_count() == 1);
m_types.set(column_ndx, int(sub_spec.get_column_type(0)));
m_attr.set(column_ndx, m_attr.get(column_ndx) | sub_spec.m_attr.get(0) | col_attr_List);
sub_spec.destroy();

subspecs.erase(subspec_ndx);
changes = true;
}
else if (type == col_type_OldStringEnum) {
m_types.set(column_ndx, int(col_type_String));
// We need to padd zeroes into the m_enumkeys so that the index in
// m_enumkeys matches the column index.
for (size_t i = enumkey_ndx; i < column_ndx; i++) {
m_enumkeys.insert(i, 0);
}
enumkey_ndx = column_ndx + 1;
changes = true;
}
else {
REALM_ASSERT_RELEASE(type.is_valid());
}
break;
}
}
if (m_enumkeys.is_attached()) {
while (m_enumkeys.size() < m_num_public_columns) {
m_enumkeys.add(0);
}
}
return changes;
}

bool Spec::convert_column_keys(TableKey table_key)
{
// This step will ensure that the column keys has right attribute and type info
bool changes = false;
auto sz = m_types.size();
for (size_t ndx = 0; ndx < sz; ndx++) {
ColKey existing_key = ColKey{m_keys.get(ndx)};
ColKey col_key = update_colkey(existing_key, ndx, table_key);
if (col_key != existing_key) {
m_keys.set(ndx, col_key.value);
changes = true;
}
}
return changes;
}

void Spec::fix_column_keys(TableKey table_key)
{
if (get_column_name(m_num_public_columns - 1) == "!ROW_INDEX") {
unsigned idx = unsigned(m_types.size()) - 1;
size_t ndx = m_num_public_columns - 1;
// Fixing "!ROW_INDEX" column
{
ColKey col_key(ColKey::Idx{idx}, col_type_Int, ColumnAttrMask(), table_key.value);
m_keys.set(ndx, col_key.value);
}
// Fix backlink columns
idx = unsigned(m_num_public_columns) - 1;
for (ndx = m_num_public_columns; ndx < m_types.size(); ndx++, idx++) {
ColKey col_key(ColKey::Idx{idx}, col_type_BackLink, ColumnAttrMask(), table_key.value);
m_keys.set(ndx, col_key.value);
}
}
}

void Spec::insert_column(size_t column_ndx, ColKey col_key, ColumnType type, StringData name, int attr)
{
REALM_ASSERT(column_ndx <= m_types.size());
Expand Down Expand Up @@ -357,33 +228,6 @@ void Spec::erase_column(size_t column_ndx)
update_internals();
}

// For link and link list columns the old subspec array contain an entry which
// is the group-level table index of the target table, and for backlink
// columns the first entry is the group-level table index of the origin
// table, and the second entry is the index of the origin column in the
// origin table.
size_t Spec::get_subspec_ndx(size_t column_ndx) const noexcept
{
REALM_ASSERT(column_ndx == get_column_count() || get_column_type(column_ndx) == col_type_Link ||
get_column_type(column_ndx) == col_type_LinkList ||
get_column_type(column_ndx) == col_type_BackLink ||
// col_type_OldTable is used when migrating from file format 9 to 10.
get_column_type(column_ndx) == col_type_OldTable);

size_t subspec_ndx = 0;
for (size_t i = 0; i != column_ndx; ++i) {
ColumnType type = ColumnType(int(m_types.get(i)));
if (type == col_type_Link || type == col_type_LinkList) {
subspec_ndx += 1; // index of dest column
}
else if (type == col_type_BackLink) {
subspec_ndx += 2; // index of table and index of linked column
}
}
return subspec_ndx;
}


void Spec::upgrade_string_to_enum(size_t column_ndx, ref_type keys_ref)
{
REALM_ASSERT(get_column_type(column_ndx) == col_type_String);
Expand Down
10 changes: 0 additions & 10 deletions src/realm/spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,10 @@ class Spec {

void set_column_attr(size_t column_ndx, ColumnAttrMask attr);

// Migration
bool convert_column_attributes();
bool convert_column_keys(TableKey table_key);
void fix_column_keys(TableKey table_key);


// Generate a column key only from state in the spec.
ColKey update_colkey(ColKey existing_key, size_t spec_ndx, TableKey table_key);
/// Construct an empty spec and return just the reference to the
/// underlying memory.
static MemRef create_empty_spec(Allocator&);

size_t get_subspec_ndx(size_t column_ndx) const noexcept;

friend class Group;
friend class Table;
};
Expand Down
2 changes: 1 addition & 1 deletion test/util/compare_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ bool compare_tables(const Table& table_1, const Table& table_2, util::Logger& lo

bool compare_groups(const Transaction& group_1, const Transaction& group_2)
{
util::StderrLogger logger;
util::StderrLogger logger(util::Logger::Level::off);
return compare_groups(group_1, group_2, logger);
}

Expand Down
Loading