| Summary: | Provide more efficient implementation for WTF::DefaultHash<bool> | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Chris Dumez <cdumez> | ||||
| Component: | Web Template Framework | Assignee: | Chris Dumez <cdumez> | ||||
| Status: | RESOLVED INVALID | ||||||
| Severity: | Normal | CC: | andersca, benjamin, cmarcelo, commit-queue, darin, koivisto | ||||
| Priority: | P2 | ||||||
| Version: | 528+ (Nightly build) | ||||||
| Hardware: | Unspecified | ||||||
| OS: | Unspecified | ||||||
| Bug Depends on: | 140848 | ||||||
| Bug Blocks: | |||||||
| Attachments: |
|
||||||
|
Description
Chris Dumez
2015-01-24 11:25:22 PST
Created attachment 245287 [details]
Patch
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.
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. 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. |