Closed Bug 1128356 Opened 9 years ago Closed 9 years ago

Add templates to eliminate boilerplate code for frame property destructors

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla38
Tracking Status
firefox38 --- fixed

People

(Reporter: seth, Assigned: seth)

Details

Attachments

(1 file, 1 obsolete file)

Virtually all frame property destructors either call |delete| or |Release()| to destroy the frame property value. We can get rid of a lot of boilerplate and make it easier to add new frame properties by adding some template functions that handle these common cases.
Here's the patch. The actual new template functions live in nsIFrame.h; the rest of the patch just updates everything to use them.
Attachment #8557677 - Flags: review?(dbaron)
Comment on attachment 8557677 [details] [diff] [review]
Add template functions for common frame property destructors

Maybe the templates should be static members of nsIFrame, or, if not,
should be in the mozilla namespace?  I don't have a strong opinion on
this, I guess.

Did you check that the size of the compiled code is roughly the same?

(A few typedefs for some of the repeated types might also be nice,
especially if they are used consistently for all relevant uses.)

r=dbaron with that
Attachment #8557677 - Flags: review?(dbaron) → review+
Thanks for the review!

(In reply to David Baron [:dbaron] (UTC-8) (needinfo? for questions) from comment #2)
> Maybe the templates should be static members of nsIFrame, or, if not,
> should be in the mozilla namespace?  I don't have a strong opinion on
> this, I guess.

I originally had them as static members of nsIFrame, but this required that you write nsIFrame::DeleteValue or the like in many places, which I found too verbose. We can definitely put them in namespace mozilla, though.

> Did you check that the size of the compiled code is roughly the same?

It should be pretty much identical; there's a one-to-one mapping between the old manually written implementations and the instantiations of the new template-based ones.
(In reply to Seth Fowler [:seth] from comment #3)
> > Did you check that the size of the compiled code is roughly the same?
> 
> It should be pretty much identical; there's a one-to-one mapping between the
> old manually written implementations and the instantiations of the new
> template-based ones.

I think it's worth double-checking, just to make sure something strange didn't happen...
OS X XUL size before the patch: 121,478,208 bytes.
OS X XUL size after the patch: 121,479,256 bytes.

A difference of 1KB. I'm pretty sure this is mostly the cost of the symbol names, since symbol names for templates are quite verbose:

> > nm -j obj/toolkit/library/XUL | ag '(Delete|Release)Value' | wc -c
> 1220

Looks about the right ballpark to me.
(In reply to Seth Fowler [:seth] from comment #3)
> We can definitely put them in namespace mozilla, though.

Or not! Just tried this. It turns out that surprisingly many things in layout, including nsIFrame, are not in namespace mozilla. Since these templates are used most of the time in header files, where we can't use 'using', it'd make things significantly more verbose to put it there. Sigh. =(
I went ahead and pushed:

https://hg.mozilla.org/integration/mozilla-inbound/rev/c80e36def0ad

It'd be nice to get more things in layout in namespace mozilla. Perhaps next time I find some time for quick refactoring bug I'll trying to move a big chunk of layout in there.
sorry had to back this out for bustage like https://treeherder.mozilla.org/logviewer.html#?job_id=6200320&repo=mozilla-inbound
Flags: needinfo?(seth)
Sigh. Visual Studio 2013 and we still need to work around MSVC-only compilers bugs. Here's an updated version that doesn't anger MSVC.

Pushed again:

https://hg.mozilla.org/integration/mozilla-inbound/rev/429f9e69e6db
Attachment #8557677 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/429f9e69e6db
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
Flags: needinfo?(seth)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: