WIP: replaced Vec with HashSet in gstreamer muteables#278
WIP: replaced Vec with HashSet in gstreamer muteables#278khodzha wants to merge 1 commit intoservo:masterfrom
Conversation
| vec.retain(|m| m.0 != muteable_id); | ||
| if vec.len() == 0 { | ||
| if let Some(set) = muteables.get_mut(&id) { | ||
| set.retain(|m| m.id != muteable_id); |
There was a problem hiding this comment.
The benefit of using a HashSet here is to avoid this loop, right? So this should probably be:
if !set.remove(mutable_id) {
warn!("Tried to remove an unknown Muteable");
}| if vec.len() == 0 { | ||
| if let Some(set) = muteables.get_mut(&id) { | ||
| set.retain(|m| m.id != muteable_id); | ||
| if set.len() == 0 { |
| } | ||
|
|
||
| struct IdMuteable { | ||
| id: usize, |
There was a problem hiding this comment.
Players and AudioContexts already have their own ids. I think there is no need to duplicated them here.
There was a problem hiding this comment.
yes, but we have only Weak<Mutex<dyn Muteable>>, is locking mutex just to get an id fine?
There was a problem hiding this comment.
Hmm, I think that should be fine.
There was a problem hiding this comment.
ah, this id is also used for Eq + Hash!
| static ref BACKEND_BASE_TIME: gst::ClockTime = { gst::SystemClock::obtain().get_time() }; | ||
| } | ||
|
|
||
| struct IdMuteable { |
There was a problem hiding this comment.
nit: Let's rename this to MuteableRef.
|
After a discussion with @ferjm it was decided HashSet doesnt provide much of a benefit since in current implementation So I'm closing this PR. |
@ferjm you've been suggesting HashSet from the start yet because we didn't have an id back then I went with Vec.
But since we already add usize ids to muteables Vec I suppose we can just utilize it for Hash + Eq and replace Vec with HashSet now.
(I'm not sure whether IdMuteable is appropriate naming at all and also whether it should go straight to
lib.rsfile or be separated into another one)