From 88c0a83cac6b757b9d104019dfed3d08c95a8613 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 4 Jan 1996 23:59:47 +0000 Subject: [PATCH] Change `declare_builtin' to do a sorted insertion into the table, so that a binary search works correctly. --- v7/src/microcode/cmpint.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/v7/src/microcode/cmpint.c b/v7/src/microcode/cmpint.c index 598246654..98b4ebabc 100644 --- a/v7/src/microcode/cmpint.c +++ b/v7/src/microcode/cmpint.c @@ -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; + } + } + } } char * -- 2.25.1