diff --git a/src/realm/string_interner.cpp b/src/realm/string_interner.cpp index a8f7e2a0204..bbb755bf27d 100644 --- a/src/realm/string_interner.cpp +++ b/src/realm/string_interner.cpp @@ -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(); @@ -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(m_top->get_alloc()); m_current_long_string_node->set_parent(m_data.get(), m_data->size() - 1); @@ -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(); }