diff options
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 33 |
1 files changed, 15 insertions, 18 deletions
| @@ -4053,6 +4053,19 @@ allocate_hash_table (void) | |||
| 4053 | - header_size - GCALIGNMENT) \ | 4053 | - header_size - GCALIGNMENT) \ |
| 4054 | / word_size))) | 4054 | / word_size))) |
| 4055 | 4055 | ||
| 4056 | static ptrdiff_t | ||
| 4057 | hash_index_size (struct Lisp_Hash_Table *h, ptrdiff_t size) | ||
| 4058 | { | ||
| 4059 | double threshold = h->rehash_threshold; | ||
| 4060 | double index_float = size / threshold; | ||
| 4061 | ptrdiff_t index_size = (index_float < INDEX_SIZE_BOUND + 1 | ||
| 4062 | ? next_almost_prime (index_float) | ||
| 4063 | : INDEX_SIZE_BOUND + 1); | ||
| 4064 | if (INDEX_SIZE_BOUND < index_size) | ||
| 4065 | error ("Hash table too large"); | ||
| 4066 | return index_size; | ||
| 4067 | } | ||
| 4068 | |||
| 4056 | /* Create and initialize a new hash table. | 4069 | /* Create and initialize a new hash table. |
| 4057 | 4070 | ||
| 4058 | TEST specifies the test the hash table will use to compare keys. | 4071 | TEST specifies the test the hash table will use to compare keys. |
| @@ -4086,9 +4099,7 @@ make_hash_table (struct hash_table_test test, EMACS_INT size, | |||
| 4086 | { | 4099 | { |
| 4087 | struct Lisp_Hash_Table *h; | 4100 | struct Lisp_Hash_Table *h; |
| 4088 | Lisp_Object table; | 4101 | Lisp_Object table; |
| 4089 | EMACS_INT index_size; | ||
| 4090 | ptrdiff_t i; | 4102 | ptrdiff_t i; |
| 4091 | double index_float; | ||
| 4092 | 4103 | ||
| 4093 | /* Preconditions. */ | 4104 | /* Preconditions. */ |
| 4094 | eassert (SYMBOLP (test.name)); | 4105 | eassert (SYMBOLP (test.name)); |
| @@ -4099,14 +4110,6 @@ make_hash_table (struct hash_table_test test, EMACS_INT size, | |||
| 4099 | if (size == 0) | 4110 | if (size == 0) |
| 4100 | size = 1; | 4111 | size = 1; |
| 4101 | 4112 | ||
| 4102 | double threshold = rehash_threshold; | ||
| 4103 | index_float = size / threshold; | ||
| 4104 | index_size = (index_float < INDEX_SIZE_BOUND + 1 | ||
| 4105 | ? next_almost_prime (index_float) | ||
| 4106 | : INDEX_SIZE_BOUND + 1); | ||
| 4107 | if (INDEX_SIZE_BOUND < max (index_size, 2 * size)) | ||
| 4108 | error ("Hash table too large"); | ||
| 4109 | |||
| 4110 | /* Allocate a table and initialize it. */ | 4113 | /* Allocate a table and initialize it. */ |
| 4111 | h = allocate_hash_table (); | 4114 | h = allocate_hash_table (); |
| 4112 | 4115 | ||
| @@ -4119,7 +4122,7 @@ make_hash_table (struct hash_table_test test, EMACS_INT size, | |||
| 4119 | h->key_and_value = make_nil_vector (2 * size); | 4122 | h->key_and_value = make_nil_vector (2 * size); |
| 4120 | h->hash = make_nil_vector (size); | 4123 | h->hash = make_nil_vector (size); |
| 4121 | h->next = make_vector (size, make_fixnum (-1)); | 4124 | h->next = make_vector (size, make_fixnum (-1)); |
| 4122 | h->index = make_vector (index_size, make_fixnum (-1)); | 4125 | h->index = make_vector (hash_index_size (h, size), make_fixnum (-1)); |
| 4123 | h->next_weak = NULL; | 4126 | h->next_weak = NULL; |
| 4124 | h->purecopy = purecopy; | 4127 | h->purecopy = purecopy; |
| 4125 | h->mutable = true; | 4128 | h->mutable = true; |
| @@ -4195,13 +4198,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 4195 | for (ptrdiff_t i = old_size; i < next_size - 1; i++) | 4198 | for (ptrdiff_t i = old_size; i < next_size - 1; i++) |
| 4196 | gc_aset (next, i, make_fixnum (i + 1)); | 4199 | gc_aset (next, i, make_fixnum (i + 1)); |
| 4197 | gc_aset (next, next_size - 1, make_fixnum (-1)); | 4200 | gc_aset (next, next_size - 1, make_fixnum (-1)); |
| 4198 | double threshold = h->rehash_threshold; | 4201 | ptrdiff_t index_size = hash_index_size (h, next_size); |
| 4199 | double index_float = next_size / threshold; | ||
| 4200 | EMACS_INT index_size = (index_float < INDEX_SIZE_BOUND + 1 | ||
| 4201 | ? next_almost_prime (index_float) | ||
| 4202 | : INDEX_SIZE_BOUND + 1); | ||
| 4203 | if (INDEX_SIZE_BOUND < index_size) | ||
| 4204 | error ("Hash table too large to resize"); | ||
| 4205 | Lisp_Object key_and_value | 4202 | Lisp_Object key_and_value |
| 4206 | = larger_vector (h->key_and_value, 2 * (next_size - old_size), | 4203 | = larger_vector (h->key_and_value, 2 * (next_size - old_size), |
| 4207 | 2 * next_size); | 4204 | 2 * next_size); |