Skip to content

Commit 23b9b1e

Browse files
committed
C#: Cache Splits::toString()
1 parent 8c7c582 commit 23b9b1e

File tree

1 file changed

+17
-14
lines changed
  • csharp/ql/src/semmle/code/csharp/controlflow/internal

1 file changed

+17
-14
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/internal/Splitting.qll

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ private module Cached {
4848
head = case2aSomeAtRank(pred, predSplits, succ, c, rnk)
4949
)
5050
}
51+
52+
cached
53+
string splitsToString(Splits splits) {
54+
splits = TSplitsNil() and
55+
result = ""
56+
or
57+
exists(SplitInternal head, Splits tail, string headString, string tailString |
58+
splits = TSplitsCons(head, tail)
59+
|
60+
headString = head.toString() and
61+
tailString = tail.toString() and
62+
if tailString = ""
63+
then result = headString
64+
else if headString = "" then result = tailString else result = headString + ", " + tailString
65+
)
66+
}
5167
}
5268
private import Cached
5369

@@ -768,20 +784,7 @@ module BooleanSplitting {
768784
*/
769785
class Splits extends TSplits {
770786
/** Gets a textual representation of this set of splits. */
771-
string toString() {
772-
this = TSplitsNil() and
773-
result = ""
774-
or
775-
exists(SplitInternal head, Splits tail, string headString, string tailString |
776-
this = TSplitsCons(head, tail)
777-
|
778-
headString = head.toString() and
779-
tailString = tail.toString() and
780-
if tailString = ""
781-
then result = headString
782-
else if headString = "" then result = tailString else result = headString + ", " + tailString
783-
)
784-
}
787+
string toString() { result = splitsToString(this) }
785788

786789
/** Gets a split belonging to this set of splits. */
787790
SplitInternal getASplit() {

0 commit comments

Comments
 (0)