Skip to content

Commit 3fedfbb

Browse files
authored
Revert "UnboundList: More compact string representation"
1 parent 473f974 commit 3fedfbb

1 file changed

Lines changed: 5 additions & 42 deletions

File tree

shared/util/codeql/util/UnboundList.qll

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ overlay[local?]
1010
module;
1111

1212
private import Location
13-
private import Strings
1413

1514
/** Provides the input to `Make`. */
1615
signature module InputSig<LocationSig Location> {
@@ -53,43 +52,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
5352
/** Gets the rank of element `e`, which is used internally in the string encoding. */
5453
int getRank(Element e) { e = DenseRank<DenseRankInput>::denseRank(result) }
5554

56-
/** Gets the ASCII printable excluding `.` with zero-based index `code`. */
57-
pragma[nomagic]
58-
private string interpretAsciiCode(int code) {
59-
exists(int dot, int c |
60-
c = code + 1 and
61-
// `.` is used as element separator, so cannot be used to encode elements
62-
dot = asciiPrintable(".") and
63-
if c < dot then c = asciiPrintable(result) else c + 1 = asciiPrintable(result)
64-
)
65-
}
66-
67-
private int asciiCodes() { result = strictcount(interpretAsciiCode(_)) }
68-
69-
/**
70-
* Gets the `i`th digit (modulo `asciiCodes()`) in a base-`asciiCodes()` integer
71-
* representation of `getRank(e)`.
72-
*/
73-
private int getAsciiCodePart(Element e, int i) {
74-
result = getRank(e) and
75-
i = 0
76-
or
77-
exists(int mid |
78-
mid = getAsciiCodePart(e, i - 1) and
79-
result = mid / asciiCodes() and
80-
result > 0
81-
)
82-
}
83-
84-
pragma[nomagic]
85-
private string encode(Element e) {
86-
result =
87-
strictconcat(string s, int i |
88-
s = interpretAsciiCode(getAsciiCodePart(e, i) % asciiCodes())
89-
|
90-
s order by i
91-
)
92-
}
55+
private string encode(Element e) { result = getRank(e).toString() }
9356

9457
bindingset[s]
9558
private Element decode(string s) { encode(result) = s }
@@ -125,7 +88,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
12588
// Same as
12689
// `result = count(this.indexOf("."))`
12790
// but performs better because it doesn't use an aggregate
128-
result = this.regexpReplaceAll("[^\\.]+", "").length()
91+
result = this.regexpReplaceAll("[0-9]+", "").length()
12992
}
13093

13194
/** Gets the list obtained by appending `suffix` onto this list. */
@@ -160,7 +123,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
160123
// `regexpCapture` will then always join in both groups, only to afterwards filter
161124
// based on the requested group (the group number is not part of the binding set
162125
// of `regexpCapture`)
163-
elem = this.regexpCapture("^([^\\.]+)\\..*$", 1) and
126+
elem = this.regexpCapture("^([0-9]+)\\..*$", 1) and
164127
e = decode(elem) and
165128
suffix = this.suffix(elem.length() + 1)
166129
)
@@ -170,7 +133,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
170133
bindingset[this]
171134
predicate isSnoc(UnboundList prefix, Element e) {
172135
// same remark as above about not using multiple capture groups
173-
prefix = this.regexpCapture("^(|.+\\.)[^\\.]+\\.$", 1) and
136+
prefix = this.regexpCapture("^(|.+\\.)[0-9]+\\.$", 1) and
174137
e = decode(this.substring(prefix.stringLength(), this.stringLength() - 1))
175138
}
176139

@@ -185,7 +148,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
185148
*/
186149
bindingset[this]
187150
UnboundList getProperPrefix(int i) {
188-
exists(string regexp, int occurrenceOffset | regexp = "[^\\.]+\\." |
151+
exists(string regexp, int occurrenceOffset | regexp = "[0-9]+\\." |
189152
exists(this.regexpFind(regexp, i, occurrenceOffset)) and
190153
result = this.prefix(occurrenceOffset)
191154
)

0 commit comments

Comments
 (0)