Skip to content

Commit c242674

Browse files
authored
Merge pull request #1076 from jasigal/fix/lastIndexOf-issue-614
Fixed: Investigate performance of lastIndexOf #614
2 parents 9ab281b + bb31bb5 commit c242674

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
test_last_index_of2.class
3+
--refine-strings
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class test_last_index_of2
2+
{
3+
public static void main(String[] args)
4+
{
5+
String letters = "automatictestcasegenerationatdiffblue";
6+
assert(letters.lastIndexOf("diffblue", 25)==-1);
7+
}
8+
}

src/solvers/refinement/string_constraint_generator_indexof.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,22 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of_string(
193193
symbol_exprt contains=fresh_boolean("contains_substring");
194194

195195
// We add axioms:
196-
// a1 : contains ==> offset <= from_index && offset <= |haystack| - |needle|
196+
// a1 : contains ==> -1 <= offset && offset <= from_index
197+
// && offset <= |haystack| - |needle|
197198
// a2 : !contains <=> offset = -1
198-
// a3 : forall n:[0, needle.length[,
199+
// a3 : forall n:[0, |needle|[,
199200
// contains ==> haystack[n+offset] = needle[n]
200201
// a4 : forall n:[offset+1, min(from_index, |haystack| - |needle|)].
201202
// contains ==>
202-
// (exists m:[0,|substring|[. haystack[m+n] != needle[m]])
203+
// (exists m:[0,|needle|[. haystack[m+n] != needle[m]])
203204
// a5: forall n:[0, min(from_index, |haystack| - |needle|)].
204205
// !contains ==>
205-
// (exists m:[0,|substring|[. haystack[m+n] != needle[m])
206+
// (exists m:[0,|needle|[. haystack[m+n] != needle[m])
206207

207208
implies_exprt a1(
208209
contains,
209210
and_exprt(
211+
binary_relation_exprt(from_integer(-1, index_type), ID_le, offset),
210212
binary_relation_exprt(
211213
offset, ID_le, minus_exprt(haystack.length(), needle.length())),
212214
binary_relation_exprt(offset, ID_le, from_index)));
@@ -255,8 +257,8 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of_string(
255257
{
256258
// Unfold the existential quantifier as a disjunction in case of a constant
257259
// a4 && a5 <=> a6:
258-
// forall n:[0, min(from_index,|haystack|-|needle|)].
259-
// !contains || n > offset ==>
260+
// forall n:[0, min(from_index, |haystack| - |needle|)].
261+
// !contains || (n > offset) ==>
260262
// haystack[n] != needle[0] || ... ||
261263
// haystack[n+|needle|-1] != needle[|needle|-1]
262264
symbol_exprt qvar2=fresh_univ_index("QA_index_of_string_2", index_type);
@@ -273,6 +275,7 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of_string(
273275

274276
or_exprt premise(
275277
not_exprt(contains), binary_relation_exprt(qvar2, ID_gt, offset));
278+
276279
string_constraintt a6(
277280
qvar2,
278281
from_integer(0, index_type),

0 commit comments

Comments
 (0)