diff options
| author | Paul Eggert | 2012-11-08 13:43:34 -0800 |
|---|---|---|
| committer | Paul Eggert | 2012-11-08 13:43:34 -0800 |
| commit | 04a2d0d38a2835db6c2e5a74cd7701555a7eb826 (patch) | |
| tree | ab23bf51e55b69c0173647e33b0769d83a306cf8 /src | |
| parent | de5ef41a76f05eb072ef06b053e543ce67fa3241 (diff) | |
| download | emacs-04a2d0d38a2835db6c2e5a74cd7701555a7eb826.tar.gz emacs-04a2d0d38a2835db6c2e5a74cd7701555a7eb826.zip | |
Use same hash function for hashfn_profiler as for hash_string etc.
* fns.c (SXHASH_COMBINE): Remove. All uses replaced by sxhash_combine.
* lisp.h (sxhash_combine): New inline function, with the contents
of the old SXHASH_COMBINE.
* profiler.c (hashfn_profiler): Use it, instead of having a
special hash function containing a comparison that always yields 1.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/fns.c | 19 | ||||
| -rw-r--r-- | src/lisp.h | 11 | ||||
| -rw-r--r-- | src/profiler.c | 2 |
4 files changed, 26 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 45e97ddd93c..c759b026dba 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-11-08 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Use same hash function for hashfn_profiler as for hash_string etc. | ||
| 4 | * fns.c (SXHASH_COMBINE): Remove. All uses replaced by sxhash_combine. | ||
| 5 | * lisp.h (sxhash_combine): New inline function, with the contents | ||
| 6 | of the old SXHASH_COMBINE. | ||
| 7 | * profiler.c (hashfn_profiler): Use it, instead of having a | ||
| 8 | special hash function containing a comparison that always yields 1. | ||
| 9 | |||
| 1 | 2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca> | 10 | 2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 11 | ||
| 3 | * xfaces.c (Qultra_light, Qreverse_oblique, Qreverse_italic) | 12 | * xfaces.c (Qultra_light, Qreverse_oblique, Qreverse_italic) |
| @@ -4036,13 +4036,6 @@ sweep_weak_hash_tables (void) | |||
| 4036 | 4036 | ||
| 4037 | #define SXHASH_MAX_LEN 7 | 4037 | #define SXHASH_MAX_LEN 7 |
| 4038 | 4038 | ||
| 4039 | /* Combine two integers X and Y for hashing. The result might not fit | ||
| 4040 | into a Lisp integer. */ | ||
| 4041 | |||
| 4042 | #define SXHASH_COMBINE(X, Y) \ | ||
| 4043 | ((((EMACS_UINT) (X) << 4) + ((EMACS_UINT) (X) >> (BITS_PER_EMACS_INT - 4))) \ | ||
| 4044 | + (EMACS_UINT) (Y)) | ||
| 4045 | |||
| 4046 | /* Hash X, returning a value that fits into a Lisp integer. */ | 4039 | /* Hash X, returning a value that fits into a Lisp integer. */ |
| 4047 | #define SXHASH_REDUCE(X) \ | 4040 | #define SXHASH_REDUCE(X) \ |
| 4048 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) | 4041 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) |
| @@ -4061,7 +4054,7 @@ hash_string (char const *ptr, ptrdiff_t len) | |||
| 4061 | while (p != end) | 4054 | while (p != end) |
| 4062 | { | 4055 | { |
| 4063 | c = *p++; | 4056 | c = *p++; |
| 4064 | hash = SXHASH_COMBINE (hash, c); | 4057 | hash = sxhash_combine (hash, c); |
| 4065 | } | 4058 | } |
| 4066 | 4059 | ||
| 4067 | return hash; | 4060 | return hash; |
| @@ -4095,7 +4088,7 @@ sxhash_float (double val) | |||
| 4095 | u.val = val; | 4088 | u.val = val; |
| 4096 | memset (&u.val + 1, 0, sizeof u - sizeof u.val); | 4089 | memset (&u.val + 1, 0, sizeof u - sizeof u.val); |
| 4097 | for (i = 0; i < WORDS_PER_DOUBLE; i++) | 4090 | for (i = 0; i < WORDS_PER_DOUBLE; i++) |
| 4098 | hash = SXHASH_COMBINE (hash, u.word[i]); | 4091 | hash = sxhash_combine (hash, u.word[i]); |
| 4099 | return SXHASH_REDUCE (hash); | 4092 | return SXHASH_REDUCE (hash); |
| 4100 | } | 4093 | } |
| 4101 | 4094 | ||
| @@ -4114,13 +4107,13 @@ sxhash_list (Lisp_Object list, int depth) | |||
| 4114 | list = XCDR (list), ++i) | 4107 | list = XCDR (list), ++i) |
| 4115 | { | 4108 | { |
| 4116 | EMACS_UINT hash2 = sxhash (XCAR (list), depth + 1); | 4109 | EMACS_UINT hash2 = sxhash (XCAR (list), depth + 1); |
| 4117 | hash = SXHASH_COMBINE (hash, hash2); | 4110 | hash = sxhash_combine (hash, hash2); |
| 4118 | } | 4111 | } |
| 4119 | 4112 | ||
| 4120 | if (!NILP (list)) | 4113 | if (!NILP (list)) |
| 4121 | { | 4114 | { |
| 4122 | EMACS_UINT hash2 = sxhash (list, depth + 1); | 4115 | EMACS_UINT hash2 = sxhash (list, depth + 1); |
| 4123 | hash = SXHASH_COMBINE (hash, hash2); | 4116 | hash = sxhash_combine (hash, hash2); |
| 4124 | } | 4117 | } |
| 4125 | 4118 | ||
| 4126 | return SXHASH_REDUCE (hash); | 4119 | return SXHASH_REDUCE (hash); |
| @@ -4140,7 +4133,7 @@ sxhash_vector (Lisp_Object vec, int depth) | |||
| 4140 | for (i = 0; i < n; ++i) | 4133 | for (i = 0; i < n; ++i) |
| 4141 | { | 4134 | { |
| 4142 | EMACS_UINT hash2 = sxhash (AREF (vec, i), depth + 1); | 4135 | EMACS_UINT hash2 = sxhash (AREF (vec, i), depth + 1); |
| 4143 | hash = SXHASH_COMBINE (hash, hash2); | 4136 | hash = sxhash_combine (hash, hash2); |
| 4144 | } | 4137 | } |
| 4145 | 4138 | ||
| 4146 | return SXHASH_REDUCE (hash); | 4139 | return SXHASH_REDUCE (hash); |
| @@ -4156,7 +4149,7 @@ sxhash_bool_vector (Lisp_Object vec) | |||
| 4156 | 4149 | ||
| 4157 | n = min (SXHASH_MAX_LEN, XBOOL_VECTOR (vec)->header.size); | 4150 | n = min (SXHASH_MAX_LEN, XBOOL_VECTOR (vec)->header.size); |
| 4158 | for (i = 0; i < n; ++i) | 4151 | for (i = 0; i < n; ++i) |
| 4159 | hash = SXHASH_COMBINE (hash, XBOOL_VECTOR (vec)->data[i]); | 4152 | hash = sxhash_combine (hash, XBOOL_VECTOR (vec)->data[i]); |
| 4160 | 4153 | ||
| 4161 | return SXHASH_REDUCE (hash); | 4154 | return SXHASH_REDUCE (hash); |
| 4162 | } | 4155 | } |
diff --git a/src/lisp.h b/src/lisp.h index cac7d4b7012..ce805e96c96 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -438,7 +438,7 @@ enum More_Lisp_Bits | |||
| 438 | /* To calculate the memory footprint of the pseudovector, it's useful | 438 | /* To calculate the memory footprint of the pseudovector, it's useful |
| 439 | to store the size of non-Lisp area in word_size units here. */ | 439 | to store the size of non-Lisp area in word_size units here. */ |
| 440 | PSEUDOVECTOR_REST_BITS = 12, | 440 | PSEUDOVECTOR_REST_BITS = 12, |
| 441 | PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1) | 441 | PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1) |
| 442 | << PSEUDOVECTOR_SIZE_BITS), | 442 | << PSEUDOVECTOR_SIZE_BITS), |
| 443 | 443 | ||
| 444 | /* Used to extract pseudovector subtype information. */ | 444 | /* Used to extract pseudovector subtype information. */ |
| @@ -1284,6 +1284,15 @@ static double const DEFAULT_REHASH_THRESHOLD = 0.8; | |||
| 1284 | 1284 | ||
| 1285 | static double const DEFAULT_REHASH_SIZE = 1.5; | 1285 | static double const DEFAULT_REHASH_SIZE = 1.5; |
| 1286 | 1286 | ||
| 1287 | /* Combine two integers X and Y for hashing. The result might not fit | ||
| 1288 | into a Lisp integer. */ | ||
| 1289 | |||
| 1290 | LISP_INLINE EMACS_UINT | ||
| 1291 | sxhash_combine (EMACS_UINT x, EMACS_UINT y) | ||
| 1292 | { | ||
| 1293 | return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y; | ||
| 1294 | } | ||
| 1295 | |||
| 1287 | /* These structures are used for various misc types. */ | 1296 | /* These structures are used for various misc types. */ |
| 1288 | 1297 | ||
| 1289 | struct Lisp_Misc_Any /* Supertype of all Misc types. */ | 1298 | struct Lisp_Misc_Any /* Supertype of all Misc types. */ |
diff --git a/src/profiler.c b/src/profiler.c index 6f112440902..365d834b9e1 100644 --- a/src/profiler.c +++ b/src/profiler.c | |||
| @@ -558,7 +558,7 @@ hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt) | |||
| 558 | = (COMPILEDP (f) ? XUINT (AREF (f, COMPILED_BYTECODE)) | 558 | = (COMPILEDP (f) ? XUINT (AREF (f, COMPILED_BYTECODE)) |
| 559 | : (CONSP (f) && CONSP (XCDR (f)) && EQ (Qclosure, XCAR (f))) | 559 | : (CONSP (f) && CONSP (XCDR (f)) && EQ (Qclosure, XCAR (f))) |
| 560 | ? XUINT (XCDR (XCDR (f))) : XUINT (f)); | 560 | ? XUINT (XCDR (XCDR (f))) : XUINT (f)); |
| 561 | hash = hash1 + (hash << 1) + (hash == (EMACS_INT) hash); | 561 | hash = sxhash_combine (hash, hash1); |
| 562 | } | 562 | } |
| 563 | return (hash & INTMASK); | 563 | return (hash & INTMASK); |
| 564 | } | 564 | } |