|
From: Seth D. <set...@us...> - 2004-12-05 22:08:37
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22414 Modified Files: stringverbs.c Log Message: optimization - deletefunc now uses readonly handle for input, creates output handle with precisely the right size for output, copies substrings with loadfromhandle Index: stringverbs.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/stringverbs.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** stringverbs.c 5 Dec 2004 00:09:15 -0000 1.4 --- stringverbs.c 5 Dec 2004 22:08:23 -0000 1.5 *************** *** 1362,1365 **** --- 1362,1369 ---- 12/4/2004 smd: optimization - midfunc (ie string.mid) now uses a readonly handle for the input string, and copies only the results to the output string, for performance + + 12/5/2004 smd: optimization - deletefunc now uses a readonly handle for the input + string, creates a new handle sized precisely for the output string, and copies + two parts from the input to the output (substrings before and after the deleted chars) */ *************** *** 1390,1396 **** --- 1394,1408 ---- case deletefunc: { + /* 12/5/2004 smd: optimized */ + Handle x; + Handle hstring; long ctdelete; long ixdelete; + long lenbefore; + long ixbefore; + long ixafter; + long lenafter; + long hlen; if (!getpositivelongvalue (hp1, 2, &ixdelete)) *************** *** 1402,1415 **** return (false); ! if (!getexempttextvalue (hp1, 1, &x)) return (false); ! --ixdelete; /*convert to zero-base*/ ! if (!pullfromhandle (x, ixdelete, ctdelete, nil)) { /*ctdelete too large*/ ! ! if (ixdelete >= 0) ! sethandlesize (x, min (ixdelete, gethandlesize (x))); ! } return (setheapvalue (x, stringvaluetype, v)); --- 1414,1445 ---- return (false); ! if (!getreadonlytextvalue (hp1, 1, &hstring)) return (false); ! hlen = gethandlesize (hstring); ! if (ixdelete > 0) ! --ixdelete; /*convert to zero-base*/ ! ! lenbefore = ixdelete; ! ! ctdelete = min (ctdelete, hlen - ixdelete); /* in case ctdelete is too big */ ! ! ixafter = ixdelete + ctdelete; ! ! lenafter = hlen - ixafter; ! ! if (!newhandle (lenbefore + lenafter, &x)) ! return false; ! ! ixbefore = 0; ! if (lenbefore > 0) ! if (!loadfromhandle (hstring, &ixbefore, lenbefore, *x)) ! return false; ! ! ixbefore += ctdelete; ! if (lenafter > 0) ! if (!loadfromhandle (hstring, &ixbefore, lenafter, &((*x) [lenbefore]) )) ! return false; return (setheapvalue (x, stringvaluetype, v)); |