|
From: Andre R. <and...@us...> - 2004-12-04 22:23:49
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30744/Common/source Modified Files: Tag: New_Tables_Experiment-branch cancoon.c langhash.c langstartup.c odbengine.c tablecompare.c Log Message: Moved table sorting functions from tablecompare.c to hashcompare.c and made some minor optimizations. By default, tables are now always sorted by name, even during startup before the UserTalk interpreter is fully initialized. Index: cancoon.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/cancoon.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** cancoon.c 1 Nov 2004 12:21:31 -0000 1.4 --- cancoon.c 4 Dec 2004 22:23:38 -0000 1.4.2.1 *************** *** 1780,1783 **** --- 1780,1785 ---- + #if 0 /*2004-12-04 aradke: not used anymore*/ + static short cccomparenodes (hdlhashtable htable, hdlhashnode hnode1, hdlhashnode hnode2) { *************** *** 1785,1788 **** --- 1787,1792 ---- } /*cccomparenodes*/ + #endif + static boolean ccsaveglobals (void) { *************** *** 1858,1862 **** langcallbacks.symbolinsertedcallback = &ccsymbolinserted; ! langcallbacks.comparenodescallback = &cccomparenodes; langcallbacks.saveglobalscallback = &ccsaveglobals; --- 1862,1866 ---- langcallbacks.symbolinsertedcallback = &ccsymbolinserted; ! //langcallbacks.comparenodescallback = &cccomparenodes; /*2004-12-04 aradke: not used anymore*/ langcallbacks.saveglobalscallback = &ccsaveglobals; Index: odbengine.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/odbengine.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** odbengine.c 1 Nov 2004 12:21:31 -0000 1.4 --- odbengine.c 4 Dec 2004 22:23:39 -0000 1.4.2.1 *************** *** 344,348 **** langcallbacks.symbolunlinkingcallback = &odbsymbolunlinking; ! langcallbacks.comparenodescallback = &tablecomparenames; } /*initlangcallbacks*/ --- 344,348 ---- langcallbacks.symbolunlinkingcallback = &odbsymbolunlinking; ! //langcallbacks.comparenodescallback = &tablecomparenames; /*2004-12-04 aradke: not used anymore*/ } /*initlangcallbacks*/ Index: tablecompare.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/tablecompare.c,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -C2 -d -r1.4.2.1 -r1.4.2.2 *** tablecompare.c 15 Nov 2004 20:52:24 -0000 1.4.2.1 --- tablecompare.c 4 Dec 2004 22:23:39 -0000 1.4.2.2 *************** *** 34,38 **** --- 34,42 ---- + /* + 2004-12-04 aradke: the comparison functions moved to langhash.c. + */ + #if 0 static short tablecomparenames (hdlhashnode hnode1, hdlhashnode hnode2) { *************** *** 236,239 **** #endif ! ! --- 240,242 ---- #endif ! #endif \ No newline at end of file Index: langhash.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langhash.c,v retrieving revision 1.4.2.19 retrieving revision 1.4.2.20 diff -C2 -d -r1.4.2.19 -r1.4.2.20 *** langhash.c 3 Dec 2004 13:09:11 -0000 1.4.2.19 --- langhash.c 4 Dec 2004 22:23:39 -0000 1.4.2.20 *************** *** 114,117 **** --- 114,119 ---- + typedef int (*hashcomparefunc) (const void *hn1, const void *hn2); /*2004-12-04 aradke*/ + hdlhashtable currenthashtable = nil; *************** *** 1419,1422 **** --- 1421,1583 ---- #endif + /* + 2004-12-04 aradke: the comparison functions are primarily used to sort tables + and to insert items at the proper position in the current sort order. + both operations are critical to overall performance, so doing things like + looking up the correct comparison callback for every comparison is + a waste of time. + + while we're working on optimizing tables, also optimize the functions + in this file to work well with the C library's qsort and the code in langhash.c. + + the comparision functions moved from tablecompare.c to langhash.c + since this is the only place where we now use them. + */ + + static int hashcomparenames (const void *hnode1, const void *hnode2) { + + /* + 2004-12-04 aradke: moved from tablecompare.c, changed defintion + to be compatible with qsort + */ + + return (compareidentifiers ((***(hdlhashnode *)hnode1).hashkey, (***(hdlhashnode *)hnode2).hashkey)); + } /*hashcomparenames*/ + + + #if !flruntime + + static int hashcomparekinds (const void *hnode1, const void *hnode2) { + + /* + 2004-12-04 aradke: moved from tablecompare.c, changed defintion + to be compatible with qsort + */ + + tyvaluerecord val1, val2; + register tyvaluetype t1, t2; + + val1 = (***(hdlhashnode *)hnode1).val; + + val2 = (***(hdlhashnode *)hnode2).val; + + t1 = val1.valuetype; + + t2 = val2.valuetype; + + if ((t1 == externalvaluetype) && (t2 == externalvaluetype)) { + + register hdlexternalhandle h1 = (hdlexternalhandle) val1.data.externalvalue; + register hdlexternalhandle h2 = (hdlexternalhandle) val2.data.externalvalue; + register tyexternalid id1 = (tyexternalid) (**h1).id; + register tyexternalid id2 = (tyexternalid) (**h2).id; + + if (id1 == id2) + return (hashcomparenames (hnode1, hnode2)); + + return (langexternalcomparetypes (id1, id2)); + } + + if (t1 == externalvaluetype) /*scalars sort before externals*/ + return (1); + + if (t2 == externalvaluetype) /*scalars sort before externals*/ + return (-1); + + if (t1 == t2) + return (hashcomparenames (hnode1, hnode2)); + + return (sgn (t1 - t2)); + } /*hashcomparekinds*/ + + + static int hashcomparevalues (const void *hnode1, const void *hnode2) { + + /* + 2.1b2 dmb: new version, corrects bugs that led to semi-random sorts. now + only values of the same kind are compared, and the valuetype is a strict + secondary sort. + + 2004-12-04 aradke: moved from tablecompare.c, changed defintion + to be compatible with qsort. we allocate temp values in the temp stack + of a table that is supposed to be pushed by the caller. + */ + + register hdlhashnode h1 = *(hdlhashnode *)hnode1; + register hdlhashnode h2 = *(hdlhashnode *)hnode2; + tyvaluerecord val1, val2, vreturned; + register boolean fllessthan = false; + register boolean flequal = false; + boolean flcomparable; + + flcomparable = (**h1).val.valuetype == (**h2).val.valuetype; + + if (flcomparable) { + + //pushhashtable (htable); /*any temps are allocated in this table*/ + + disablelangerror (); /*protect us from error dialogs*/ + + copyvaluerecord ((**h1).val, &val1); + + copyvaluerecord ((**h2).val, &val2); + + flcomparable = LTvalue (val1, val2, &vreturned); + + cleartmpstack (); /*temps no longer needed*/ + + fllessthan = vreturned.data.flvalue; + + if (flcomparable && !fllessthan) { + + copyvaluerecord ((**h1).val, &val1); + + copyvaluerecord ((**h2).val, &val2); + + flcomparable = EQvalue (val1, val2, &vreturned); + + cleartmpstack (); /*temps no longer needed*/ + + flequal = vreturned.data.flvalue; + } + + enablelangerror (); + + //pophashtable (); + } + + if ((!flcomparable) || flequal) + return (hashcomparekinds (hnode1, hnode2)); + + if (fllessthan) + return (-1); + else + return (1); + } /*hashcomparevalues*/ + + #endif + + + static hashcomparefunc hashgetcomparefunc (hdlhashtable htable) { + + #if! flruntime + + switch ((**htable).sortorder) { + + case sortbyvalue: + return (&hashcomparevalues); + + case sortbykind: + return (&hashcomparekinds); + + } /*switch*/ + + #endif + + return (&hashcomparenames); + } /*hashgetcomparefunc*/ + + + #if 0 static int hashcompare (const void *h1, const void *h2) { *************** *** 1425,1428 **** --- 1586,1591 ---- } /*hashcompare*/ + #endif + static boolean hashsortedinsert (hdlhashnode hnode) { *************** *** 1432,1440 **** if ((**currenthashtable).sortedlist == nil) return (true); - - if (langcallbacks.comparenodescallback == (langcomparenodescallback) &falsenoop) - return (listappend ((**currenthashtable).sortedlist, (Handle) hnode)); ! return (listsortedinsert ((**currenthashtable).sortedlist, (Handle) hnode, &hashcompare)); #else --- 1595,1600 ---- if ((**currenthashtable).sortedlist == nil) return (true); ! return (listsortedinsert ((**currenthashtable).sortedlist, (Handle) hnode, hashgetcomparefunc (currenthashtable))); #else *************** *** 1444,1447 **** --- 1604,1608 ---- register hdlhashnode nomad = (**ht).hfirstsort; register hdlhashnode nomadprev = nil; + hashcomparefunc comparefunc = hashgetcomparefunc (currenthashtable); short comparison; *************** *** 1457,1461 **** while (true) { ! comparison = (*langcallbacks.comparenodescallback) (ht, hn, nomad); if (comparison < 0) { --- 1618,1622 ---- while (true) { ! comparison = (*comparefunc) (&hn, &nomad); if (comparison < 0) { *************** *** 1501,1508 **** if ((**currenthashtable).sortedlist == nil) return; - - assert (langcallbacks.comparenodescallback != (langcomparenodescallback) &falsenoop); ! (void) listsorteddelete ((**currenthashtable).sortedlist, (Handle) hnodedelete, &hashcompare); #else --- 1662,1667 ---- if ((**currenthashtable).sortedlist == nil) return; ! (void) listsorteddelete ((**currenthashtable).sortedlist, (Handle) hnodedelete, hashgetcomparefunc (currenthashtable)); #else *************** *** 2621,2627 **** assert ((**ht).ctnodes == listcount ((**ht).sortedlist)); ! pushhashtable (ht); /*required by hashcompare*/ ! listsort ((**ht).sortedlist, &hashcompare); pophashtable (); --- 2780,2786 ---- assert ((**ht).ctnodes == listcount ((**ht).sortedlist)); ! pushhashtable (ht); /*required by comparison function*/ ! listsort ((**ht).sortedlist, hashgetcomparefunc (ht)); pophashtable (); *************** *** 2662,2670 **** #ifdef THINK_C ! qsort (*hlist, ctitems, sizeof (hdlhashnode), (__cmp_func) &hashcompare); #else ! qsort (*hlist, ctitems, sizeof (hdlhashnode), &hashcompare); #endif --- 2821,2829 ---- #ifdef THINK_C ! qsort (*hlist, ctitems, sizeof (hdlhashnode), (__cmp_func) hashgetcomparefunc (ht)); #else ! qsort (*hlist, ctitems, sizeof (hdlhashnode), hashgetcomparefunc (ht)); #endif *************** *** 2725,2729 **** return (hashquicksort (ht)); ! pushhashtable (ht); #ifdef fltablesortorderisarray --- 2884,2888 ---- return (hashquicksort (ht)); ! pushhashtable (ht); /*required by comparison function*/ #ifdef fltablesortorderisarray *************** *** 2731,2735 **** assert ((**ht).sortedlist != nil); ! listresort ((**ht).sortedlist, ix, &hashcompare); #else --- 2890,2894 ---- assert ((**ht).sortedlist != nil); ! listresort ((**ht).sortedlist, ix, hashgetcomparefunc (ht)); #else *************** *** 4251,4255 **** pushhashtable (htable); /*for hashcompare*/ ! flfound = listbinarysearchexact ((**htable).sortedlist, (Handle) hnode, index, &hashcompare); pophashtable (); --- 4410,4414 ---- pushhashtable (htable); /*for hashcompare*/ ! flfound = listbinarysearchexact ((**htable).sortedlist, (Handle) hnode, index, hashgetcomparefunc (htable)); pophashtable (); Index: langstartup.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langstartup.c,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -C2 -d -r1.3.2.2 -r1.3.2.3 *** langstartup.c 1 Dec 2004 19:44:45 -0000 1.3.2.2 --- langstartup.c 4 Dec 2004 22:23:39 -0000 1.3.2.3 *************** *** 824,828 **** langcallbacks.symbolinsertedcallback = (langsymbolinsertedcallback) &truenoop; ! langcallbacks.comparenodescallback = (langcomparenodescallback) &falsenoop; langcallbacks.debuggercallback = (langtreenodecallback) &truenoop; --- 824,828 ---- langcallbacks.symbolinsertedcallback = (langsymbolinsertedcallback) &truenoop; ! //langcallbacks.comparenodescallback = (langcomparenodescallback) &falsenoop; /*2004-12-04 aradke: not used anymore*/ langcallbacks.debuggercallback = (langtreenodecallback) &truenoop; |