diff --git a/arcane/src/arcane/mesh/ItemInternalMap.h b/arcane/src/arcane/mesh/ItemInternalMap.h index 03d36fcc9..f782d2653 100644 --- a/arcane/src/arcane/mesh/ItemInternalMap.h +++ b/arcane/src/arcane/mesh/ItemInternalMap.h @@ -153,9 +153,18 @@ class ARCANE_MESH_EXPORT ItemInternalMap return (m_new_impl.find(key) != m_new_impl.end()); } - //! Resizes the hash table - void resize([[maybe_unused]] Int32 new_size, [[maybe_unused]] bool use_prime = false) + /*! + * \brief Makes room for \a new_size entries. + * + * Called before a batch of insertions by a family that knows how many items it + * is about to add, so that the table is sized once instead of growing by + * doubling and rehashing at each step. \a use_prime belonged to the previous + * implementation and is ignored. + */ + void resize(Int32 new_size, [[maybe_unused]] bool use_prime = false) { + if (new_size > 0) + m_new_impl.reserve(static_cast(new_size), false); } /*! diff --git a/arcane/src/arcane/std/CartesianMeshGenerator.cc b/arcane/src/arcane/std/CartesianMeshGenerator.cc index f391f4d13..b5ab53fb8 100644 --- a/arcane/src/arcane/std/CartesianMeshGenerator.cc +++ b/arcane/src/arcane/std/CartesianMeshGenerator.cc @@ -660,7 +660,11 @@ generateMesh() // Création hash-table des noeuds et préparation de leurs uid UniqueArray nodes_unique_id(CheckedConvert::toInteger(own_nb_node_xyz)); - HashTableMapT nodes_infos(CheckedConvert::toInteger(own_nb_node_xyz), true); + // The size of a HashTableMapT is a number of buckets and not a number of + // entries: it rehashes as soon as its count passes 0.85 * nb_bucket, so the + // table is sized for the load factor and holds every node without rehashing. + const Int64 wanted_bucket = static_cast(own_nb_node_xyz / 0.85) + 1; + HashTableMapT nodes_infos(CheckedConvert::toInteger(wanted_bucket), true); // Calcule des infos blocs et des offset associés à tous les sub_domain_id IntegerUniqueArray sd_x_ibl, sd_x_obl; // Numéro et offset dans le bloc