Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Faststring.dll
Message
From
06/07/2020 17:16:17
 
 
To
06/07/2020 13:51:45
General information
Forum:
Visual FoxPro
Category:
Third party products
Title:
Miscellaneous
Thread ID:
01674989
Message ID:
01675118
Views:
169
guessing you'll get a small boost if
		FOR lnEnd= toString.BaseAdr-1+m.lnBeg+m.lnBegLen TO  toString.BaseAdr-1+toString.Length
			lcVal = SYS(2600, m.lnEnd, lnEndLen)
calculation is unrolled into the loop variable, but this changes lnBeg used in outer while.
Don't think of the string and the position you are currently checking, think linear memory adress from start on and you are more than half way done eliminating pointer calculation. It is only an offset, but zero based, as you already haave coded.

regards
thomas

>I have adapted your code for a replacement to the STREXTRACT function which is considerably faster for large strings (I am parsing the XML files for a XLSX file):
>
>
>LOCAL lcDrawingXML, lcBegDelimiter, lcEndDelimiter, loDrawingXML, lnSecs
>lcDrawingXML = FILETOSTR('drawing1.xml')
>
>DECLARE INTEGER HeapAlloc   IN Win32Api AS apiHeapAlloc INTEGER, INTEGER, INTEGER
>DECLARE INTEGER HeapFree    IN Win32APi AS apiHeapFree INTEGER, INTEGER, INTEGER
>DECLARE LONG GetProcessHeap IN Win32API AS apiGetProcessHeap
>
>lcBegDelimiter = "<xdr:twoCellAnchor>"
>lcEndDelimiter = "</xdr:twoCellAnchor>"
>
>
>loDrawingXML = fAddStringToHeap(lcDrawingXML)
>
>lnSecs = SECONDS()
>lcTwoCellAnchor = fStrExtract(loDrawingXML, lcBegDelimiter, lcEndDelimiter, 1)
>? "SYS(2600): " +  TRANSFORM(SECONDS() - lnSecs)
>_CLIPTEXT = lcTwoCellAnchor
>
>SET STEP ON
>
>lnSecs = SECONDS()
>lcTwoCellAnchor = fStrExtract(loDrawingXML, lcBegDelimiter, lcEndDelimiter, 2000)
>? "SYS(2600): " +  TRANSFORM(SECONDS() - lnSecs)
>_CLIPTEXT = lcTwoCellAnchor
>
>SET STEP ON
>
>loDrawingXML = fReleaseStringFromHeap(loDrawingXML)
>
>
>
>FUNCTION fAddStringToHeap
>LPARAMETERS tcString
>LOCAL loString
>loString = CREATEOBJECT("Empty")
>ADDPROPERTY(loString, "Length", 0)
>ADDPROPERTY(loString, "BaseAdr", 0)
>loString.Length  = LEN(tcString)
>loString.BaseAdr = apiHeapAlloc(apiGetProcessHeap(), 0, loString.Length)
>SYS(2600, loString.BaseAdr, loString.Length, tcString)
>RETURN loString
>ENDFUNC
>
>
>
>FUNCTION fStrExtract
>LPARAMETERS toString, tcBegDelimiter, tcEndDelimiter, tnOccurance
>LOCAL lnBeg, lcVal, lnEnd, lnBegLen, lnEndLen, lcStrExtract
>lnBegLen     = LEN(tcBegDelimiter)
>lnEndLen     = LEN(tcEndDelimiter)
>lnOccurance  = 0
>lcStrExtract = ""
>lnBeg = 1
>DO WHILE lnBeg < toString.Length
>	lcVal = SYS(2600, toString.BaseAdr-1 + lnBeg, lnBegLen)
>	IF lcVal == tcBegDelimiter
>		FOR lnEnd=lnBeg+lnBegLen TO toString.Length
>			lcVal = SYS(2600, toString.BaseAdr-1 + lnEnd, lnEndLen)
>			IF lcVal == tcEndDelimiter
>				lnOccurance = lnOccurance + 1
>				IF lnOccurance = tnOccurance
>					RETURN SYS(2600, toString.BaseAdr-1 + lnBeg, lnEnd - lnBeg + lnBegLen + 1)
>				ENDIF
>				lnBeg = lnEnd - 1
>				EXIT
>			ENDIF
>		ENDFOR
>	ENDIF
>	lnBeg = lnBeg + 1 
>ENDDO
>RETURN lcStrExtract
>ENDFUNC
>
>
>FUNCTION fReleaseStringFromHeap
>LPARAMETERS toString
>apiHeapFree(apiGetProcessHeap(), 0, toString.BaseAdr)
>RETURN .NULL.
>ENDFUNC
>
Previous
Reply
Map
View

Click here to load this message in the networking platform