Bug 647367 - Sequester jshash.{h,cpp} in js/jsd/ (attempt 2). r=luke.

--HG--
rename : js/src/jshash.cpp => js/jsd/jshash.cpp
rename : js/src/jshash.h => js/jsd/jshash.h
This commit is contained in:
Nicholas Nethercote 2012-07-18 17:38:10 -07:00
parent f3677daed7
commit f32ed5397d
15 changed files with 50 additions and 69 deletions

View File

@ -17,7 +17,9 @@ include $(DEPTH)/config/autoconf.mk
MODULE = jsdebug
LIBRARY_NAME = jsd
DIRS = idl
CPPSRCS = jsd_xpc.cpp
CPPSRCS = \
jsd_xpc.cpp \
jshash.cpp
IS_COMPONENT = 1
LIBXUL_LIBRARY = 1

View File

@ -61,7 +61,7 @@ static JSHashAllocOps defaultHashAllocOps = {
DefaultAllocEntry, DefaultFreeEntry
};
JS_PUBLIC_API(JSHashTable *)
JSHashTable *
JS_NewHashTable(uint32_t n, JSHashFunction keyHash,
JSHashComparator keyCompare, JSHashComparator valueCompare,
JSHashAllocOps *allocOps, void *allocPriv)
@ -101,7 +101,7 @@ JS_NewHashTable(uint32_t n, JSHashFunction keyHash,
return ht;
}
JS_PUBLIC_API(void)
void
JS_HashTableDestroy(JSHashTable *ht)
{
uint32_t i, n;
@ -133,7 +133,7 @@ JS_HashTableDestroy(JSHashTable *ht)
#define BUCKET_HEAD(ht, keyHash) \
(&(ht)->buckets[((keyHash) * JS_GOLDEN_RATIO) >> (ht)->shift])
JS_PUBLIC_API(JSHashEntry **)
JSHashEntry **
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key)
{
JSHashEntry *he, **hep, **hep0;
@ -212,7 +212,7 @@ Resize(JSHashTable *ht, uint32_t newshift)
return JS_TRUE;
}
JS_PUBLIC_API(JSHashEntry *)
JSHashEntry *
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep,
JSHashNumber keyHash, const void *key, void *value)
{
@ -243,7 +243,7 @@ JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep,
return he;
}
JS_PUBLIC_API(JSHashEntry *)
JSHashEntry *
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
{
JSHashNumber keyHash;
@ -265,7 +265,7 @@ JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
return JS_HashTableRawAdd(ht, hep, keyHash, key, value);
}
JS_PUBLIC_API(void)
void
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
{
uint32_t n;
@ -283,7 +283,7 @@ JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
}
}
JS_PUBLIC_API(JSBool)
JSBool
JS_HashTableRemove(JSHashTable *ht, const void *key)
{
JSHashNumber keyHash;
@ -299,7 +299,7 @@ JS_HashTableRemove(JSHashTable *ht, const void *key)
return JS_TRUE;
}
JS_PUBLIC_API(void *)
void *
JS_HashTableLookup(JSHashTable *ht, const void *key)
{
JSHashNumber keyHash;
@ -318,7 +318,7 @@ JS_HashTableLookup(JSHashTable *ht, const void *key)
** entry found. Stop if "f" says to (return value & JS_ENUMERATE_STOP).
** Return a count of the number of elements scanned.
*/
JS_PUBLIC_API(int)
int
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg)
{
JSHashEntry *he, **hep, **bucket;
@ -367,7 +367,7 @@ out:
#ifdef JS_HASHMETER
#include <stdio.h>
JS_PUBLIC_API(void)
void
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
{
double sqsum, mean, sigma;
@ -413,7 +413,7 @@ JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
}
#endif /* JS_HASHMETER */
JS_PUBLIC_API(int)
int
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
{
int count;
@ -425,7 +425,7 @@ JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
return count;
}
JS_PUBLIC_API(JSHashNumber)
JSHashNumber
JS_HashString(const void *key)
{
JSHashNumber h;
@ -437,7 +437,7 @@ JS_HashString(const void *key)
return h;
}
JS_PUBLIC_API(int)
int
JS_CompareValues(const void *v1, const void *v2)
{
return v1 == v2;

View File

@ -70,49 +70,49 @@ struct JSHashTable {
* Create a new hash table.
* If allocOps is null, use default allocator ops built on top of malloc().
*/
extern JS_PUBLIC_API(JSHashTable *)
extern JSHashTable *
JS_NewHashTable(uint32_t n, JSHashFunction keyHash,
JSHashComparator keyCompare, JSHashComparator valueCompare,
JSHashAllocOps *allocOps, void *allocPriv);
extern JS_PUBLIC_API(void)
extern void
JS_HashTableDestroy(JSHashTable *ht);
/* Low level access methods */
extern JS_PUBLIC_API(JSHashEntry **)
extern JSHashEntry **
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
#ifdef __cplusplus
extern JS_PUBLIC_API(JSHashEntry *)
extern JSHashEntry *
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep, JSHashNumber keyHash,
const void *key, void *value);
#endif
extern JS_PUBLIC_API(void)
extern void
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
/* Higher level access methods */
extern JS_PUBLIC_API(JSHashEntry *)
extern JSHashEntry *
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
extern JS_PUBLIC_API(JSBool)
extern JSBool
JS_HashTableRemove(JSHashTable *ht, const void *key);
extern JS_PUBLIC_API(int)
extern int
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
extern JS_PUBLIC_API(void *)
extern void *
JS_HashTableLookup(JSHashTable *ht, const void *key);
extern JS_PUBLIC_API(int)
extern int
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
/* General-purpose C string hash function. */
extern JS_PUBLIC_API(JSHashNumber)
extern JSHashNumber
JS_HashString(const void *key);
/* Stub function just returns v1 == v2 */
extern JS_PUBLIC_API(int)
extern int
JS_CompareValues(const void *v1, const void *v2);
JS_END_EXTERN_C

View File

@ -82,7 +82,6 @@ CPPSRCS = \
jsfun.cpp \
jsgc.cpp \
jscrashreport.cpp \
jshash.cpp \
jsinfer.cpp \
jsinterp.cpp \
jsiter.cpp \
@ -162,7 +161,6 @@ INSTALLED_HEADERS = \
jsdhash.h \
jsfriendapi.h \
jsgc.h \
jshash.h \
jslock.h \
json.h \
jsproxy.h \

View File

@ -15,7 +15,6 @@
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsatom.h"
@ -43,12 +42,6 @@ using namespace js::gc;
const size_t JSAtomState::commonAtomsOffset = offsetof(JSAtomState, emptyAtom);
/*
* ATOM_HASH assumes that JSHashNumber is 32-bit even on 64-bit systems.
*/
JS_STATIC_ASSERT(sizeof(JSHashNumber) == 4);
JS_STATIC_ASSERT(sizeof(JSAtom *) == JS_BYTES_PER_WORD);
const char *
js_AtomToPrintableString(JSContext *cx, JSAtom *atom, JSAutoByteString *bytes)
{

View File

@ -12,12 +12,12 @@
#include "jsalloc.h"
#include "jsapi.h"
#include "jsprvtd.h"
#include "jshash.h"
#include "jspubtd.h"
#include "jslock.h"
#include "gc/Barrier.h"
#include "js/HashTable.h"
#include "mozilla/HashFunctions.h"
struct JSIdArray {
int length;
@ -83,23 +83,15 @@ JSID_TO_ATOM(jsid id)
return (JSAtom *)JSID_TO_STRING(id);
}
JS_STATIC_ASSERT(sizeof(JSHashNumber) == 4);
JS_STATIC_ASSERT(sizeof(js::HashNumber) == 4);
JS_STATIC_ASSERT(sizeof(jsid) == JS_BYTES_PER_WORD);
namespace js {
static JS_ALWAYS_INLINE JSHashNumber
static JS_ALWAYS_INLINE js::HashNumber
HashId(jsid id)
{
JSHashNumber n =
#if JS_BYTES_PER_WORD == 4
JSHashNumber(JSID_BITS(id));
#elif JS_BYTES_PER_WORD == 8
JSHashNumber(JSID_BITS(id)) ^ JSHashNumber(JSID_BITS(id) >> 32);
#else
# error "Unsupported configuration"
#endif
return n * JS_GOLDEN_RATIO;
return HashGeneric(JSID_BITS(id));
}
static JS_ALWAYS_INLINE Value
@ -135,15 +127,6 @@ struct DefaultHasher<jsid>
}
#if JS_BYTES_PER_WORD == 4
# define ATOM_HASH(atom) ((JSHashNumber)(atom) >> 2)
#elif JS_BYTES_PER_WORD == 8
# define ATOM_HASH(atom) (((JSHashNumber)(uintptr_t)(atom) >> 3) ^ \
(JSHashNumber)((uintptr_t)(atom) >> 32))
#else
# error "Unsupported configuration"
#endif
/*
* Return a printable, lossless char[] representation of a string-type atom.
* The lifetime of the result matches the lifetime of bytes.

View File

@ -44,7 +44,6 @@
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsclist.h"
#include "jsprf.h"
#include "jsapi.h"

View File

@ -15,7 +15,6 @@
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsarray.h"

View File

@ -21,7 +21,6 @@
#include "jsclass.h"
#include "jsfriendapi.h"
#include "jsinfer.h"
#include "jshash.h"
#include "jspubtd.h"
#include "jsprvtd.h"
#include "jslock.h"

View File

@ -24,6 +24,7 @@
#include "jsscope.h"
#include "jsstr.h"
#include "js/HashTable.h"
#include "js/MemoryMetrics.h"
#include "jsatominlines.h"
@ -145,7 +146,7 @@ Shape::hashify(JSContext *cx)
Shape **
ShapeTable::search(jsid id, bool adding)
{
JSHashNumber hash0, hash1, hash2;
js::HashNumber hash0, hash1, hash2;
int sizeLog2;
Shape *stored, *shape, **spp, **firstRemoved;
uint32_t sizeMask;

View File

@ -1165,7 +1165,7 @@ struct ScriptFilenameEntry
struct ScriptFilenameHasher
{
typedef const char *Lookup;
static HashNumber hash(const char *l) { return JS_HashString(l); }
static HashNumber hash(const char *l) { return mozilla::HashString(l); }
static bool match(const ScriptFilenameEntry *e, const char *l) {
return strcmp(e->filename, l) == 0;
}

View File

@ -23,7 +23,6 @@
#include <string.h>
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsarray.h"
@ -42,6 +41,7 @@
#include "jsversion.h"
#include "builtin/RegExp.h"
#include "js/HashTable.h"
#include "vm/GlobalObject.h"
#include "vm/NumericConversions.h"
#include "vm/RegExpObject.h"

View File

@ -9,7 +9,6 @@
#include "mozilla/FloatingPoint.h"
#include "jstypes.h"
#include "jsutil.h"
#include "jshash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsarray.h"

View File

@ -8,7 +8,7 @@
#include "xpcprivate.h"
#include "jshash.h"
#include "js/HashTable.h"
/***************************************************************************/
// static shared...
@ -19,7 +19,7 @@
static JSDHashNumber
HashIIDPtrKey(JSDHashTable *table, const void *key)
{
return *((JSHashNumber*)key);
return *((js::HashNumber*)key);
}
static JSBool
@ -56,7 +56,7 @@ HashNativeKey(JSDHashTable *table, const void *key)
NS_ASSERTION(Addition, "bad key");
// This would be an XOR like below.
// But "0 ^ x == x". So it does not matter.
h = (JSHashNumber) NS_PTR_TO_INT32(Addition) >> 2;
h = (js::HashNumber) NS_PTR_TO_INT32(Addition) >> 2;
} else {
XPCNativeInterface** Current = Set->GetInterfaceArray();
PRUint16 count = Set->GetInterfaceCount();
@ -64,13 +64,13 @@ HashNativeKey(JSDHashTable *table, const void *key)
count++;
for (PRUint16 i = 0; i < count; i++) {
if (i == Position)
h ^= (JSHashNumber) NS_PTR_TO_INT32(Addition) >> 2;
h ^= (js::HashNumber) NS_PTR_TO_INT32(Addition) >> 2;
else
h ^= (JSHashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
}
} else {
for (PRUint16 i = 0; i < count; i++)
h ^= (JSHashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
}
}

View File

@ -179,6 +179,14 @@ AddToHash(uint32_t hash, A* a)
return detail::AddUintptrToHash<sizeof(uintptr_t)>(hash, uintptr_t(a));
}
template<>
MOZ_WARN_UNUSED_RESULT
inline uint32_t
AddToHash(uint32_t hash, uintptr_t a)
{
return detail::AddUintptrToHash<sizeof(uintptr_t)>(hash, a);
}
template<typename A, typename B>
MOZ_WARN_UNUSED_RESULT
uint32_t