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

WIP: replaced Vec with HashSet in gstreamer muteables #278

Closed
wants to merge 1 commit into from

Conversation

@khodzha
Copy link
Contributor

khodzha commented Jul 7, 2019

@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.rs file or be separated into another one)

Copy link
Member

ferjm left a comment

Thanks, @khodzha! A HashSet is an improvement, but I think we can do it without duplicating the ids.

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);

This comment has been minimized.

@ferjm

ferjm Jul 8, 2019

Member

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 {

This comment has been minimized.

@ferjm

ferjm Jul 8, 2019

Member

is_empty is more idiomatic.


lazy_static! {
static ref BACKEND_BASE_TIME: gst::ClockTime = { gst::SystemClock::obtain().get_time() };
}

struct IdMuteable {
id: usize,

This comment has been minimized.

@ferjm

ferjm Jul 8, 2019

Member

Players and AudioContexts already have their own ids. I think there is no need to duplicated them here.

This comment has been minimized.

@khodzha

khodzha Jul 8, 2019

Author Contributor

yes, but we have only Weak<Mutex<dyn Muteable>>, is locking mutex just to get an id fine?

This comment has been minimized.

@ferjm

ferjm Jul 8, 2019

Member

Hmm, I think that should be fine.

This comment has been minimized.

@khodzha

khodzha Jul 9, 2019

Author Contributor

ah, this id is also used for Eq + Hash!


lazy_static! {
static ref BACKEND_BASE_TIME: gst::ClockTime = { gst::SystemClock::obtain().get_time() };
}

struct IdMuteable {

This comment has been minimized.

@ferjm

ferjm Jul 8, 2019

Member

nit: Let's rename this to MuteableRef.

@khodzha
Copy link
Contributor Author

khodzha commented Jul 10, 2019

After a discussion with @ferjm it was decided HashSet doesnt provide much of a benefit since in current implementation retain() loop cant be replaced with a remove() (which was the idea behind using HashSet in the first place).

So I'm closing this PR.

@khodzha khodzha closed this Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.