Closed Bug 307600 Opened 19 years ago Closed 19 years ago

Implement nsIContent::AttrHasValue

Categories

(Core :: DOM: Core & HTML, defect, P1)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

(Keywords: perf)

Attachments

(3 files, 2 obsolete files)

We have a lot of places that GetAttr just to do comparisons on the value.  These
comparisons could be optimized if they were happening inside nsAttrValue in a
lot of cases (with fallback to exactly the speed we have right now).
Depends on: 307601
Attached patch Like so (obsolete) (deleted) β€” β€” Splinter Review
I'll start converting callers in followup bugs once we're happy with the API.

In my testing, if the caller's type (string/atom) matches the callee's type for
the attr this is about 3 times faster than a GetAttr/compare, while if the
types don't match it's still about 30-40% faster.
Attachment #195348 - Flags: superreview?(jst)
Attachment #195348 - Flags: review?(jst)
Priority: -- → P1
Target Milestone: --- → mozilla1.9alpha
Comment on attachment 195348 [details] [diff] [review]
Like so

   virtual PRBool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const = 0;
+  virtual PRBool AttrHasValue(PRInt32 aNameSpaceID,
+			       nsIAtom* aName,
+			       const nsAString& aValue,
+			       PRBool aCaseSensitive) const
+  virtual PRBool AttrHasValue(PRInt32 aNameSpaceID, nsIAtom* aName,
+			       nsIAtom* aValue, PRBool aCaseSensitive) const

I was sort of thinking about naming these HasAttrWithValue(), but I'm not sure
now which is better.

r+sr=jst either way.
Attachment #195348 - Flags: superreview?(jst)
Attachment #195348 - Flags: superreview+
Attachment #195348 - Flags: review?(jst)
Attachment #195348 - Flags: review+
So... People suggested AttrValueIs or AttrIs.  Shaver also objected to having
PR_TRUE/PR_FALSE for the case and said separate methods would be better, but I
couldn't think of any reasonably short names for the case-insensitive one.

Using an enum instead of true/false was also suggested, but I really don't want
to include nsIContent in nsAttrValue.h, and declaring two separate enums that
just happen to share the same values seems fishy to me.

jst?  Thoughts?
Attached patch Patch for checkin (deleted) β€” β€” Splinter Review
Attached patch Additional patch for XTF (obsolete) (deleted) β€” β€” Splinter Review
Attachment #195673 - Flags: superreview?(jst)
Attachment #195673 - Flags: review?(jst)
Attachment #195673 - Flags: superreview?(jst)
Attachment #195673 - Flags: review?(jst)
Attached patch Even compiling (deleted) β€” β€” Splinter Review
Attachment #195673 - Attachment is obsolete: true
Attachment #195676 - Flags: superreview?(jst)
Attachment #195676 - Flags: review?(jst)
Blocks: 308093
Attachment #195348 - Attachment is obsolete: true
Attachment #195708 - Flags: superreview?(jst)
Attachment #195708 - Flags: review?(jst)
Attachment #195676 - Flags: superreview?(jst)
Attachment #195676 - Flags: superreview+
Attachment #195676 - Flags: review?(jst)
Attachment #195676 - Flags: review+
Attachment #195708 - Flags: superreview?(jst)
Attachment #195708 - Flags: superreview+
Attachment #195708 - Flags: review?(jst)
Attachment #195708 - Flags: review+
Fixed.  I'll file followup bugs on other places that can use these methods.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Blocks: 308270
Oh, and it looks like this checkin improved Tdhtml by 5-6%.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: