Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): refactor Hash_InitTable



details:   https://anonhg.NetBSD.org/src/rev/20525dbba4d3
branches:  trunk
changeset: 945304:20525dbba4d3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 25 18:03:59 2020 +0000

description:
make(1): refactor Hash_InitTable

First prepare all the data, then initialize the fields in declaration
order.

diffstat:

 usr.bin/make/hash.c |  16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diffs (40 lines):

diff -r ca3a493ec9fd -r 20525dbba4d3 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Sun Oct 25 17:58:53 2020 +0000
+++ b/usr.bin/make/hash.c       Sun Oct 25 18:03:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.49 2020/10/25 17:58:53 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.50 2020/10/25 18:03:59 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
 #include "make.h"
 
 /*     "@(#)hash.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: hash.c,v 1.49 2020/10/25 17:58:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.50 2020/10/25 18:03:59 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -133,15 +133,15 @@
 Hash_InitTable(HashTable *t)
 {
        unsigned int n = 16, i;
-       HashEntry **hp;
+       HashEntry **buckets = bmake_malloc(sizeof(*buckets) * n);
+       for (i = 0; i < n; i++)
+               buckets[i] = NULL;
 
-       t->numEntries = 0;
-       t->maxchain = 0;
+       t->buckets = buckets;
        t->bucketsSize = n;
+       t->numEntries = 0;
        t->bucketsMask = n - 1;
-       t->buckets = hp = bmake_malloc(sizeof(*hp) * n);
-       for (i = 0; i < n; i++)
-               hp[i] = NULL;
+       t->maxchain = 0;
 }
 
 /* Removes everything from the hash table and frees up the memory space it



Home | Main Index | Thread Index | Old Index