Skip to content

Commit 6a14977

Browse files
authored
Merge pull request #37 from t-b/speedup
Speedup parsing using regexps
2 parents 3c1f33f + a6c68c0 commit 6a14977

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

procedures/CodeBrowser.ipf

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
373373
End
374374

375375
// Adds Constants/StrConstants by searching for them in the Procedure with a Regular Expression
376-
Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWave)
377-
String module, procedureWithoutModule
376+
Function addDecoratedConstants(text, declWave, lineWave)
377+
WAVE/T text
378378
WAVE/T declWave
379379
WAVE/D lineWave
380380

@@ -383,12 +383,6 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
383383

384384
Wave/T helpWave = getHelpWave()
385385

386-
// get procedure code
387-
procText = getProcedureText("", 0, module, procedureWithoutModule)
388-
numLines = ItemsInList(procText, "\r")
389-
390-
// search code and return wavLineNumber
391-
Make/FREE/N=(numLines)/T text = StringFromList(p, procText, "\r")
392386
// help for regex on https://regex101.com/
393387
re = "^(?i)[[:space:]]*((?:override\s+)?(?:static)?[[:space:]]*(?:Str)?Constant)[[:space:]]+([^=\s]*)\s*=\s*(?:\"(?:[^\"\\\\]|\\\\.)+\"|0[xX][0-9a-fA-F]+|[0-9]+)\s*(?:[\/]{2}.*)?"
394388
Grep/Q/INDX/E=re text
@@ -418,8 +412,8 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
418412
KillWaves/Z W_Index
419413
End
420414

421-
Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
422-
String module, procedureWithoutModule
415+
Function addDecoratedMacros(text, declWave, lineWave)
416+
WAVE/T text
423417
WAVE/T declWave
424418
WAVE/D lineWave
425419

@@ -428,12 +422,6 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
428422

429423
Wave/T helpWave = getHelpWave()
430424

431-
// get procedure code
432-
procText = getProcedureText("", 0, module, procedureWithoutModule)
433-
numLines = ItemsInList(procText, "\r")
434-
435-
// search code and return wavLineNumber
436-
Make/FREE/N=(numLines)/T text = StringFromList(p, procText, "\r")
437425
// regexp: match case insensitive (?i) spaces don't matter. search for window or macro or proc. Macro Name is the the next non-space character followed by brackets () where the arguments are. At the end there might be a colon, specifying the type of macro and a comment beginning with /
438426
// macro should have no arguments. Handled for backwards compatibility.
439427
// help for regex on https://regex101.com/
@@ -462,8 +450,8 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
462450
endfor
463451
End
464452

465-
Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWave, [parseVariables])
466-
String module, procedureWithoutModule
453+
Function addDecoratedStructure(text, declWave, lineWave, [parseVariables])
454+
WAVE/T text
467455
WAVE/T declWave
468456
WAVE/D lineWave
469457
Variable parseVariables
@@ -476,15 +464,6 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
476464

477465
Wave/T helpWave = getHelpWave()
478466

479-
// get procedure code
480-
procText = getProcedureText("", 0, module, procedureWithoutModule)
481-
numLines = ItemsInList(procText, "\r")
482-
if(numLines == 0)
483-
debugPrint("no Content in Procedure " + procedureWithoutModule)
484-
endif
485-
486-
// search code and return wavLineNumber
487-
Make/FREE/N=(numLines)/T text = StringFromList(p, procText, "\r")
488467
// regexp: match case insensitive (?i) leading spaces don't matter. optional static statement. search for structure name which contains no spaces. followed by an optional space and nearly anything like inline comments
489468
// help for regex on https://regex101.com/
490469
reStart = "^(?i)[[:space:]]*((?:static[[:space:]])?)[[:space:]]*structure[[:space:]]+([^[:space:]\/]+)[[:space:]\/]?.*"
@@ -537,8 +516,8 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
537516
WaveClear wavStructureStart, wavStructureEnd
538517
End
539518

540-
Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
541-
String module, procedureWithoutModule
519+
Function addDecoratedMenu(text, declWave, lineWave)
520+
WAVE/T text
542521
WAVE/T declWave
543522
WAVE/D lineWave
544523

@@ -548,12 +527,6 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
548527

549528
Wave/T helpWave = getHelpWave()
550529

551-
// get procedure code
552-
procText = getProcedureText("", 0, module, procedureWithoutModule)
553-
numLines = ItemsInList(procText, "\r")
554-
555-
// search code and return wavLineNumber
556-
Make/FREE/N=(numLines)/T text = StringFromList(p, procText, "\r")
557530
// regexp: match case insensitive (?i) spaces don't matter. search for menu or submenu with a name in double quotes.
558531
// help for regex on https://regex101.com/
559532
re = "^(?i)[[:space:]]*(menu|submenu)[[:space:]]+\"((?:[^\"\\\\]|\\\\.)+)\"(?:[[:space:]]*[,][[:space:]]*(hideable|dynamic|contextualmenu))?"
@@ -738,15 +711,42 @@ Function/S parseProcedure(procedure, [checksumIsCalculated])
738711
// scan and add elements to lists
739712
resetLists(decls, lines, helps)
740713
addDecoratedFunctions(procedure.module, procedure.fullName, decls, lines)
741-
addDecoratedConstants(procedure.module, procedure.name, decls, lines)
742-
addDecoratedMacros(procedure.module, procedure.name, decls, lines)
743-
addDecoratedStructure(procedure.module, procedure.name, decls, lines)
744-
addDecoratedMenu(procedure.module, procedure.name, decls, lines)
714+
715+
WAVE/T procContent = getProcedureTextAsWave(procedure.module, procedure.fullName)
716+
addDecoratedConstants(procContent, decls, lines)
717+
addDecoratedMacros(procContent, decls, lines)
718+
addDecoratedStructure(procContent, decls, lines)
719+
addDecoratedMenu(procContent, decls, lines)
745720

746721
// stop timer
747722
setParsingTime(timerStop(timer))
748723
End
749724

725+
/// @brief Return the text of the given procedure as free wave splitted at the EOL
726+
static Function/WAVE getProcedureTextAsWave(module, procedureWithoutModule)
727+
string module, procedureWithoutModule
728+
729+
string procText
730+
variable numLines
731+
732+
// get procedure code
733+
procText = getProcedureText("", 0, module, procedureWithoutModule)
734+
735+
#if (IgorVersion() >= 7.0)
736+
return ListToTextWave(procText, "\r")
737+
#else
738+
numLines = ItemsInList(procText, "\r")
739+
740+
if(numLines == 0)
741+
Make/FREE/N=(numLines)/T wv
742+
return wv
743+
endif
744+
745+
Make/FREE/N=(numLines)/T wv = StringFromList(p, procText, "\r")
746+
return wv
747+
#endif
748+
End
749+
750750
// Identifier = module#procedure
751751
static Function saveResults(procedure)
752752
STRUCT procedure &procedure

0 commit comments

Comments
 (0)