Bug 237262 - Adopt the modern Hasher more widely
Summary: Adopt the modern Hasher more widely
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-27 17:56 PST by Chris Dumez
Modified: 2022-02-28 15:09 PST (History)
11 users (show)

See Also:


Attachments
Patch (22.07 KB, patch)
2022-02-27 18:07 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (22.26 KB, patch)
2022-02-28 07:40 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (22.44 KB, patch)
2022-02-28 09:24 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2022-02-27 17:56:55 PST
Adopt the modern Hasher more widely.
Comment 1 Chris Dumez 2022-02-27 18:07:49 PST
Created attachment 453364 [details]
Patch
Comment 2 Darin Adler 2022-02-27 22:47:52 PST
Comment on attachment 453364 [details]
Patch

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

review- because Color’s hashing is wrong.

> Source/WebCore/platform/graphics/Color.h:262
> +    add(hasher, color.m_colorAndFlags);

When the color is out of line, this is wrong. We need to hash the data in the out-of-line color, not the pointer, since two colors with different pointers can have the same value. That’s what the old Color::hash function did, and this needs to do the same.

Also, this should take const Color& since it’s expensive to copy a Color when it’s out-of-line.
Comment 3 Chris Dumez 2022-02-28 07:27:50 PST
Comment on attachment 453364 [details]
Patch

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

>> Source/WebCore/platform/graphics/Color.h:262
>> +    add(hasher, color.m_colorAndFlags);
> 
> When the color is out of line, this is wrong. We need to hash the data in the out-of-line color, not the pointer, since two colors with different pointers can have the same value. That’s what the old Color::hash function did, and this needs to do the same.
> 
> Also, this should take const Color& since it’s expensive to copy a Color when it’s out-of-line.

My bad, I did look at the previous hasher but missed the fact that we could end up with a pointer. I'll re-introduce the previous hasher behavior.
Comment 4 Chris Dumez 2022-02-28 07:40:00 PST
Created attachment 453392 [details]
Patch
Comment 5 Sam Weinig 2022-02-28 08:20:57 PST
Comment on attachment 453392 [details]
Patch

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

Love seeing this.

> Source/WebKit/Platform/IPC/StringReference.cpp:62
> +    return computeHash(a);

This parameter names could be better. string? reference? stringReference?
Comment 6 Chris Dumez 2022-02-28 09:24:57 PST
Created attachment 453397 [details]
Patch
Comment 7 EWS 2022-02-28 12:00:44 PST
Committed r290610 (247883@main): <https://commits.webkit.org/247883@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 453397 [details].
Comment 8 Radar WebKit Bug Importer 2022-02-28 12:01:18 PST
<rdar://problem/89573649>
Comment 9 Darin Adler 2022-02-28 13:28:50 PST
Comment on attachment 453397 [details]
Patch

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

> Source/WebCore/platform/graphics/Color.h:265
> +    if (color.isOutOfLine())
> +        add(hasher, color.asOutOfLine().unresolvedComponents(), color.colorSpace(), color.flags().toRaw());
> +    else
> +        add(hasher, color.asPackedInline().value, color.flags().toRaw());

Surprised calling toRaw was needed. We should fix the Hasher mechanism so we don’t need that.
Comment 10 Chris Dumez 2022-02-28 14:02:35 PST
(In reply to Darin Adler from comment #9)
> Comment on attachment 453397 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=453397&action=review
> 
> > Source/WebCore/platform/graphics/Color.h:265
> > +    if (color.isOutOfLine())
> > +        add(hasher, color.asOutOfLine().unresolvedComponents(), color.colorSpace(), color.flags().toRaw());
> > +    else
> > +        add(hasher, color.asPackedInline().value, color.flags().toRaw());
> 
> Surprised calling toRaw was needed. We should fix the Hasher mechanism so we
> don’t need that.

Oh, I don’t know for sure that it was needed, I copied from the pre-existing hashing function.
Comment 11 Chris Dumez 2022-02-28 15:09:57 PST
(In reply to Chris Dumez from comment #10)
> (In reply to Darin Adler from comment #9)
> > Comment on attachment 453397 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=453397&action=review
> > 
> > > Source/WebCore/platform/graphics/Color.h:265
> > > +    if (color.isOutOfLine())
> > > +        add(hasher, color.asOutOfLine().unresolvedComponents(), color.colorSpace(), color.flags().toRaw());
> > > +    else
> > > +        add(hasher, color.asPackedInline().value, color.flags().toRaw());
> > 
> > Surprised calling toRaw was needed. We should fix the Hasher mechanism so we
> > don’t need that.
> 
> Oh, I don’t know for sure that it was needed, I copied from the pre-existing
> hashing function.

It wasn't needed. I fixed it in <https://commits.webkit.org/r290616>.