WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
140858
Provide more efficient implementation for WTF::DefaultHash<bool>
https://bugs.webkit.org/show_bug.cgi?id=140858
Summary
Provide more efficient implementation for WTF::DefaultHash<bool>
Chris Dumez
Reported
2015-01-24 11:25:22 PST
Provide more efficient implementation for WTF::DefaultHash<bool>. Right now, it merely calls intHash(uint8_t) which is a bit wasteful.
Attachments
Patch
(2.11 KB, patch)
2015-01-24 11:27 PST
,
Chris Dumez
darin
: review-
darin
: commit-queue-
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2015-01-24 11:27:56 PST
Created
attachment 245287
[details]
Patch
WebKit Commit Bot
Comment 2
2015-01-24 11:29:41 PST
Attachment 245287
[details]
did not pass style-queue: ERROR: Source/WTF/wtf/HashFunctions.h:182: More than one command on the same line [whitespace/newline] [4] Total errors found: 1 in 2 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 3
2015-01-24 15:06:38 PST
Comment on
attachment 245287
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=245287&action=review
Not sure this optimization is important. But this patch doesn’t successfully apply it.
> Source/WTF/wtf/HashFunctions.h:41 > + return key1 ? 0x62baf5a0 : 0x4636b9c9;
WebKit mostly uses uppercase hex; this is lowercase. How did you choose the branching version of this over the arithmetic version?
> Source/WTF/wtf/HashFunctions.h:182 > + template<> struct DefaultHash<bool> { typedef IntHash<bool> Hash; };
This is not enough to get intHash(bool) called. The problem is that the IntHash struct template casts to IntTypes<sizeof(T)>::UnsignedType, so it’s going to choose some kind of integer type based on sizeof(bool). That’s not what we want. I think we’ll need: struct BoolHash { static unsigned hash(bool key) { return intHash(key); } static bool equal(bool a, bool b) { return a == b; } static const bool safeToCompareToEmptyOrDeleted = true; }; You can test by setting a breakpoint in a debug build and seeing the new function isn’t called.
Chris Dumez
Comment 4
2015-01-24 15:15:50 PST
Comment on
attachment 245287
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=245287&action=review
I am not sure this optimization is very important either, but since you commented, I figured I would write a quick patch.
>> Source/WTF/wtf/HashFunctions.h:41 >> + return key1 ? 0x62baf5a0 : 0x4636b9c9; > > WebKit mostly uses uppercase hex; this is lowercase. How did you choose the branching version of this over the arithmetic version?
I only considered simplicity / readability. I haven't actually measured if one version is faster than the others. Wouldn't be difficult to benchmark those though if we want.
>> Source/WTF/wtf/HashFunctions.h:182 >> + template<> struct DefaultHash<bool> { typedef IntHash<bool> Hash; }; > > This is not enough to get intHash(bool) called. The problem is that the IntHash struct template casts to IntTypes<sizeof(T)>::UnsignedType, so it’s going to choose some kind of integer type based on sizeof(bool). That’s not what we want. I think we’ll need: > > struct BoolHash { > static unsigned hash(bool key) { return intHash(key); } > static bool equal(bool a, bool b) { return a == b; } > static const bool safeToCompareToEmptyOrDeleted = true; > }; > > You can test by setting a breakpoint in a debug build and seeing the new function isn’t called.
Right, sorry about that. I didn't see IntHash was using typename IntTypes<sizeof(T)>::UnsignedType.
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