[pdm-devel] [PATCH proxmox 2/3] section-config: remove DerefMut and make underlying HashMap private
Gabriel Goller
g.goller at proxmox.com
Wed Apr 23 11:40:16 CEST 2025
On 15.04.2025 10:29, Wolfgang Bumiller wrote:
>1 minor thing...
>
>On Mon, Apr 14, 2025 at 02:00:44PM +0200, Gabriel Goller wrote:
>> [snip]
>> + /// Remove a key-value pair from the section config.
>> + ///
>> + /// If the key existed and was removed, also remove the key from the order vector
>> + /// to maintain ordering consistency.
>> + ///
>> + /// # Returns
>> + ///
>> + /// * `Some(value)` - If the key was present, returns the value that was removed
>> + /// * `None` - If the key was not present
>> + pub fn remove(&mut self, key: &str) -> Option<T> {
>> + let removed_value = self.sections.remove(key);
>> + // only update the order vector if we actually removed something
>> + if removed_value.is_some() {
>> + self.order.retain(|k| k != key);
>
>`retain()` always goes through the entire vector. We don't typically
>have large numbers of sections, so, not that bad, butin general I do
>lean more towards
>
> if let Some(pos) = vec.iter().position(|k| k == key) {
> vec.remove(pos);
> }
>
>when we know there should only be at most 1 such element
Yup, we can guarantee that AFAIK.
Fixed it.
More information about the pdm-devel
mailing list