File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,8 +112,26 @@ const InterfaceInfo *WitPackage::get_interface(const std::string &name) const
112112
113113void WitPackage::add_interface (const InterfaceInfo &interface)
114114{
115+ // Reserve space to minimize reallocations
116+ if (interfaces.capacity () == interfaces.size ())
117+ {
118+ interfaces.reserve (interfaces.size () * 2 + 8 );
119+ }
120+
115121 interfaces.push_back (interface);
116- interface_map[interface.name ] = &interfaces.back ();
122+
123+ // Rebuild the entire map to ensure all pointers are valid
124+ // This is necessary because vector may have reallocated
125+ rebuild_interface_map ();
126+ }
127+
128+ void WitPackage::rebuild_interface_map ()
129+ {
130+ interface_map.clear ();
131+ for (auto &interface : interfaces)
132+ {
133+ interface_map[interface.name ] = &interface;
134+ }
117135}
118136
119137// PackageRegistry implementation
Original file line number Diff line number Diff line change @@ -69,6 +69,12 @@ struct WitPackage
6969 * Add an interface to this package
7070 */
7171 void add_interface (const InterfaceInfo &interface);
72+
73+ /* *
74+ * Rebuild the interface map to point to current vector elements
75+ * Call this after adding multiple interfaces or when vector may have reallocated
76+ */
77+ void rebuild_interface_map ();
7278};
7379
7480/* *
You can’t perform that action at this time.
0 commit comments