NOTE: This patch has been committed.
Part 2 will follow in a moment.
src/ChangeLog addition:
2005-01-26 Ben Wing <ben(a)xemacs.org>
* emacs-marshals.c:
* emacs-marshals.c (initialize_marshaller_storage):
* hash.c:
* hash.c (string_equal):
* hash.c (make_hash_table):
* hash.h:
* ui-gtk.c (type_already_imported_p):
Clean up and generalize creation of string hash tables.
* ui-gtk.c (emacs_gtk_boxed_hash):
* elhash.h:
* gccache-gtk.c (gc_cache_hash):
* glyphs-gtk.c (gtk_image_instance_hash):
* lrecord.h (struct lrecord_implementation):
* marker.c (marker_hash):
* objects-gtk.c (gtk_color_instance_hash):
* objects-msw.c (mswindows_color_instance_hash):
* objects-tty.c (tty_color_instance_hash):
* objects-x.c (x_color_instance_hash):
* objects.c (color_instance_hash):
* objects.c (font_instance_hash):
* opaque.c (hash_opaque):
* opaque.c (hash_opaque_ptr):
* rangetab.c (range_table_entry_hash):
* rangetab.c (range_table_hash):
* specifier.c (specifier_hash):
* specifier.h (struct specifier_methods):
* xgccache.c (gc_cache_hash):
Use Hashcode rather than unsigned long.
symlink source patch:
Diff command: bash -ci "cvs-diff --show-c-function -no-changelog "
Files affected: src/xgccache.c src/specifier.h src/specifier.c src/rangetab.c src/opaque.c
src/objects.c src/objects-x.c src/objects-tty.c src/objects-msw.c src/objects-gtk.c
src/marker.c src/lrecord.h src/glyphs-gtk.c src/gccache-gtk.c src/elhash.h
src/emacs-marshals.c src/ui-gtk.c src/hash.h src/hash.c
Index: src/hash.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/hash.c,v
retrieving revision 1.12
diff -u -p -r1.12 hash.c
--- src/hash.c 2003/09/30 15:26:50 1.12
+++ src/hash.c 2005/01/26 10:16:08
@@ -1,6 +1,6 @@
/* Hash tables.
Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
- Copyright (C) 2003 Ben Wing.
+ Copyright (C) 2003, 2004 Ben Wing.
This file is part of XEmacs.
@@ -56,8 +56,19 @@ memory_hash (const void *xv, Bytecount s
return h;
}
-Hashcode
-string_hash (const char *xv)
+static int
+string_equal (const void *st1, const void *st2)
+{
+ if (!st1)
+ return st2 ? 0 : 1;
+ else if (!st2)
+ return 0;
+ else
+ return !strcmp ((const char *) st1, (const char *) st2);
+}
+
+static Hashcode
+string_hash (const void *xv)
{
Hashcode h = 0;
unsigned const char *x = (unsigned const char *) xv;
@@ -167,7 +178,7 @@ free_hash_table (struct hash_table *hash
xfree (hash_table, struct hash_table *);
}
-struct hash_table*
+struct hash_table *
make_hash_table (Elemcount size)
{
struct hash_table *hash_table = xnew_and_zero (struct hash_table);
@@ -175,6 +186,12 @@ make_hash_table (Elemcount size)
hash_table->harray = xnew_array (hentry, hash_table->size);
clrhash (hash_table);
return hash_table;
+}
+
+struct hash_table *
+make_string_hash_table (Elemcount size)
+{
+ return make_general_hash_table (size, string_hash, string_equal);
}
struct hash_table *
Index: src/hash.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/hash.h,v
retrieving revision 1.9
diff -u -p -r1.9 hash.h
--- src/hash.h 2003/02/13 09:57:07 1.9
+++ src/hash.h 2005/01/26 10:16:10
@@ -45,6 +45,8 @@ struct hash_table
automatically if the number of entries approaches the size */
struct hash_table *make_hash_table (Elemcount size);
+struct hash_table *make_string_hash_table (Elemcount size);
+
struct hash_table *make_general_hash_table (Elemcount size,
hash_table_hash_function
hash_function,
Index: src/ui-gtk.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/ui-gtk.c,v
retrieving revision 1.21
diff -u -p -r1.21 ui-gtk.c
--- src/ui-gtk.c 2005/01/24 23:34:13 1.21
+++ src/ui-gtk.c 2005/01/26 10:16:12
@@ -107,18 +107,6 @@ EXFUN (Fgtk_import_type, 1);
static struct hash_table *internal_type_hash;
static int
-type_hash_equal(const void *arg1, const void *arg2)
-{
- return ((GtkType) arg1 == (GtkType) arg2);
-}
-
-static unsigned long
-type_hash_hash(const void *arg)
-{
- return ((unsigned long) arg);
-}
-
-static int
type_already_imported_p (GtkType t)
{
void *retval = NULL;
@@ -148,7 +136,7 @@ type_already_imported_p (GtkType t)
if (!internal_type_hash)
{
- internal_type_hash = make_general_hash_table (163, type_hash_hash,
type_hash_equal);
+ internal_type_hash = make_hash_table (163);
return (0);
}
@@ -1128,11 +1116,11 @@ emacs_gtk_boxed_equality (Lisp_Object o1
(data1->object_type == data2->object_type));
}
-static unsigned long
+static Hashcode
emacs_gtk_boxed_hash (Lisp_Object obj, int UNUSED (depth))
{
emacs_gtk_boxed_data *data = XGTK_BOXED(obj);
- return (HASH2 ((unsigned long)data->object, data->object_type));
+ return (HASH2 ((Hashcode) data->object, data->object_type));
}
DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("GtkBoxed", emacs_gtk_boxed,
Index: src/emacs-marshals.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/emacs-marshals.c,v
retrieving revision 1.8
diff -u -p -r1.8 emacs-marshals.c
--- src/emacs-marshals.c 2004/05/02 04:06:58 1.8
+++ src/emacs-marshals.c 2005/01/26 10:16:14
@@ -1466,35 +1466,6 @@ emacs_gtk_marshal_STRING__NONE (ffi_actu
#include "hash.h"
-static int
-our_string_eq (const void *st1, const void *st2)
-{
- if (!st1)
- return st2 ? 0 : 1;
- else if (!st2)
- return 0;
- else
- return !strcmp ( (const char *) st1, (const char *) st2);
-}
-
-static unsigned long
-our_string_hash (const void *xv)
-{
- unsigned int h = 0;
- unsigned const char *x = (unsigned const char *) xv;
-
- if (!x) return 0;
-
- while (*x)
- {
- unsigned int g;
- h = (h << 4) + *x++;
- if ((g = h & 0xf0000000) != 0)
- h = (h ^ (g >> 24)) ^ g;
- }
-
- return h;
-}
static struct hash_table *marshaller_hashtable;
@@ -1502,7 +1473,7 @@ static void initialize_marshaller_storag
{
if (!marshaller_hashtable)
{
- marshaller_hashtable = make_general_hash_table (100, our_string_hash, our_string_eq);
+ marshaller_hashtable = make_string_hash_table (100);
puthash ("emacs_gtk_marshal_BOOL__OBJECT_INT", (void *)
emacs_gtk_marshal_BOOL__OBJECT_INT, marshaller_hashtable);
puthash ("emacs_gtk_marshal_BOOL__OBJECT_OBJECT_OBJECT", (void *)
emacs_gtk_marshal_BOOL__OBJECT_OBJECT_OBJECT, marshaller_hashtable);
puthash ("emacs_gtk_marshal_BOOL__OBJECT_OBJECT", (void *)
emacs_gtk_marshal_BOOL__OBJECT_OBJECT, marshaller_hashtable);
Index: src/elhash.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/elhash.h,v
retrieving revision 1.14
diff -u -p -r1.14 elhash.h
--- src/elhash.h 2004/12/06 03:52:04 1.14
+++ src/elhash.h 2005/01/26 10:16:15
@@ -62,7 +62,7 @@ EXFUN (Fremhash, 2);
EXFUN (Fclrhash, 1);
typedef int (*hash_table_test_function_t) (Lisp_Object obj1, Lisp_Object obj2);
-typedef unsigned long (*hash_table_hash_function_t) (Lisp_Object obj);
+typedef Hashcode (*hash_table_hash_function_t) (Lisp_Object obj);
typedef int (*maphash_function_t) (Lisp_Object key, Lisp_Object value,
void* extra_arg);
Index: src/gccache-gtk.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/gccache-gtk.c,v
retrieving revision 1.6
diff -u -p -r1.6 gccache-gtk.c
--- src/gccache-gtk.c 2005/01/24 23:33:57 1.6
+++ src/gccache-gtk.c 2005/01/26 10:16:17
@@ -91,12 +91,12 @@ struct gc_cache {
};
#ifdef GCCACHE_HASH
-static unsigned long
+static Hashcode
gc_cache_hash (const void *arg)
{
const struct gcv_and_mask *gcvm = (const struct gcv_and_mask *) arg;
unsigned long *longs = (unsigned long *) &gcvm->gcv;
- unsigned long hash = gcvm->mask;
+ Hashcode hash = gcvm->mask;
unsigned int i;
/* This could look at the mask and only use the used slots in the
hash code. That would win in that we wouldn't have to initialize
@@ -104,7 +104,7 @@ gc_cache_hash (const void *arg)
the hash function to be as fast as possible; some timings should
be done. */
for (i = 0; i < (sizeof (GdkGCValues) / sizeof (unsigned long)); i++)
- hash = (hash<<1) ^ *longs++;
+ hash = (hash << 1) ^ *longs++;
return hash;
}
Index: src/glyphs-gtk.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/glyphs-gtk.c,v
retrieving revision 1.29
diff -u -p -r1.29 glyphs-gtk.c
--- src/glyphs-gtk.c 2005/01/24 23:33:57 1.29
+++ src/glyphs-gtk.c 2005/01/26 10:16:19
@@ -482,7 +482,7 @@ gtk_image_instance_equal (struct Lisp_Im
return 1;
}
-static unsigned long
+static Hashcode
gtk_image_instance_hash (struct Lisp_Image_Instance *p, int UNUSED (depth))
{
switch (IMAGE_INSTANCE_TYPE (p))
Index: src/lrecord.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/lrecord.h,v
retrieving revision 1.34
diff -u -p -r1.34 lrecord.h
--- src/lrecord.h 2004/11/04 23:06:40 1.34
+++ src/lrecord.h 2005/01/26 10:16:22
@@ -276,7 +276,7 @@ struct lrecord_implementation
hash to the same value in order for hash tables to work properly.
This means that `hash' can be NULL only if the `equal' method is
also NULL. */
- unsigned long (*hash) (Lisp_Object, int);
+ Hashcode (*hash) (Lisp_Object, int);
/* Data layout description for your object. See long comment below. */
const struct memory_description *description;
Index: src/marker.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/marker.c,v
retrieving revision 1.14
diff -u -p -r1.14 marker.c
--- src/marker.c 2004/09/20 19:19:51 1.14
+++ src/marker.c 2005/01/26 10:16:23
@@ -88,10 +88,10 @@ marker_equal (Lisp_Object obj1, Lisp_Obj
!marker1->buffer));
}
-static unsigned long
+static Hashcode
marker_hash (Lisp_Object obj, int UNUSED (depth))
{
- unsigned long hash = (unsigned long) XMARKER (obj)->buffer;
+ Hashcode hash = (Hashcode) XMARKER (obj)->buffer;
if (hash)
hash = HASH2 (hash, XMARKER (obj)->membpos);
return hash;
Index: src/objects-gtk.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/objects-gtk.c,v
retrieving revision 1.14
diff -u -p -r1.14 objects-gtk.c
--- src/objects-gtk.c 2004/09/20 19:19:54 1.14
+++ src/objects-gtk.c 2005/01/26 10:16:25
@@ -178,7 +178,7 @@ gtk_color_instance_equal (struct Lisp_Co
COLOR_INSTANCE_GTK_COLOR (c2)));
}
-static unsigned long
+static Hashcode
gtk_color_instance_hash (struct Lisp_Color_Instance *c, int UNUSED (depth))
{
return (gdk_color_hash (COLOR_INSTANCE_GTK_COLOR (c), NULL));
Index: src/objects-msw.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/objects-msw.c,v
retrieving revision 1.45
diff -u -p -r1.45 objects-msw.c
--- src/objects-msw.c 2005/01/24 23:34:05 1.45
+++ src/objects-msw.c 2005/01/26 10:16:27
@@ -1390,7 +1390,7 @@ mswindows_color_instance_equal (Lisp_Col
COLOR_INSTANCE_MSWINDOWS_COLOR (c2));
}
-static unsigned long
+static Hashcode
mswindows_color_instance_hash (Lisp_Color_Instance *c, int UNUSED (depth))
{
return (unsigned long) COLOR_INSTANCE_MSWINDOWS_COLOR (c);
Index: src/objects-tty.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/objects-tty.c,v
retrieving revision 1.14
diff -u -p -r1.14 objects-tty.c
--- src/objects-tty.c 2004/11/04 23:06:45 1.14
+++ src/objects-tty.c 2005/01/26 10:16:29
@@ -213,7 +213,7 @@ tty_color_instance_equal (Lisp_Color_Ins
COLOR_INSTANCE_TTY_SYMBOL (c2)));
}
-static unsigned long
+static Hashcode
tty_color_instance_hash (Lisp_Color_Instance *c, int UNUSED (depth))
{
return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
Index: src/objects-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/objects-x.c,v
retrieving revision 1.26
diff -u -p -r1.26 objects-x.c
--- src/objects-x.c 2004/11/04 23:06:45 1.26
+++ src/objects-x.c 2005/01/26 10:16:31
@@ -326,7 +326,7 @@ x_color_instance_equal (Lisp_Color_Insta
(color1.blue == color2.blue));
}
-static unsigned long
+static Hashcode
x_color_instance_hash (Lisp_Color_Instance *c, int UNUSED (depth))
{
XColor color = COLOR_INSTANCE_X_COLOR (c);
Index: src/objects.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/objects.c,v
retrieving revision 1.24
diff -u -p -r1.24 objects.c
--- src/objects.c 2005/01/24 23:34:05 1.24
+++ src/objects.c 2005/01/26 10:16:33
@@ -133,13 +133,13 @@ color_instance_equal (Lisp_Object obj1,
DEVMETH (XDEVICE (c1->device), color_instance_equal, (c1, c2, depth)));
}
-static unsigned long
+static Hashcode
color_instance_hash (Lisp_Object obj, int depth)
{
Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
struct device *d = DEVICEP (c->device) ? XDEVICE (c->device) : 0;
- return HASH2 ((unsigned long) d,
+ return HASH2 ((Hashcode) d,
!d ? LISP_HASH (obj)
: DEVMETH_OR_GIVEN (d, color_instance_hash, (c, depth),
LISP_HASH (obj)));
@@ -334,7 +334,7 @@ font_instance_equal (Lisp_Object obj1, L
depth + 1);
}
-static unsigned long
+static Hashcode
font_instance_hash (Lisp_Object obj, int depth)
{
return internal_hash (font_instance_truename_internal
Index: src/opaque.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/opaque.c,v
retrieving revision 1.18
diff -u -p -r1.18 opaque.c
--- src/opaque.c 2004/09/20 19:19:55 1.18
+++ src/opaque.c 2005/01/26 10:16:34
@@ -100,11 +100,11 @@ equal_opaque (Lisp_Object obj1, Lisp_Obj
/* This will not work correctly for opaques with subobjects! */
-static unsigned long
+static Hashcode
hash_opaque (Lisp_Object obj, int UNUSED (depth))
{
if (XOPAQUE_SIZE (obj) == sizeof (unsigned long))
- return *((unsigned long *) XOPAQUE_DATA (obj));
+ return *((Hashcode *) XOPAQUE_DATA (obj));
else
return memory_hash (XOPAQUE_DATA (obj), XOPAQUE_SIZE (obj));
}
@@ -141,10 +141,10 @@ equal_opaque_ptr (Lisp_Object obj1, Lisp
return (XOPAQUE_PTR (obj1)->ptr == XOPAQUE_PTR (obj2)->ptr);
}
-static unsigned long
+static Hashcode
hash_opaque_ptr (Lisp_Object obj, int UNUSED (depth))
{
- return (unsigned long) XOPAQUE_PTR (obj)->ptr;
+ return (Hashcode) XOPAQUE_PTR (obj)->ptr;
}
static const struct memory_description opaque_ptr_description[] = {
Index: src/rangetab.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/rangetab.c,v
retrieving revision 1.20
diff -u -p -r1.20 rangetab.c
--- src/rangetab.c 2005/01/24 23:34:06 1.20
+++ src/rangetab.c 2005/01/26 10:16:36
@@ -159,19 +159,19 @@ range_table_equal (Lisp_Object obj1, Lis
return 1;
}
-static unsigned long
+static Hashcode
range_table_entry_hash (struct range_table_entry *rte, int depth)
{
return HASH3 (rte->first, rte->last, internal_hash (rte->val, depth + 1));
}
-static unsigned long
+static Hashcode
range_table_hash (Lisp_Object obj, int depth)
{
Lisp_Range_Table *rt = XRANGE_TABLE (obj);
int i;
int size = Dynarr_length (rt->entries);
- unsigned long hash = size;
+ Hashcode hash = size;
/* approach based on internal_array_hash(). */
if (size <= 5)
Index: src/specifier.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/specifier.c,v
retrieving revision 1.37
diff -u -p -r1.37 specifier.c
--- src/specifier.c 2005/01/24 23:34:10 1.37
+++ src/specifier.c 2005/01/26 10:16:38
@@ -337,7 +337,7 @@ specifier_equal (Lisp_Object obj1, Lisp_
return retval;
}
-static unsigned long
+static Hashcode
specifier_hash (Lisp_Object obj, int depth)
{
Lisp_Specifier *s = XSPECIFIER (obj);
@@ -347,7 +347,7 @@ specifier_hash (Lisp_Object obj, int dep
the most likely places where interesting stuff will be. */
return HASH5 ((HAS_SPECMETH_P (s, hash) ?
SPECMETH (s, hash, (obj, depth)) : 0),
- (unsigned long) s->methods,
+ (Hashcode) s->methods,
internal_hash (s->global_specs, depth + 1),
internal_hash (s->frame_specs, depth + 1),
internal_hash (s->buffer_specs, depth + 1));
Index: src/specifier.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/specifier.h,v
retrieving revision 1.15
diff -u -p -r1.15 specifier.h
--- src/specifier.h 2005/01/24 23:34:10 1.15
+++ src/specifier.h 2005/01/26 10:16:40
@@ -115,7 +115,7 @@ struct specifier_methods
If this function is not present, hashing behaves as if it
returned zero. */
- unsigned long (*hash_method) (Lisp_Object specifier, int depth);
+ Hashcode (*hash_method) (Lisp_Object specifier, int depth);
/* Validate method: Given an instantiator, verify that it's
valid for this specifier type. If not, signal an error.
Index: src/xgccache.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/xgccache.c,v
retrieving revision 1.9
diff -u -p -r1.9 xgccache.c
--- src/xgccache.c 2005/01/24 23:34:14 1.9
+++ src/xgccache.c 2005/01/26 10:16:42
@@ -92,12 +92,12 @@ struct gc_cache {
};
#ifdef GCCACHE_HASH
-static unsigned long
+static Hashcode
gc_cache_hash (const void *arg)
{
const struct gcv_and_mask *gcvm = (const struct gcv_and_mask *) arg;
unsigned long *longs = (unsigned long *) &gcvm->gcv;
- unsigned long hash = gcvm->mask;
+ Hashcode hash = gcvm->mask;
int i;
/* This could look at the mask and only use the used slots in the
hash code. That would win in that we wouldn't have to initialize
@@ -105,7 +105,7 @@ gc_cache_hash (const void *arg)
the hash function to be as fast as possible; some timings should
be done. */
for (i = 0; i < (int) (sizeof (XGCValues) / sizeof (unsigned long)); i++)
- hash = (hash<<1) ^ *longs++;
+ hash = (hash << 1) ^ *longs++;
return hash;
}