Skip to content

Commit fa8fe8b

Browse files
committed
Optimize substrings for performance (h/t @rodinaarssen)
1 parent 836bc0e commit fa8fe8b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/org/rascalmpl/library/String.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ str(str) indentTabsAsSpaces(int tabSize) {
748748
* The number of substrings is quadratic in the size of the string; expensive to compute.
749749
}
750750
set[str] substrings(str input)
751-
= {input[i..i+l] | int i <- [0..size(input)], int l <- [1..size(input)], i + l <= size(input)};
751+
= {input[i..i+l] | int i <- [0..size(input)], int l <- [1..size(input)-i+1]} - input;
752752
753753
@synopsis{If a string does not end with a newline character, append one. }
754754
str insertFinalNewline(str input, list[str] lineseps = newLineCharacters)

0 commit comments

Comments
 (0)