You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize hashset (and possibly similar HashMap?) usage when the user first uses contains() to check the non-existence of a value, followed by insertion.
Advantage
Faster code
Shorter code
Drawbacks
No response
Example
use std::collections::HashSet;fnmain(){letmut vals = HashSet::new();insert_if(&mut vals,10);}fninsert_if(set:&mutHashSet<i32>,value:i32){if !set.contains(&value){
set.insert(value);println!("inserted {value:?}");}}
Interesting! I will try to do it. I might need some help, though :)
If you know some other lint that has similar logic (looking if two expressions happen one after another and then linting) let me know.
What it does
Optimize hashset (and possibly similar HashMap?) usage when the user first uses
contains()
to check the non-existence of a value, followed by insertion.Advantage
Drawbacks
No response
Example
Could be written as:
The text was updated successfully, but these errors were encountered: