diff --git a/phf_codegen/src/lib.rs b/phf_codegen/src/lib.rs index 6673c708..293b9d97 100644 --- a/phf_codegen/src/lib.rs +++ b/phf_codegen/src/lib.rs @@ -198,6 +198,17 @@ impl Map { self } + /// Clears the entries currently in the builder. + /// + /// Using a single builder and clearing it after calls to [`Self::build`] is more efficent + /// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`]. + pub fn clear_entries(&mut self) -> &mut Map { + self.keys.clear(); + self.values.clear(); + + self + } + /// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed `phf::Map`. /// @@ -302,6 +313,15 @@ impl Set { self } + /// Clears the entries currently in the builder. + /// + /// Using a single builder and clearing it after calls to [`Self::build`] is more efficent + /// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`]. + pub fn clear_entries(&mut self) -> &mut Set { + self.map.clear_entries(); + self + } + /// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed `phf::Set`. /// @@ -358,6 +378,17 @@ impl OrderedMap { self } + /// Clears the entries currently in the builder. + /// + /// Using a single builder and clearing it after calls to [`Self::build`] is more efficent + /// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`]. + pub fn clear_entries(&mut self) -> &mut OrderedMap { + self.keys.clear(); + self.values.clear(); + + self + } + /// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed /// `phf::OrderedMap`. @@ -472,6 +503,15 @@ impl OrderedSet { self } + /// Clears the entries currently in the builder. + /// + /// Using a single builder and clearing it after calls to [`Self::build`] is more efficent + /// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`]. + pub fn clear_entries(&mut self) -> &mut OrderedSet { + self.map.clear_entries(); + self + } + /// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed /// `phf::OrderedSet`.