WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
44107
CSS: Make rgb() and rgba() fast paths case-insensitive
https://bugs.webkit.org/show_bug.cgi?id=44107
Summary
CSS: Make rgb() and rgba() fast paths case-insensitive
Andreas Kling
Reported
2010-08-17 07:07:26 PDT
The fast path in CSSParser::parseColor() could easily catch RGB() and RGBA() as well. Instead of equalIgnoringCase(), we can do inline character comparison and gain some speed while we're at it, too.
Attachments
Proposed patch
(2.58 KB, patch)
2010-08-17 07:13 PDT
,
Andreas Kling
no flags
Details
Formatted Diff
Diff
Proposed patch v2
(2.51 KB, patch)
2010-08-18 09:24 PDT
,
Andreas Kling
darin
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Andreas Kling
Comment 1
2010-08-17 07:13:12 PDT
Created
attachment 64588
[details]
Proposed patch
Ariya Hidayat
Comment 2
2010-08-17 17:25:24 PDT
Comment on
attachment 64588
[details]
Proposed patch
> - if (name.startsWith("rgba(")) { > + if (mightBeRGBA(characters, length)) {
Will there be a (minor) behavior difference IF the input is invalid e.g. "rgba(foo"?
Andreas Kling
Comment 3
2010-08-17 17:36:54 PDT
(In reply to
comment #2
)
> (From update of
attachment 64588
[details]
) > > - if (name.startsWith("rgba(")) { > > + if (mightBeRGBA(characters, length)) { > > Will there be a (minor) behavior difference IF the input is invalid e.g. "rgba(foo"?
The invalid string "rgba(foo" will fail via Color::setNamedColor() below instead of inside the fast rgba() parser. Behavior won't change but you have a point - it will be slightly slower for invalid strings. I will update the patch.
Andreas Kling
Comment 4
2010-08-18 09:24:52 PDT
Created
attachment 64719
[details]
Proposed patch v2 Updated to avoid performance regression for invalid colors.
Darin Adler
Comment 5
2010-08-18 10:26:01 PDT
Comment on
attachment 64719
[details]
Proposed patch v2
> +static inline bool mightBeRGBA(const UChar* characters, unsigned length) > +{ > + if (length < 5) > + return false; > + return characters[4] == '(' > + && (characters[0] == 'r' || characters[0] == 'R') > + && (characters[1] == 'g' || characters[1] == 'G') > + && (characters[2] == 'b' || characters[2] == 'B') > + && (characters[3] == 'a' || characters[3] == 'A'); > +}
This kind of check can be done considerably more efficiently like this: && (characters[0] | 0x20) == 'r' && (characters[1] | 0x20) == 'b' r=me as-is but consider my faster version
Andreas Kling
Comment 6
2010-08-18 10:56:29 PDT
(In reply to
comment #5
)
> r=me as-is but consider my faster version
Indeed, Ariya was saying the same thing on IRC. I will land with that modification. Thanks!
Andreas Kling
Comment 7
2010-08-18 13:05:31 PDT
Committed
r65626
: <
http://trac.webkit.org/changeset/65626
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug