public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: hash.c: replace some unsigned long with unsigned int
Date: Wed, 3 May 2023 15:32:09 +0930	[thread overview]
Message-ID: <ZFH44S/nfshKLrn9@squeak.grove.modra.org> (raw)

	* hash.c (higher_prime_number): Use uint32_t param, return value,
	tables and variables.
	(bfd_default_hash_table_size): Make it an unsigned int.
	(bfd_hash_set_default_size): Use unsigned int param and return.
	* bfd-in.h (bfd_hash_set_default_size): Update prototype.
	* bfd-in2.h: Regenerate.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index de7285626cd..0a4da9aa407 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -333,7 +333,7 @@ extern void bfd_hash_traverse
 /* Allows the default size of a hash table to be configured. New hash
    tables allocated using bfd_hash_table_init will be created with
    this size.  */
-extern unsigned long bfd_hash_set_default_size (unsigned long);
+extern unsigned int bfd_hash_set_default_size (unsigned int);
 
 /* This structure is used to keep track of stabs in sections
    information while linking.  */
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c7bcd5f51fb..f5e1c1380c0 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -340,7 +340,7 @@ extern void bfd_hash_traverse
 /* Allows the default size of a hash table to be configured. New hash
    tables allocated using bfd_hash_table_init will be created with
    this size.  */
-extern unsigned long bfd_hash_set_default_size (unsigned long);
+extern unsigned int bfd_hash_set_default_size (unsigned int);
 
 /* This structure is used to keep track of stabs in sections
    information while linking.  */
diff --git a/bfd/hash.c b/bfd/hash.c
index 6e60bedc05b..add7d10ecb3 100644
--- a/bfd/hash.c
+++ b/bfd/hash.c
@@ -304,50 +304,49 @@ SUBSUBSECTION
    greater than N, and near a power of two.  Copied from libiberty.
    Returns zero for ridiculously large N to signify an error.  */
 
-static unsigned long
-higher_prime_number (unsigned long n)
+static uint32_t
+higher_prime_number (uint32_t n)
 {
   /* These are primes that are near, but slightly smaller than, a
      power of two.  */
-  static const unsigned long primes[] =
+  static const uint32_t primes[] =
     {
-      (unsigned long) 31,
-      (unsigned long) 61,
-      (unsigned long) 127,
-      (unsigned long) 251,
-      (unsigned long) 509,
-      (unsigned long) 1021,
-      (unsigned long) 2039,
-      (unsigned long) 4093,
-      (unsigned long) 8191,
-      (unsigned long) 16381,
-      (unsigned long) 32749,
-      (unsigned long) 65521,
-      (unsigned long) 131071,
-      (unsigned long) 262139,
-      (unsigned long) 524287,
-      (unsigned long) 1048573,
-      (unsigned long) 2097143,
-      (unsigned long) 4194301,
-      (unsigned long) 8388593,
-      (unsigned long) 16777213,
-      (unsigned long) 33554393,
-      (unsigned long) 67108859,
-      (unsigned long) 134217689,
-      (unsigned long) 268435399,
-      (unsigned long) 536870909,
-      (unsigned long) 1073741789,
-      (unsigned long) 2147483647,
-					/* 4294967291L */
-      ((unsigned long) 2147483647) + ((unsigned long) 2147483644),
+      UINT32_C (31),
+      UINT32_C (61),
+      UINT32_C (127),
+      UINT32_C (251),
+      UINT32_C (509),
+      UINT32_C (1021),
+      UINT32_C (2039),
+      UINT32_C (4093),
+      UINT32_C (8191),
+      UINT32_C (16381),
+      UINT32_C (32749),
+      UINT32_C (65521),
+      UINT32_C (131071),
+      UINT32_C (262139),
+      UINT32_C (524287),
+      UINT32_C (1048573),
+      UINT32_C (2097143),
+      UINT32_C (4194301),
+      UINT32_C (8388593),
+      UINT32_C (16777213),
+      UINT32_C (33554393),
+      UINT32_C (67108859),
+      UINT32_C (134217689),
+      UINT32_C (268435399),
+      UINT32_C (536870909),
+      UINT32_C (1073741789),
+      UINT32_C (2147483647),
+      UINT32_C (4294967291)
   };
 
-  const unsigned long *low = &primes[0];
-  const unsigned long *high = &primes[sizeof (primes) / sizeof (primes[0])];
+  const uint32_t *low = &primes[0];
+  const uint32_t *high = &primes[sizeof (primes) / sizeof (primes[0])];
 
   while (low != high)
     {
-      const unsigned long *mid = low + (high - low) / 2;
+      const uint32_t *mid = low + (high - low) / 2;
       if (n >= *mid)
 	low = mid + 1;
       else
@@ -360,7 +359,7 @@ higher_prime_number (unsigned long n)
   return *low;
 }
 
-static unsigned long bfd_default_hash_table_size = DEFAULT_SIZE;
+static unsigned int bfd_default_hash_table_size = DEFAULT_SIZE;
 
 /* Create a new hash table, given a number of entries.  */
 
@@ -660,15 +659,15 @@ bfd_hash_traverse (struct bfd_hash_table *table,
  out:
   table->frozen = 0;
 }
-\f
-unsigned long
-bfd_hash_set_default_size (unsigned long hash_size)
+
+unsigned int
+bfd_hash_set_default_size (unsigned int hash_size)
 {
   /* These silly_size values result in around 1G and 32M of memory
      being allocated for the table of pointers.  Note that the number
      of elements allocated will be almost twice the size of any power
      of two chosen here.  */
-  unsigned long silly_size = sizeof (size_t) > 4 ? 0x4000000 : 0x400000;
+  unsigned int silly_size = sizeof (size_t) > 4 ? 0x4000000 : 0x400000;
   if (hash_size > silly_size)
     hash_size = silly_size;
   else if (hash_size != 0)

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-05-03  6:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZFH44S/nfshKLrn9@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).