diff options
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 52 |
1 files changed, 18 insertions, 34 deletions
| @@ -4280,13 +4280,13 @@ static void | |||
| 4280 | set_hash_next_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, ptrdiff_t val) | 4280 | set_hash_next_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, ptrdiff_t val) |
| 4281 | { | 4281 | { |
| 4282 | eassert (idx >= 0 && idx < h->table_size); | 4282 | eassert (idx >= 0 && idx < h->table_size); |
| 4283 | h->next[idx] = val; | 4283 | h->hash_next[idx].next = val; |
| 4284 | } | 4284 | } |
| 4285 | static void | 4285 | static void |
| 4286 | set_hash_hash_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, hash_hash_t val) | 4286 | set_hash_hash_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, hash_hash_t val) |
| 4287 | { | 4287 | { |
| 4288 | eassert (idx >= 0 && idx < h->table_size); | 4288 | eassert (idx >= 0 && idx < h->table_size); |
| 4289 | h->hash[idx] = val; | 4289 | h->hash_next[idx].hash = val; |
| 4290 | } | 4290 | } |
| 4291 | static void | 4291 | static void |
| 4292 | set_hash_index_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, ptrdiff_t val) | 4292 | set_hash_index_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, ptrdiff_t val) |
| @@ -4383,7 +4383,7 @@ static ptrdiff_t | |||
| 4383 | HASH_NEXT (struct Lisp_Hash_Table *h, ptrdiff_t idx) | 4383 | HASH_NEXT (struct Lisp_Hash_Table *h, ptrdiff_t idx) |
| 4384 | { | 4384 | { |
| 4385 | eassert (idx >= 0 && idx < h->table_size); | 4385 | eassert (idx >= 0 && idx < h->table_size); |
| 4386 | return h->next[idx]; | 4386 | return h->hash_next[idx].next; |
| 4387 | } | 4387 | } |
| 4388 | 4388 | ||
| 4389 | /* Return the index of the element in hash table H that is the start | 4389 | /* Return the index of the element in hash table H that is the start |
| @@ -4571,8 +4571,7 @@ make_hash_table (const struct hash_table_test *test, EMACS_INT size, | |||
| 4571 | if (size == 0) | 4571 | if (size == 0) |
| 4572 | { | 4572 | { |
| 4573 | h->key_and_value = NULL; | 4573 | h->key_and_value = NULL; |
| 4574 | h->hash = NULL; | 4574 | h->hash_next = NULL; |
| 4575 | h->next = NULL; | ||
| 4576 | eassert (index_size == 1); | 4575 | eassert (index_size == 1); |
| 4577 | h->index = (hash_idx_t *)empty_hash_index_vector; | 4576 | h->index = (hash_idx_t *)empty_hash_index_vector; |
| 4578 | h->next_free = -1; | 4577 | h->next_free = -1; |
| @@ -4584,12 +4583,10 @@ make_hash_table (const struct hash_table_test *test, EMACS_INT size, | |||
| 4584 | for (ptrdiff_t i = 0; i < 2 * size; i++) | 4583 | for (ptrdiff_t i = 0; i < 2 * size; i++) |
| 4585 | h->key_and_value[i] = HASH_UNUSED_ENTRY_KEY; | 4584 | h->key_and_value[i] = HASH_UNUSED_ENTRY_KEY; |
| 4586 | 4585 | ||
| 4587 | h->hash = hash_table_alloc_bytes (size * sizeof *h->hash); | 4586 | h->hash_next = hash_table_alloc_bytes (size * sizeof *h->hash_next); |
| 4588 | |||
| 4589 | h->next = hash_table_alloc_bytes (size * sizeof *h->next); | ||
| 4590 | for (ptrdiff_t i = 0; i < size - 1; i++) | 4587 | for (ptrdiff_t i = 0; i < size - 1; i++) |
| 4591 | h->next[i] = i + 1; | 4588 | h->hash_next[i].next = i + 1; |
| 4592 | h->next[size - 1] = -1; | 4589 | h->hash_next[size - 1].next = -1; |
| 4593 | 4590 | ||
| 4594 | h->index = hash_table_alloc_bytes (index_size * sizeof *h->index); | 4591 | h->index = hash_table_alloc_bytes (index_size * sizeof *h->index); |
| 4595 | for (ptrdiff_t i = 0; i < index_size; i++) | 4592 | for (ptrdiff_t i = 0; i < index_size; i++) |
| @@ -4630,13 +4627,9 @@ copy_hash_table (struct Lisp_Hash_Table *h1) | |||
| 4630 | h2->key_and_value = hash_table_alloc_bytes (kv_bytes); | 4627 | h2->key_and_value = hash_table_alloc_bytes (kv_bytes); |
| 4631 | memcpy (h2->key_and_value, h1->key_and_value, kv_bytes); | 4628 | memcpy (h2->key_and_value, h1->key_and_value, kv_bytes); |
| 4632 | 4629 | ||
| 4633 | ptrdiff_t hash_bytes = h1->table_size * sizeof *h1->hash; | 4630 | ptrdiff_t hn_bytes = h1->table_size * sizeof *h1->hash_next; |
| 4634 | h2->hash = hash_table_alloc_bytes (hash_bytes); | 4631 | h2->hash_next = hash_table_alloc_bytes (hn_bytes); |
| 4635 | memcpy (h2->hash, h1->hash, hash_bytes); | 4632 | memcpy (h2->hash_next, h1->hash_next, hn_bytes); |
| 4636 | |||
| 4637 | ptrdiff_t next_bytes = h1->table_size * sizeof *h1->next; | ||
| 4638 | h2->next = hash_table_alloc_bytes (next_bytes); | ||
| 4639 | memcpy (h2->next, h1->next, next_bytes); | ||
| 4640 | 4633 | ||
| 4641 | ptrdiff_t index_bytes = h1->index_size * sizeof *h1->index; | 4634 | ptrdiff_t index_bytes = h1->index_size * sizeof *h1->index; |
| 4642 | h2->index = hash_table_alloc_bytes (index_bytes); | 4635 | h2->index = hash_table_alloc_bytes (index_bytes); |
| @@ -4674,11 +4667,12 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 4674 | 4667 | ||
| 4675 | /* Allocate all the new vectors before updating *H, to | 4668 | /* Allocate all the new vectors before updating *H, to |
| 4676 | avoid problems if memory is exhausted. */ | 4669 | avoid problems if memory is exhausted. */ |
| 4677 | hash_idx_t *next = hash_table_alloc_bytes (new_size * sizeof *next); | 4670 | struct hash_next *hash_next |
| 4678 | memcpy (next, h->next, old_size * sizeof *next); | 4671 | = hash_table_alloc_bytes (new_size * sizeof *hash_next); |
| 4672 | memcpy (hash_next, h->hash_next, old_size * sizeof *hash_next); | ||
| 4679 | for (ptrdiff_t i = old_size; i < new_size - 1; i++) | 4673 | for (ptrdiff_t i = old_size; i < new_size - 1; i++) |
| 4680 | next[i] = i + 1; | 4674 | hash_next[i].next = i + 1; |
| 4681 | next[new_size - 1] = -1; | 4675 | hash_next[new_size - 1].next = -1; |
| 4682 | 4676 | ||
| 4683 | Lisp_Object *key_and_value | 4677 | Lisp_Object *key_and_value |
| 4684 | = hash_table_alloc_bytes (2 * new_size * sizeof *key_and_value); | 4678 | = hash_table_alloc_bytes (2 * new_size * sizeof *key_and_value); |
| @@ -4687,9 +4681,6 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 4687 | for (ptrdiff_t i = 2 * old_size; i < 2 * new_size; i++) | 4681 | for (ptrdiff_t i = 2 * old_size; i < 2 * new_size; i++) |
| 4688 | key_and_value[i] = HASH_UNUSED_ENTRY_KEY; | 4682 | key_and_value[i] = HASH_UNUSED_ENTRY_KEY; |
| 4689 | 4683 | ||
| 4690 | hash_hash_t *hash = hash_table_alloc_bytes (new_size * sizeof *hash); | ||
| 4691 | memcpy (hash, h->hash, old_size * sizeof *hash); | ||
| 4692 | |||
| 4693 | ptrdiff_t old_index_size = h->index_size; | 4684 | ptrdiff_t old_index_size = h->index_size; |
| 4694 | ptrdiff_t index_size = hash_index_size (new_size); | 4685 | ptrdiff_t index_size = hash_index_size (new_size); |
| 4695 | hash_idx_t *index = hash_table_alloc_bytes (index_size * sizeof *index); | 4686 | hash_idx_t *index = hash_table_alloc_bytes (index_size * sizeof *index); |
| @@ -4708,11 +4699,8 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 4708 | 2 * old_size * sizeof *h->key_and_value); | 4699 | 2 * old_size * sizeof *h->key_and_value); |
| 4709 | h->key_and_value = key_and_value; | 4700 | h->key_and_value = key_and_value; |
| 4710 | 4701 | ||
| 4711 | hash_table_free_bytes (h->hash, old_size * sizeof *h->hash); | 4702 | hash_table_free_bytes (h->hash_next, old_size * sizeof *h->hash_next); |
| 4712 | h->hash = hash; | 4703 | h->hash_next = hash_next; |
| 4713 | |||
| 4714 | hash_table_free_bytes (h->next, old_size * sizeof *h->next); | ||
| 4715 | h->next = next; | ||
| 4716 | 4704 | ||
| 4717 | h->key_and_value = key_and_value; | 4705 | h->key_and_value = key_and_value; |
| 4718 | 4706 | ||
| @@ -4760,11 +4748,7 @@ hash_table_thaw (Lisp_Object hash_table) | |||
| 4760 | h->index_size = index_size; | 4748 | h->index_size = index_size; |
| 4761 | h->next_free = -1; | 4749 | h->next_free = -1; |
| 4762 | 4750 | ||
| 4763 | h->hash = hash_table_alloc_bytes (size * sizeof *h->hash); | 4751 | h->hash_next = hash_table_alloc_bytes (size * sizeof *h->hash_next); |
| 4764 | |||
| 4765 | h->next = hash_table_alloc_bytes (size * sizeof *h->next); | ||
| 4766 | for (ptrdiff_t i = 0; i < size; i++) | ||
| 4767 | h->next[i] = -1; | ||
| 4768 | 4752 | ||
| 4769 | h->index = hash_table_alloc_bytes (index_size * sizeof *h->index); | 4753 | h->index = hash_table_alloc_bytes (index_size * sizeof *h->index); |
| 4770 | for (ptrdiff_t i = 0; i < index_size; i++) | 4754 | for (ptrdiff_t i = 0; i < index_size; i++) |