<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>140858</bug_id>
          
          <creation_ts>2015-01-24 11:25:22 -0800</creation_ts>
          <short_desc>Provide more efficient implementation for WTF::DefaultHash&lt;bool&gt;</short_desc>
          <delta_ts>2015-01-30 18:45:58 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>140848</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chris Dumez">cdumez</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>andersca</cc>
    
    <cc>benjamin</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>commit-queue</cc>
    
    <cc>darin</cc>
    
    <cc>koivisto</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1063929</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-01-24 11:25:22 -0800</bug_when>
    <thetext>Provide more efficient implementation for WTF::DefaultHash&lt;bool&gt;. Right now, it merely calls intHash(uint8_t) which is a bit wasteful.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063930</commentid>
    <comment_count>1</comment_count>
      <attachid>245287</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-01-24 11:27:56 -0800</bug_when>
    <thetext>Created attachment 245287
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063931</commentid>
    <comment_count>2</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-01-24 11:29:41 -0800</bug_when>
    <thetext>Attachment 245287 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063935</commentid>
    <comment_count>3</comment_count>
      <attachid>245287</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-01-24 15:06:38 -0800</bug_when>
    <thetext>Comment on attachment 245287
Patch

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

Not sure this optimization is important. But this patch doesn’t successfully apply it.

&gt; Source/WTF/wtf/HashFunctions.h:41
&gt; +        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?

&gt; Source/WTF/wtf/HashFunctions.h:182
&gt; +    template&lt;&gt; struct DefaultHash&lt;bool&gt; { typedef IntHash&lt;bool&gt; Hash; };

This is not enough to get intHash(bool) called. The problem is that the IntHash struct template casts to IntTypes&lt;sizeof(T)&gt;::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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063936</commentid>
    <comment_count>4</comment_count>
      <attachid>245287</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-01-24 15:15:50 -0800</bug_when>
    <thetext>Comment on attachment 245287
Patch

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

I am not sure this optimization is very important either, but since you commented, I figured I would write a quick patch.

&gt;&gt; Source/WTF/wtf/HashFunctions.h:41
&gt;&gt; +        return key1 ? 0x62baf5a0 : 0x4636b9c9;
&gt; 
&gt; 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&apos;t actually measured if one version is faster than the others. Wouldn&apos;t be difficult to benchmark those though if we want.

&gt;&gt; Source/WTF/wtf/HashFunctions.h:182
&gt;&gt; +    template&lt;&gt; struct DefaultHash&lt;bool&gt; { typedef IntHash&lt;bool&gt; Hash; };
&gt; 
&gt; This is not enough to get intHash(bool) called. The problem is that the IntHash struct template casts to IntTypes&lt;sizeof(T)&gt;::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:
&gt; 
&gt;     struct BoolHash {
&gt;         static unsigned hash(bool key) { return intHash(key); }
&gt;         static bool equal(bool a, bool b) { return a == b; }
&gt;         static const bool safeToCompareToEmptyOrDeleted = true;
&gt;     };
&gt; 
&gt; 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&apos;t see IntHash was using typename IntTypes&lt;sizeof(T)&gt;::UnsignedType.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>245287</attachid>
            <date>2015-01-24 11:27:56 -0800</date>
            <delta_ts>2015-01-24 15:06:38 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-140858-20150124112757.patch</filename>
            <type>text/plain</type>
            <size>2156</size>
            <attacher name="Chris Dumez">cdumez</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTc5MDYxCmRpZmYgLS1naXQgYS9Tb3VyY2UvV1RGL0NoYW5n
ZUxvZyBiL1NvdXJjZS9XVEYvQ2hhbmdlTG9nCmluZGV4IGY4Yjk1O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LyBtYWtlIEludEhhc2gg
dGhlIGRlZmF1bHQgaGFzaCBmdW5jdGlvbiBmb3IgbWFueSBpbnRlZ2VyIHR5cGVzCiAKLSAgICB0
ZW1wbGF0ZTw+IHN0cnVjdCBEZWZhdWx0SGFzaDxib29sPiB7IHR5cGVkZWYgSW50SGFzaDx1aW50
OF90PiBIYXNoOyB9OworICAgIHRlbXBsYXRlPD4gc3RydWN0IERlZmF1bHRIYXNoPGJvb2w+IHsg
dHlwZWRlZiBJbnRIYXNoPGJvb2w+IEhhc2g7IH07CiAgICAgdGVtcGxhdGU8PiBzdHJ1Y3QgRGVm
YXVsdEhhc2g8c2hvcnQ+IHsgdHlwZWRlZiBJbnRIYXNoPHVuc2lnbmVkPiBIYXNoOyB9OwogICAg
IHRlbXBsYXRlPD4gc3RydWN0IERlZmF1bHRIYXNoPHVuc2lnbmVkIHNob3J0PiB7IHR5cGVkZWYg
SW50SGFzaDx1bnNpZ25lZD4gSGFzaDsgfTsKICAgICB0ZW1wbGF0ZTw+IHN0cnVjdCBEZWZhdWx0
SGFzaDxpbnQ+IHsgdHlwZWRlZiBJbnRIYXNoPHVuc2lnbmVkPiBIYXNoOyB9Owo=
</data>
<flag name="review"
          id="270232"
          type_id="1"
          status="-"
          setter="darin"
    />
    <flag name="commit-queue"
          id="270233"
          type_id="3"
          status="-"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>