|
From: Henri A. <has...@us...> - 2004-10-29 09:02:32
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18283 Modified Files: oplist.c langlist.c Log Message: Added opunshifthandle() to make list additions more efficient and logical: we now only iterate through the smaller list, pushing into the longer list if the longer list is on the left side of the operand, and unshifting into the longer list if it's on the right side of the operand. Index: oplist.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/oplist.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** oplist.c 23 Oct 2004 22:42:17 -0000 1.2 --- oplist.c 29 Oct 2004 09:02:22 -0000 1.3 *************** *** 240,243 **** --- 240,322 ---- } /*oppushhandle*/ + + boolean opunshifthandle (hdllistrecord hlist, ptrstring pname, Handle hdata) { + + /* + add a new item at the beginning of the list. link in the indicated handle in the + refcon field of the allocated headrecord. return false if there's an allocation + error. + */ + + register hdllistrecord h = hlist; + register hdlheadrecord hstart; + register hdloutlinerecord ho; + register long ctitems; + hdlheadrecord hnew; + bigstring bs; + + if ((**h).isrecord && (pname == nil)) + goto error; + + ho = (hdloutlinerecord) (**h).houtline; + + if (!oppushoutline (ho)) + goto error; + + ctitems = (**h).ctitems; + + copystring (pname, bs); /*checks for nil*/ + + if (ctitems == 0) { /*adding to an empty list*/ + + hnew = (**ho).hsummit; /*set this guy's refcon handle*/ + + opsetheadstring (hnew, bs); + } + + else { + hstart = (**ho).hsummit; + + if (!opaddheadline (hstart, up, bs, &hnew)) { + + oppopoutline (); + + goto error; + } + + (**ho).ctexpanded++; + + (**hnew).flexpanded = true; + } + + #ifdef fldebug + + if (fldebugging) { + + copystring ((ptrstring) "\x0A" "headline #", bs); + + pushint (ctitems + 1, bs); + + opsetheadstring (hnew, bs); + } + + #endif + + (**hnew).hrefcon = hdata; /*link in the user's data structure*/ + + (**h).ctitems++; + + oppopoutline (); + + return (true); + + error: + + disposehandle (hdata); + + return (false); + } /*opunshifthandle*/ + + boolean oppushdata (hdllistrecord hlist, ptrstring pname, ptrvoid pdata, long ctbytes) { Index: langlist.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langlist.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** langlist.c 23 Oct 2004 22:28:09 -0000 1.2 --- langlist.c 29 Oct 2004 09:02:23 -0000 1.3 *************** *** 892,933 **** 5.0.2b10 dmb: since we throw away v1 and v2, we can boost performance by adding directly to v1 and making that the return value. */ ! hdllistrecord list1 = (*v1).data.listvalue; ! hdllistrecord list2 = (*v2).data.listvalue; hdllistrecord list3; ! long i, n; Handle hitem, hignore; bigstring key; ! //if (!copyvaluerecord (*v1, vreturned)) ! // return (false); ! ! *vreturned = *v1; ! initvalue (v1, novaluetype); ! list3 = (*vreturned).data.listvalue; ! n = opcountlistitems (list2); ! ! for (i = 1; i <= n; ++i) { /*copy values over from second list*/ ! ! if (!opgetlisthandle (list2, i, key, &hitem)) ! return (false); ! if (!copyhandle (hitem, &hitem)) ! return (false); ! ! if ((**list3).isrecord) { ! if (opgetlisthandle (list3, -1, key, &hignore)) ! disposehandle (hitem); else oppushhandle (list3, key, hitem); ! } ! else ! oppushhandle (list3, nil, hitem); ! } return (true); --- 892,962 ---- 5.0.2b10 dmb: since we throw away v1 and v2, we can boost performance by adding directly to v1 and making that the return value. + + 10.0a1 hra: we were always looping through v2, so adding a long list to a small + list was significantly slower (2x or more) than adding the small list to the long + list. Now we always loop through the shortest of the 2 lists. */ ! hdllistrecord list2; hdllistrecord list3; ! long i, n, m, min_mn; Handle hitem, hignore; bigstring key; ! m = opcountlistitems ((*v1).data.listvalue); ! n = opcountlistitems ((*v2).data.listvalue); ! if ( m > n ) { /* the first list is longer than the second: append to the first */ ! list2 = (*v2).data.listvalue; ! *vreturned = *v1; ! initvalue (v1, novaluetype); ! list3 = (*vreturned).data.listvalue; ! for (i = 1; i <= n; ++i) { /*copy values over from second list*/ ! if (!opgetlisthandle (list2, i, key, &hitem)) ! return (false); ! if (!copyhandle (hitem, &hitem)) ! return (false); ! ! if ((**list3).isrecord) { ! ! if (opgetlisthandle (list3, -1, key, &hignore)) ! disposehandle (hitem); ! else ! oppushhandle (list3, key, hitem); ! } else oppushhandle (list3, key, hitem); ! } /*for*/ ! ! } else { /* the second list is longer than the first: prepend to the second */ ! list2 = (*v1).data.listvalue; ! *vreturned = *v2; ! initvalue (v2, novaluetype); ! ! list3 = (*vreturned).data.listvalue; ! ! for (i = m; i >= 1; --i) { /*copy values over from first list, in reverse*/ ! ! if (!opgetlisthandle (list2, i, key, &hitem)) ! return (false); ! ! if (!copyhandle (hitem, &hitem)) ! return (false); ! ! if ((**list3).isrecord) { ! ! if (opgetlisthandle (list3, -1, key, &hignore)) ! disposehandle (hitem); ! else ! opunshifthandle (list3, key, hitem); ! } ! else ! opunshifthandle (list3, key, hitem); ! } /*for*/ ! } return (true); *************** *** 1056,1060 **** --- 1085,1093 ---- break; + + default: + break; } + for (; ix1 <= ix2; ++ix1) { |