chris@umcp-cs.UUCP (08/30/84)
Ok, apparently a bunch of people didn't get the other posting, so here again are mods for Gosling Emacs #264 macros.c to speed up initialization. I made these changes quite some time ago so I don't remember precisely what I did, so be sure to save an unmangled copy of macros.c before doing anything else. I think all you have to do is remove the call to SortMacros, remove the MacrosAreSorted variable, and replace ScanMap+InitMacros with the code appended to this letter. However, it may be that DefMac needs to be modified. I've extracted the part of my DefMac that inserts the macro definiton and appended that as well, but beware of another change I've made: I eliminated the bogus `union' so the names of the arguments are different. ----from DefMac---- DefMac (name, string, len, keymap, IsMLisp) char *name, *string; int len; struct keymap *keymap; int IsMLisp; { register int i; register struct BoundName *p; if ((i = FindMac (name)) < 0) { register struct BoundName **bp; register char **np; register struct BoundName **be; if (NMacs >= maxmacs) { error ("Too many macro definitions."); return -1; } np = &MacNames[NMacs]; bp = &MacBodies[NMacs++]; be = &MacBodies[i = -i - 1]; np[1] = 0; /* sneaky! */ while (bp > be) { np[0] = np[-1]; bp[0] = bp[-1]; --np, --bp; } p = *bp = (struct BoundName *) malloc (sizeof *p); p -> b_name = *np = savestr (name); p -> b_StepThrough = 0; } ----end of piece of DefMac---- ----replacement for ScanMap and InitMacros---- static ScanMap (map) register struct keymap *map; { register struct BoundName *p; register c; for (c = 0; c < 0200; c++) if (p = map -> k_binding[c]) { int lo = 0, hi = NMacs - 1; register struct BoundName **m; while (lo <= hi) { register mid = (lo + hi) >> 1; m = &MacBodies[mid]; if (*m == p) goto SkipIt; if (*m > p) hi = mid - 1; else lo = mid + 1; } m = &MacBodies[lo]; { register struct BoundName **j = NewNames++; while (j > m) { j[0] = j[-1]; j--; } } *m = p; NMacs++; SkipIt: if (islower (c)) map -> k_binding[toupper (c)] = p; } } InitMacros () { register int i; register struct BoundName *p; defproc (EditMacro, "edit-macro"); defproc (DefineBufferMacro, "define-buffer-macro"); NMacs = NewNames - MacBodies; QSortA (MacBodies, &MacBodies[NMacs - 1]); ScanMap (&GlobalMap); ScanMap (&ESCmap); ScanMap (&CtlXmap); QSortN (MacBodies, &MacBodies[NMacs - 1]); for (i = 0; p = MacBodies[i]; i++) MacNames[i] = p -> b_name; } static QSortN (l, h) struct BoundName **l; register struct BoundName **h; { register struct BoundName **i, **j; register char *s1, *s2; if ((i = l) >= h) return; j = h; partition: /* while (strcmp ((*i) -> b_name, (*h) -> b_name) < 0) i++; */ for (;;) { s1 = (*i) -> b_name; s2 = (*h) -> b_name; while (*s1 == *s2++) if (*s1++ == 0) goto out1; if (*s1 > *--s2) break; i++; } out1: /* while (--j > i && strcmp ((*j) -> b_name, (*h) -> b_name) > 0); */ while (--j > i) { s1 = (*j) -> b_name; s2 = (*h) -> b_name; while (*s1 == *s2++) if (*s1++ == 0) goto out2; if (*s1 < *--s2) break; } out2: if (i < j) { register struct BoundName *t; t = *i, *i = *j, *j = t; goto partition; } if (i < h) { register struct BoundName *t; t = *i, *i = *h, *h = t; QSortN (i + 1, h); } QSortN (l, i - 1); } static QSortA (l, h) struct BoundName **l; register struct BoundName **h; { register struct BoundName **i, **j; if ((i = l) >= h) return; j = h; partition: while (*i < *h) i++; while (--j > i && *j > *h); if (i < j) { register struct BoundName *t; t = *i, *i = *j, *j = t; goto partition; } if (i < h) { register struct BoundName *t; t = *i, *i = *h, *h = t; QSortA (i + 1, h); } QSortA (l, i - 1); } ----end of replacement---- -- In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland