Don't init array at run time
authorAlan Modra <amodra@gmail.com>
Sun, 19 Aug 2018 23:55:12 +0000 (09:25 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 20 Aug 2018 00:24:20 +0000 (09:54 +0930)
When it can be done at compile time.

* mmo.c (valid_mmo_symbol_character_set): Initialize and make
array const.
(mmo_init): Don't init valid_mmo_symbol_character_set.

bfd/ChangeLog
bfd/mmo.c

index 4dac44b3fee09db66677253cf52a8e216e563ede..2af1fc04e9ad20b546dfe45d059d06bc37c2970d 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-20  Alan Modra  <amodra@gmail.com>
+
+       * mmo.c (valid_mmo_symbol_character_set): Initialize and make
+       array const.
+       (mmo_init): Don't init valid_mmo_symbol_character_set.
+
 2018-08-20  Alan Modra  <amodra@gmail.com>
 
        * rs6000-core.c (CORE_COMMONSZ): Balance parentheses in expression.
index 6a3e255803babe760cde39b45afaa3b6c38ac11a..152ecc2841e382e0aabb61ea732090d46a4a44e5 100644 (file)
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -431,22 +431,30 @@ static bfd_boolean mmo_write_section_description (bfd *, asection *);
 static bfd_boolean mmo_has_leading_or_trailing_zero_tetra_p (bfd *,
                                                             asection *);
 
-/* Global "const" variables initialized once.  Must not depend on
-   particular input or caller; put such things into the bfd or elsewhere.
-   Look ma, no static per-invocation data!  */
-
-static
-char valid_mmo_symbol_character_set[/* A-Z a-z (we assume consecutive
-                                      codes; sorry EBCDIC:ers!).  */
-                                   + 'Z' - 'A' + 1 + 'z' - 'a' + 1
-                                   /* Digits.  */
-                                   + 10
-                                   /* ':' and '_'.  */
-                                   + 1 + 1
-                                   /* Codes higher than 126.  */
-                                   + 256 - 126
-                                   /* Ending zero.  */
-                                   + 1];
+static const char
+valid_mmo_symbol_character_set[] =
+{
+  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+  ':', '_', 126, 127, 128, 129,
+  130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
+  140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+  150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+  160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
+  170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
+  180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
+  190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
+  200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
+  210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
+  220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
+  230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+  240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
+  250, 251, 252, 253, 254, 255,
+  0
+};
 
 
 /* Get section SECNAME or create one if it doesn't exist.  When creating
@@ -484,21 +492,10 @@ static void
 mmo_init (void)
 {
   static bfd_boolean inited = FALSE;
-  int i = 0;
-  int j = 0;
-  static const char letters[]
-    = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_";
 
   if (inited)
     return;
   inited = TRUE;
-
-  /* Fill in the set of valid symbol characters.  */
-  strcpy (valid_mmo_symbol_character_set, letters);
-  i = strlen (letters);
-
-  for (j = 126; j < 256; j++)
-    valid_mmo_symbol_character_set[i++] = j;
 }
 
 /* Check whether an existing file is an mmo file.  */
This page took 0.028645 seconds and 4 git commands to generate.