Change `declare_builtin' to do a sorted insertion into the table, so
authorChris Hanson <org/chris-hanson/cph>
Thu, 4 Jan 1996 23:59:47 +0000 (23:59 +0000)
committerChris Hanson <org/chris-hanson/cph>
Thu, 4 Jan 1996 23:59:47 +0000 (23:59 +0000)
that a binary search works correctly.

v7/src/microcode/cmpint.c

index 5982466541d958eb805e15b11a142b9b6fc61675..98b4ebabc8fb7996ac6c9ccb27bbe68effe2dbb7 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: cmpint.c,v 1.87 1996/01/04 23:30:48 cph Exp $
+$Id: cmpint.c,v 1.88 1996/01/04 23:59:47 cph Exp $
 
 Copyright (c) 1989-96 Massachusetts Institute of Technology
 
@@ -3442,9 +3442,39 @@ DEFUN (declare_builtin, (builtin, name),
       termination_init_error ();
     }
   }
-  builtins[n_builtins] = builtin;
-  builtin_names[n_builtins++] = name;
-  return;
+  {
+    unsigned int low = 0;
+    unsigned int high = n_builtins;
+    while (1)
+      {
+       if (low < high)
+         {
+           unsigned int middle = ((low + high) / 2);
+           if (builtin < (builtins[middle]))
+             high = middle;
+           else if (builtin > (builtins[middle]))
+             low = (middle + 1);
+           else
+             {
+               (builtin_names[middle]) = name;
+               return;
+             }
+         }
+       else
+         {
+           unsigned int scan = n_builtins;
+           while (low < scan)
+             {
+               (builtins [scan]) = (builtins [scan - 1]);
+               (builtin_names [scan]) = (builtin_names [scan - 1]);
+               scan -= 1;
+             }
+           (builtins [low]) = builtin;
+           (builtin_names [low]) = name;
+           return;
+         }
+      }
+  }
 }
 \f
 char *