Bug 107095

Summary: Group parameters (firstRuleIndex and lastRuleIndex) into a parameter object, RuleRange.
Product: WebKit Reporter: Hayato Ito <hayato>
Component: CSSAssignee: Hayato Ito <hayato>
Status: RESOLVED FIXED    
Severity: Normal CC: allan.jensen, cmarcelo, macpherson, menard, ojan.autocc, webcomponents-bugzilla, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 89879    
Attachments:
Description Flags
factoring.
none
Introduces a RuleRange
none
Patch for landing none

Description Hayato Ito 2013-01-16 22:40:00 PST
This is a follow up patch for bug 106879.

Both firstRuleIndex and lastRuleIndex can also be grouped into a parameter object.
Comment 1 Hayato Ito 2013-01-16 22:48:13 PST
Created attachment 183124 [details]
factoring.
Comment 2 Darin Adler 2013-01-17 09:26:33 PST
Comment on attachment 183124 [details]
factoring.

View in context: https://bugs.webkit.org/attachment.cgi?id=183124&action=review

Seems OK, but I have a refinement I think would make this cleaner, so I am going to say review+.

> Source/WebCore/css/StyleResolver.h:345
>      struct MatchRequest {

I think a better design would be to make the ruleSet and scope data members const the way the includeEmptyRules member is, then make firstRuleIndex and lastRuleIndex be plain old int members rather than references. Then we could pass non-const MatchRequest& objects in and handle this in a more natural way.

That would also allow us to keep the default initial values for includeEmptyRules and scope, and so be cleaner at the call sites.

It’s really strange for const MatchRequest& to “secretly” have some references in it and so be partly an “out” argument. There’s no reason to be twisted like that.
Comment 3 Hayato Ito 2013-01-17 21:18:48 PST
Created attachment 183368 [details]
Introduces a RuleRange
Comment 4 Hayato Ito 2013-01-17 21:21:58 PST
Thank you for the review.

You are a good reviewer. :) Actually, I and my colleagues were a litte supprised that we could change a value through a reference even if the object is declared 'const'. A reference is a just a pointer internally, so it should not be a surprising fact. But I am feeling that it's confusing for readers and should be avoided.

I've tried your suggestions, but holding plain old int members rather than references causes another buden. The caller has to retrive the result from MatchRequest object and copy them to the collect fields of range. I am afraid that it's error-prone.

I think that mixing const members (ruleSet, scope, ...) and output parameters into one object is the troublesome principally in this case. So I've decided to separete them. RuleRange is now introduced.
This is not a huge win than I expected at first. But that makes code clearer.

You gave me r+, but I think this patch should be reviewed again. Could you review it?

(In reply to comment #2)
> (From update of attachment 183124 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=183124&action=review
> 
> Seems OK, but I have a refinement I think would make this cleaner, so I am going to say review+.
> 
> > Source/WebCore/css/StyleResolver.h:345
> >      struct MatchRequest {
> 
> I think a better design would be to make the ruleSet and scope data members const the way the includeEmptyRules member is, then make firstRuleIndex and lastRuleIndex be plain old int members rather than references. Then we could pass non-const MatchRequest& objects in and handle this in a more natural way.
> 
> That would also allow us to keep the default initial values for includeEmptyRules and scope, and so be cleaner at the call sites.
> 
> It’s really strange for const MatchRequest& to “secretly” have some references in it and so be partly an “out” argument. There’s no reason to be twisted like that.
Comment 5 Hayato Ito 2013-01-23 01:11:16 PST
Let me land this patch in a few days since the pervious patch got r+ and it appears to be relatively safe to land. If there is a concern about this, please let me know.
Comment 6 Dimitri Glazkov (Google) 2013-01-23 08:40:16 PST
Comment on attachment 183368 [details]
Introduces a RuleRange

View in context: https://bugs.webkit.org/attachment.cgi?id=183368&action=review

> Source/WebCore/ChangeLog:13
> +        (WebCore::StyleResolver::collectMatchingRules):

It's customary to explain what's happening in the patch using these lines. I am sure you're just too excited to get this going :)
Comment 7 Hayato Ito 2013-01-23 18:35:55 PST
Created attachment 184374 [details]
Patch for landing
Comment 8 Hayato Ito 2013-01-23 18:37:14 PST
Thank you for the review. Let me land this patch after I add a small explanation to the ChangeLog.

(In reply to comment #6)
> (From update of attachment 183368 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=183368&action=review
> 
> > Source/WebCore/ChangeLog:13
> > +        (WebCore::StyleResolver::collectMatchingRules):
> 
> It's customary to explain what's happening in the patch using these lines. I am sure you're just too excited to get this going :)
Comment 9 WebKit Review Bot 2013-01-23 20:46:46 PST
Comment on attachment 184374 [details]
Patch for landing

Clearing flags on attachment: 184374

Committed r140643: <http://trac.webkit.org/changeset/140643>
Comment 10 WebKit Review Bot 2013-01-23 20:46:50 PST
All reviewed patches have been landed.  Closing bug.