Closed Bug 1286760 Opened 8 years ago Closed 8 years ago

The member initialization list of MediaDecoderStateMachine is a bit messy

Categories

(Core :: Audio/Video: Playback, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox50 --- fixed

People

(Reporter: jwwang, Assigned: jwwang)

References

Details

Attachments

(1 file)

We will use some macros to make the code more compact and more readable.
Assignee: nobody → jwwang
Comment on attachment 8770844 [details]
Bug 1286760 - use macro to simplify the code.

https://reviewboard.mozilla.org/r/64176/#review61222

I hate macros, but it does look better there, so fiiine: r+ with issue addressed.

Also, if similar macros could be useful in other files, you may want to create generic macros in StateWatching.h, and then have the macros in this file refine the generic ones with the local details ('mTaskQueue' and "MediaDecoderStateMachine::") -- But this could be a separate bug for later.

::: dom/media/MediaDecoderStateMachine.cpp:220
(Diff revision 1)
> +#define DECL_WATCHABLE(name, val) \
> +  name(val, "MediaDecoderStateMachine::" #name)
> +#define DECL_MIRROR(name, val) \
> +  name(mTaskQueue, val, "MediaDecoderStateMachine::" #name "(Mirror)")
> +#define DECL_CANONICAL(name, val) \
> +  name(mTaskQueue, val, "MediaDecoderStateMachine::" #name "(Canonical)")

These macros are used to *initialize* (not declare) members, so shouldn't they rather start with "INIT_"?

::: dom/media/MediaDecoderStateMachine.cpp:222
(Diff revision 1)
> +#define DECL_MIRROR(name, val) \
> +  name(mTaskQueue, val, "MediaDecoderStateMachine::" #name "(Mirror)")
> +#define DECL_CANONICAL(name, val) \
> +  name(mTaskQueue, val, "MediaDecoderStateMachine::" #name "(Canonical)")

Add a space at the start of " (Mirror)" and " (Canonical)" to match the original strings, unless you *do* want to remove that space.
Attachment #8770844 - Flags: review?(gsquelart) → review+
https://reviewboard.mozilla.org/r/64176/#review61222

Can you illustrate how this could be done?

> These macros are used to *initialize* (not declare) members, so shouldn't they rather start with "INIT_"?

Will do.

> Add a space at the start of " (Mirror)" and " (Canonical)" to match the original strings, unless you *do* want to remove that space.

Will add the space.
Comment on attachment 8770844 [details]
Bug 1286760 - use macro to simplify the code.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/64176/diff/1-2/
https://reviewboard.mozilla.org/r/64176/#review61222

Sorry if I was unclear. I was thinking of something like this:

StateWatching.h:
#define INIT_MIRROR(class, taskqueue, name, val) \
  name(taskqueue, val, #class "::" #name "(Mirror)")

MediaDecoderStateMachine.cpp:
#define INIT_MSDM_MIRROR(name, val) \
  INIT_MIRROR(MediaDecoderStateMachine, mTaskQueue, name, val)

This way other classes could follow the same pattern by copying what's in MDSM.cpp, and all such files would be consistent.

Disclaimer: I'm scared of nested macros, so make sure that it actually works if you want to go ahead with it!
IMHO, INIT_MIRROR is just too thin to reduce complexity as much as nested macro adds. Consistency is easy to achieve when the macro is simple. I would prefer to define a similar INIT_MIRROR when it come to MediaDecoder member initialization.
Pushed by jwwang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/cb1812acfcd1
use macro to simplify the code. r=gerald
(In reply to JW Wang [:jwwang] from comment #6)
> IMHO, INIT_MIRROR is just too thin to reduce complexity as much as nested
> macro adds. Consistency is easy to achieve when the macro is simple. I would
> prefer to define a similar INIT_MIRROR when it come to MediaDecoder member
> initialization.

Makes sense. Thank you for considering it.
Thanks for the review!
https://hg.mozilla.org/mozilla-central/rev/cb1812acfcd1
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
See Also: → 1294636
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: