minimal perf code change
Posted: Wed Dec 09, 2020 4:16 pm
Hi Robert,
reading up on the sources you pointed to in the vfp / local thread with own brain tuned to rather dumb/not optimizing vfp, the code in
https://github.com/X-Sharp/XSharpPublic ... /Macro.prg
is not nice to CPU...
minimal enhancement writes lFirst only on first, not on every char
but I'd simplify to
Roslyn pretty certain to be smarter than vfp compiler, but this is shorter, probably closer to optimized result IL and stays with traditional loops. Hindbrain does such stupid pet tricks automatically from long exposure to vfp shortcomings...
regards
thomas
reading up on the sources you pointed to in the vfp / local thread with own brain tuned to rather dumb/not optimizing vfp, the code in
https://github.com/X-Sharp/XSharpPublic ... /Macro.prg
is not nice to CPU...
Code: Select all
INTERNAL FUNCTION _IsIdentifier(cName AS STRING) AS LOGIC
LOCAL lFirst := TRUE AS LOGIC
FOREACH VAR c IN cName
IF lFirst
IF ! _IsIdentifierStartChar(c)
RETURN FALSE
ENDIF
ELSE
IF ! _IsIdentifierPartChar(c)
RETURN FALSE
ENDIF
ENDIF
lFirst := FALSE
NEXT
RETURN TRUE
Code: Select all
INTERNAL FUNCTION _IsIdentifier(cName AS STRING) AS LOGIC
LOCAL lFirst := TRUE AS LOGIC
FOREACH VAR c IN cName
IF lFirst
IF ! _IsIdentifierStartChar(c)
RETURN FALSE
ENDIF
lFirst := FALSE
ELSE
IF ! _IsIdentifierPartChar(c)
RETURN FALSE
ENDIF
ENDIF
NEXT
RETURN TRUE
Code: Select all
INTERNAL FUNCTION _IsIdentifier(cName AS STRING) AS LOGIC
*-- guessing this code is from base[0] land, perhaps replace with the constants for base/lowerbound index value
*-- check for empty cName probably not needed, but as previous loop was for ... each, guarantee first char to exist
IF cName:Length()=0 OR ! _IsIdentifierStartChar(cName[0])
RETURN FALSE
ENDIF
*-- loop from 2. char, modify with base index if used not only in zero based strings
FOR var lnRun := 1 TO cName:Length()-1
IF ! _IsIdentifierPartChar(cName[lnRun])
RETURN FALSE
ENDIF
NEXT
RETURN TRUE
regards
thomas