comparison src/hashtab.c @ 20007:aadd1cae2ff5 v8.2.0559

patch 8.2.0559: clearing a struct is verbose Commit: https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 12 19:37:17 2020 +0200 patch 8.2.0559: clearing a struct is verbose Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Apr 2020 19:45:05 +0200
parents f0f9692d4487
children 883aa425656a
comparison
equal deleted inserted replaced
20006:aee3c9266968 20007:aadd1cae2ff5
63 */ 63 */
64 void 64 void
65 hash_init(hashtab_T *ht) 65 hash_init(hashtab_T *ht)
66 { 66 {
67 // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". 67 // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray".
68 vim_memset(ht, 0, sizeof(hashtab_T)); 68 CLEAR_POINTER(ht);
69 ht->ht_array = ht->ht_smallarray; 69 ht->ht_array = ht->ht_smallarray;
70 ht->ht_mask = HT_INIT_SIZE - 1; 70 ht->ht_mask = HT_INIT_SIZE - 1;
71 } 71 }
72 72
73 /* 73 /*
392 mch_memmove(temparray, newarray, sizeof(temparray)); 392 mch_memmove(temparray, newarray, sizeof(temparray));
393 oldarray = temparray; 393 oldarray = temparray;
394 } 394 }
395 else 395 else
396 oldarray = ht->ht_array; 396 oldarray = ht->ht_array;
397 CLEAR_FIELD(ht->ht_smallarray);
397 } 398 }
398 else 399 else
399 { 400 {
400 // Allocate an array. 401 // Allocate an array.
401 newarray = ALLOC_MULT(hashitem_T, newsize); 402 newarray = ALLOC_CLEAR_MULT(hashitem_T, newsize);
402 if (newarray == NULL) 403 if (newarray == NULL)
403 { 404 {
404 // Out of memory. When there are NULL items still return OK. 405 // Out of memory. When there are NULL items still return OK.
405 // Otherwise set ht_error, because lookup may result in a hang if 406 // Otherwise set ht_error, because lookup may result in a hang if
406 // we add another item. 407 // we add another item.
409 ht->ht_error = TRUE; 410 ht->ht_error = TRUE;
410 return FAIL; 411 return FAIL;
411 } 412 }
412 oldarray = ht->ht_array; 413 oldarray = ht->ht_array;
413 } 414 }
414 vim_memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize));
415 415
416 /* 416 /*
417 * Move all the items from the old array to the new one, placing them in 417 * Move all the items from the old array to the new one, placing them in
418 * the right spot. The new array won't have any removed items, thus this 418 * the right spot. The new array won't have any removed items, thus this
419 * is also a cleanup action. 419 * is also a cleanup action.