Mercurial > hg > xemacs-beta
changeset 2515:de9952d2ed18
[xemacs-hg @ 2005-01-26 10:22:19 by ben]
Hash table cleanups, part 1 of 2
emacs-marshals.c, hash.c, hash.h, ui-gtk.c: Clean up and generalize creation of string hash tables.
ui-gtk.c, elhash.h, gccache-gtk.c, glyphs-gtk.c, lrecord.h, marker.c, objects-gtk.c, objects-msw.c, objects-tty.c, objects-x.c, objects.c, opaque.c, rangetab.c, specifier.c, specifier.h, xgccache.c: Use Hashcode rather than unsigned long.
author | ben |
---|---|
date | Wed, 26 Jan 2005 10:22:29 +0000 |
parents | b49d38bc659d |
children | b87570db038f |
files | src/ChangeLog src/elhash.h src/emacs-marshals.c src/gccache-gtk.c src/glyphs-gtk.c src/hash.c src/hash.h src/lrecord.h src/marker.c src/objects-gtk.c src/objects-msw.c src/objects-tty.c src/objects-x.c src/objects.c src/opaque.c src/rangetab.c src/specifier.c src/specifier.h src/ui-gtk.c src/xgccache.c |
diffstat | 20 files changed, 87 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Wed Jan 26 10:09:20 2005 +0000 +++ b/src/ChangeLog Wed Jan 26 10:22:29 2005 +0000 @@ -1,3 +1,35 @@ +2005-01-26 Ben Wing <ben@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. + 2005-01-26 Ben Wing <ben@xemacs.org> * profile.c: @@ -11,18 +43,6 @@ * emacs.c: Update history section. - * 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. - - * profile.c: - * profile.c (vars_of_profile): - * profile.h: 2004-11-13 Ben Wing <ben@xemacs.org>
--- a/src/elhash.h Wed Jan 26 10:09:20 2005 +0000 +++ b/src/elhash.h Wed Jan 26 10:22:29 2005 +0000 @@ -62,7 +62,7 @@ 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);
--- a/src/emacs-marshals.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/emacs-marshals.c Wed Jan 26 10:22:29 2005 +0000 @@ -1466,35 +1466,6 @@ #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 @@ { 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);
--- a/src/gccache-gtk.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/gccache-gtk.c Wed Jan 26 10:22:29 2005 +0000 @@ -91,12 +91,12 @@ }; #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 @@ 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; }
--- a/src/glyphs-gtk.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/glyphs-gtk.c Wed Jan 26 10:22:29 2005 +0000 @@ -482,7 +482,7 @@ return 1; } -static unsigned long +static Hashcode gtk_image_instance_hash (struct Lisp_Image_Instance *p, int UNUSED (depth)) { switch (IMAGE_INSTANCE_TYPE (p))
--- a/src/hash.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/hash.c Wed Jan 26 10:22:29 2005 +0000 @@ -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 @@ 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 @@ 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); @@ -178,6 +189,12 @@ } struct hash_table * +make_string_hash_table (Elemcount size) +{ + return make_general_hash_table (size, string_hash, string_equal); +} + +struct hash_table * make_general_hash_table (Elemcount size, hash_table_hash_function hash_function, hash_table_test_function test_function)
--- a/src/hash.h Wed Jan 26 10:09:20 2005 +0000 +++ b/src/hash.h Wed Jan 26 10:22:29 2005 +0000 @@ -45,6 +45,8 @@ 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,
--- a/src/lrecord.h Wed Jan 26 10:09:20 2005 +0000 +++ b/src/lrecord.h Wed Jan 26 10:22:29 2005 +0000 @@ -276,7 +276,7 @@ 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;
--- a/src/marker.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/marker.c Wed Jan 26 10:22:29 2005 +0000 @@ -88,10 +88,10 @@ !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;
--- a/src/objects-gtk.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/objects-gtk.c Wed Jan 26 10:22:29 2005 +0000 @@ -178,7 +178,7 @@ 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));
--- a/src/objects-msw.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/objects-msw.c Wed Jan 26 10:22:29 2005 +0000 @@ -1390,7 +1390,7 @@ 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);
--- a/src/objects-tty.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/objects-tty.c Wed Jan 26 10:22:29 2005 +0000 @@ -213,7 +213,7 @@ 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));
--- a/src/objects-x.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/objects-x.c Wed Jan 26 10:22:29 2005 +0000 @@ -326,7 +326,7 @@ (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);
--- a/src/objects.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/objects.c Wed Jan 26 10:22:29 2005 +0000 @@ -133,13 +133,13 @@ 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 @@ depth + 1); } -static unsigned long +static Hashcode font_instance_hash (Lisp_Object obj, int depth) { return internal_hash (font_instance_truename_internal
--- a/src/opaque.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/opaque.c Wed Jan 26 10:22:29 2005 +0000 @@ -100,11 +100,11 @@ /* 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 @@ 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[] = {
--- a/src/rangetab.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/rangetab.c Wed Jan 26 10:22:29 2005 +0000 @@ -159,19 +159,19 @@ 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)
--- a/src/specifier.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/specifier.c Wed Jan 26 10:22:29 2005 +0000 @@ -337,7 +337,7 @@ return retval; } -static unsigned long +static Hashcode specifier_hash (Lisp_Object obj, int depth) { Lisp_Specifier *s = XSPECIFIER (obj); @@ -347,7 +347,7 @@ 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));
--- a/src/specifier.h Wed Jan 26 10:09:20 2005 +0000 +++ b/src/specifier.h Wed Jan 26 10:22:29 2005 +0000 @@ -115,7 +115,7 @@ 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.
--- a/src/ui-gtk.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/ui-gtk.c Wed Jan 26 10:22:29 2005 +0000 @@ -107,18 +107,6 @@ 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 @@ 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 @@ (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,
--- a/src/xgccache.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/xgccache.c Wed Jan 26 10:22:29 2005 +0000 @@ -92,12 +92,12 @@ }; #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 @@ 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; }