Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the HashMap's Entry API #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Feb 26, 2023

  1. Switch to the HashMap's Entry API

    Improvement:
    - When doing `if get_mut(..) else .insert` it doesn't rehash the key
    - It is arguably more readable
    
    Problems:
    - When filling up the `df` HashMap, it clones the string unnecessarily:
    
        Old code:
        ```rust
        if let Some(freq) = self.df.get_mut(t) {
            *freq += 1;
        } else {
            // `t` is only cloned when the key is not present
            self.df.insert(t.clone(), 1);
        }
        ```
    
        ```rust
        // Always clones `t`
        self.df.entry(t.clone())
            .and_modify(|freq| *freq += 1)
            .or_insert(1);
        ```
    - Uses closures so performance in `debug` builds might degrade
    jalil-salame committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    70e8298 View commit details
    Browse the repository at this point in the history