Skip to content

Commit

Permalink
third bugfix in interning large strings
Browse files Browse the repository at this point in the history
  • Loading branch information
finnschiermer committed May 31, 2024
1 parent eac7dd0 commit 6e2c636
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/realm/string_interner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ static void add_to_hash_map(Array& node, uint64_t hash, uint64_t id, uint8_t has
new_size *= 2;
new_node.create(NodeHeader::type_Normal, false, new_size, 0);
need_to_rehash = !rehash(node, new_node, hash_size);
if (need_to_rehash) // we failed, try again - or shift to radix
if (need_to_rehash) { // we failed, try again - or shift to radix
new_node.destroy();
std::cout << "Repeated rehash from " << node.size() << " to " << new_size << std::endl;
}
}
new_node.set_parent(node.get_parent(), node.get_ndx_in_parent());
new_node.update_parent();
Expand Down Expand Up @@ -424,7 +426,14 @@ StringID StringInterner::intern(StringData sd)
m_current_string_leaf->detach();
}
else {
REALM_ASSERT_DEBUG(m_current_string_leaf);
// we have been building an existing leaf and need to shift representation.
// but first we need to update leaf accessor for existing leaf
if (m_current_string_leaf->is_attached()) {
m_current_string_leaf->update_from_parent();
}
else {
m_current_string_leaf->init_from_ref(m_current_string_leaf->get_ref_from_parent());
}
REALM_ASSERT_DEBUG(m_current_string_leaf->size() > 0);
m_current_long_string_node = std::make_unique<Array>(m_top->get_alloc());
m_current_long_string_node->set_parent(m_data.get(), m_data->size() - 1);
Expand Down Expand Up @@ -467,15 +476,17 @@ StringID StringInterner::intern(StringData sd)
else {
// Append to leaf with up to 256 entries.
// First create a new leaf if needed (limit number of entries to 256 pr leaf)
bool need_new_leaf = !m_current_string_leaf->is_attached() || (index & 0xFF) == 0;
if (need_new_leaf) {
bool need_leaf_update = !m_current_string_leaf->is_attached() || (index & 0xFF) == 0;
if (need_leaf_update) {
m_current_string_leaf->set_parent(m_data.get(), index >> 8);
if ((index & 0xFF) == 0) {
// create new leaf
m_current_string_leaf->create(0, 65535);
m_data->add(m_current_string_leaf->get_ref());
m_compressed_leafs.push_back({});
}
else {
// just setup leaf accessor
if (m_current_string_leaf->is_attached()) {
m_current_string_leaf->update_from_parent();
}
Expand Down

0 comments on commit 6e2c636

Please sign in to comment.