Implement real update in the rule view

RESOLVED FIXED in Firefox 15

Status

()

Firefox
Developer Tools: Inspector
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dcamp, Assigned: dcamp)

Tracking

13 Branch
Firefox 15
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

5 years ago
Created attachment 625796 [details] [diff] [review]
v1

The rule view doesn't have a real refresh method.  When we refresh for pseudo-class lock it's a complete destroy + rebuild, which can lose a small amount of user data (disabled properties, doubled-up properties, etc) as well as being a bit inefficient.

Attached patch implements a real refresh method for the rule view.

Asking for review from Rob because he did the initial rule view review, but if paul wants to steal the review I wouldn't complain.
Attachment #625796 - Flags: review?(rcampbell)

Comment 1

5 years ago
(I think you forgot to remove a couple of dump calls)
(Assignee)

Comment 2

5 years ago
Indeed, will get rid of them in the next version of the patch.
Comment on attachment 625796 [details] [diff] [review]
v1

-    let rule = new Rule(this, aOptions);
+    let rule = null;
+
+    // If we're refreshing and the rule previously existed, reuse the
+    // Rule object.
+    for each (let r in (this._refreshRules || [])) {
+      if (r.matches(aOptions)) {
+        rule = r;
+        rule.refresh();
+        break;
+      }
+    }
+
+    // If this is a new rule, create its Rule object.
+    if (!rule) {
+      rule = new Rule(this, aOptions);
+    }

I might rework this a bit.

let rule = null;
for each (rule in (this._refreshRules || [])) {
  if (rule.matches(aOptions)) {
     rule.refresh();
     break;
  }
}

gets rid of an extra assignment, I think.

   /**
+   * Returns true if the rule matches the creation options
+   * specified.
+   */
+  matches: function Rule_matches(aOptions)
+  {
+    return (this.style === (aOptions.style || aOptions.domRule.style));
+  },

Could use an @param on your javadoc.

NIT in _getTextProperties:

in for each loop:

if(!matches || !matches[2])
         continue;
 
missing space.


+  _updateTextProperty: function Rule__updateTextProperty(aNewProp) {

could use an @param in your javadoc.

+      let rank = 1;

maybe add a comment // 1 for matching name

+      if (prop.enabled) {
+        rank += 1;
+      }

that's only worth 1? :)

After reading through this, I might score the rankings in your method comment:

+   *   Name, value, and priority match, enabled. (6)
+   *   Name, value, and priority match, disabled. (5)
+   *   Name and value match, enabled (4)
+   *   Name and value match, disabled (3)
+   *   Name matches, enabled (2)
+   *   Name matches, disabled. (1)

not sure if that helps or not.

in nodeChanged:
+    dump("Refresh took " + (end - start) + "ms\n");

one of the missed dumps, I presume. don't forget the start and end times.
Attachment #625796 - Flags: review?(rcampbell) → review+
(In reply to Rob Campbell [:rc] (:robcee) from comment #3)
> Comment on attachment 625796 [details] [diff] [review]
> v1
> 
> -    let rule = new Rule(this, aOptions);
> +    let rule = null;
> +
> +    // If we're refreshing and the rule previously existed, reuse the
> +    // Rule object.
> +    for each (let r in (this._refreshRules || [])) {
> +      if (r.matches(aOptions)) {
> +        rule = r;
> +        rule.refresh();
> +        break;
> +      }
> +    }
> +
> +    // If this is a new rule, create its Rule object.
> +    if (!rule) {
> +      rule = new Rule(this, aOptions);
> +    }
> 
> I might rework this a bit.
> 
> let rule = null;
> for each (rule in (this._refreshRules || [])) {

Make this a for...of loop:
for (foo of (this._refreshRules || [])) {
(Assignee)

Updated

5 years ago
Blocks: 740543
(Assignee)

Comment 5

5 years ago
Created attachment 628446 [details] [diff] [review]
v2
Attachment #625796 - Attachment is obsolete: true
(Assignee)

Comment 6

5 years ago
(In reply to Rob Campbell [:rc] (:robcee) from comment #3)
> I might rework this a bit.
> 
> let rule = null;
> for each (rule in (this._refreshRules || [])) {
>   if (rule.matches(aOptions)) {
>      rule.refresh();
>      break;
>   }
> }
> 
> gets rid of an extra assignment, I think.

Yeah, but it leaves rule assigned if rule didn't match any rule.

I didn't come up with a more compact way to do this.

> +  matches: function Rule_matches(aOptions)
> Could use an @param on your javadoc.

Done.

> NIT in _getTextProperties:
> missing space.

Done.

> +  _updateTextProperty: function Rule__updateTextProperty(aNewProp) {
> could use an @param in your javadoc.

Done.

> +      let rank = 1;
> 
> maybe add a comment // 1 for matching name
> 
> +      if (prop.enabled) {
> +        rank += 1;
> +      }
> 
> that's only worth 1? :)

I beefed up inline comments about the ranking system.

> 
> After reading through this, I might score the rankings in your method
> comment:
> not sure if that helps or not.

I think it did, I added those.

> in nodeChanged:
> +    dump("Refresh took " + (end - start) + "ms\n");
> 
> one of the missed dumps, I presume. don't forget the start and end times.

Stripped out that dump and associated timers.

(In reply to Dão Gottwald [:dao] from comment #4)
> Make this a for...of loop:
> for (foo of (this._refreshRules || [])) {

Indeed, I did this throughout the patch.
(Assignee)

Comment 7

5 years ago
https://tbpl.mozilla.org/?tree=Try&rev=2e9df75cda67
(Assignee)

Comment 8

5 years ago
https://hg.mozilla.org/integration/fx-team/rev/40462fc79a4b
Whiteboard: [fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/40462fc79a4b
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 15
You need to log in before you can comment on or make changes to this bug.