Ignore:
Timestamp:
Jun 27, 2005, 5:02:08 PM (20 years ago)
Author:
mjs
Message:

Reviewed by Darin.

  • replace hash functions with better ones
  • JavaScriptCore.pbproj/project.pbxproj: Add new file to build.
  • kjs/interpreter_map.cpp: (KJS::InterpreterMap::computeHash): Use shared pointer hash.
  • kjs/pointer_hash.h: Added. (KJS::pointerHash): Pointer hash based on 32-bit mix and 64-bit mix hashes.
  • kjs/protected_values.cpp: (KJS::ProtectedValues::computeHash): Use shared pointer hash.
  • kjs/ustring.cpp: (KJS::UString::Rep::computeHash): Use SuperFastHash algorithm.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/protected_values.cpp

    r8249 r9501  
    2222
    2323#include "protected_values.h"
     24
     25#include "pointer_hash.h"
    2426#include "simple_number.h"
     27#include <stdint.h>
    2528
    2629namespace KJS {
     
    184187}
    185188
    186 // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
    187 // or anything like that.
    188 const unsigned PHI = 0x9e3779b9U;
    189 
    190 template <int size> static unsigned hash(ValueImp *pointer);
    191 
    192 template <> static inline unsigned hash<4>(ValueImp *pointer)
    193 {
    194   int a = (int)PHI;
    195   int b = (int)pointer;
    196   int c = 0;
    197 
    198   a -= b; a -= c; a ^= (c>>13);
    199   b -= c; b -= a; b ^= (a<<8);
    200   c -= a; c -= b; c ^= (b>>13);
    201   a -= b; a -= c; a ^= (c>>12);
    202   b -= c; b -= a; b ^= (a<<16);
    203   c -= a; c -= b; c ^= (b>>5);
    204   a -= b; a -= c; a ^= (c>>3);
    205   b -= c; b -= a; b ^= (a<<10);
    206   c -= a; c -= b; c ^= (b>>15);
    207  
    208   return (unsigned)c;
    209 }
    210 
    211 template <> static inline unsigned hash<8>(ValueImp *pointer)
    212 {
    213   int a = (int)PHI;
    214   int b = (int)(long)pointer;
    215   int c = (int)(((long)pointer >> 16) >> 16);
    216 
    217   a -= b; a -= c; a ^= (c>>13);
    218   b -= c; b -= a; b ^= (a<<8);
    219   c -= a; c -= b; c ^= (b>>13);
    220   a -= b; a -= c; a ^= (c>>12);
    221   b -= c; b -= a; b ^= (a<<16);
    222   c -= a; c -= b; c ^= (b>>5);
    223   a -= b; a -= c; a ^= (c>>3);
    224   b -= c; b -= a; b ^= (a<<10);
    225   c -= a; c -= b; c ^= (b>>15);
    226  
    227   return (unsigned)c;
    228 }
    229 
    230 
    231 // This hash algorithm comes from:
    232 // http://burtleburtle.net/bob/hash/hashfaq.html
    233 // http://burtleburtle.net/bob/hash/doobs.html
    234189unsigned ProtectedValues::computeHash(ValueImp *pointer)
    235190{
    236   return hash<sizeof(ValueImp *)>(pointer);
     191  return pointerHash(pointer);
    237192}
    238193
Note: See TracChangeset for help on using the changeset viewer.