Changeset 9501 in webkit for trunk/JavaScriptCore/kjs/protected_values.cpp
- Timestamp:
- Jun 27, 2005, 5:02:08 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/protected_values.cpp
r8249 r9501 22 22 23 23 #include "protected_values.h" 24 25 #include "pointer_hash.h" 24 26 #include "simple_number.h" 27 #include <stdint.h> 25 28 26 29 namespace KJS { … … 184 187 } 185 188 186 // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's187 // 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.html233 // http://burtleburtle.net/bob/hash/doobs.html234 189 unsigned ProtectedValues::computeHash(ValueImp *pointer) 235 190 { 236 return hash<sizeof(ValueImp *)>(pointer);191 return pointerHash(pointer); 237 192 } 238 193
Note:
See TracChangeset
for help on using the changeset viewer.