The prettyPrintVersions function iterates over each line of an input file, which can contain up to 30,000 lines as Today.
Currently, within each iteration, a new regex object is created at FileUtilities.swift:107:
if line.contains(/"implementationVersions" :/) {
Proposed Improvements
- Precreate the regex
Define the regex as a let before the loop, then reuse it within the for-in iteration instead
- Use contain with a substring not regex (optional)
The same result can be achieved with String.contains(:)_ for the string "implementationVersions :". If this approach is retained, let constant from the point 1 can be defined as a string literal instead of regex literal.
The improvements can reduce the parsing of the input content from seconds to milliseconds for the function in questions.