8000 Fix sequence point warning; test cases to meet threshold · python/cpython@fe9e9d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe9e9d9

Browse files
committed
Fix sequence point warning; test cases to meet threshold
1 parent f469766 commit fe9e9d9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Lib/test/string_tests.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,8 @@ def test_rindex(self):
321321
def test_find_periodic_pattern(self):
322322
"""Cover the special path for periodic patterns."""
323323
def reference_find(p, s):
324-
m = len(p)
325324
for i in range(len(s)):
326-
if s[i:i+m] == p:
325+
if s.startswith(p, i):
327326
return i
328327
return -1
329328

@@ -332,8 +331,8 @@ def reference_find(p, s):
332331
for _ in range(1000):
333332
p0 = ''.join(choices('abcde', k=rr(10))) * rr(10, 20)
334333
p = p0[:len(p0) - rr(10)] # pop off some characters
335-
left = ''.join(choices('abcdef', k=rr(200)))
336-
right = ''.join(choices('abcdef', k=rr(200)))
334+
left = ''.join(choices('abcdef', k=rr(2000)))
335+
right = ''.join(choices('abcdef', k=rr(2000)))
337336
text = left + p + right
338337
with self.subTest(p=p, text=text):
339338
self.checkequal(reference_find(p, text),
@@ -344,14 +343,14 @@ def test_find_shift_table_overflow(self):
344343
N = 2**16 + 100 # Overflow the 16-bit shift table
345344

346345
# first check the periodic case
347-
# here, the shift for 'b' is N.
346+
# here, the shift for 'b' is N + 1.
348347
pattern1 = 'a' * N + 'b' + 'a' * N
349348
text1 = 'babbaa' * N + pattern1
350349
self.checkequal(len(text1)-len(pattern1),
351350
text1, 'find', pattern1)
352351

353352
# now check the non-periodic case
354-
# here, the shift for 'd' is 3*(N+1)
353+
# here, the shift for 'd' is 3*(N+1)+1
355354
pattern2 = 'ddd' + 'abc' * N + "eee"
356355
text2 = pattern2[:-1] + "ddeede" * 2 * N + pattern2 + "de" * N
357356
self.checkequal(len(text2) - N*len("de") - len(pattern2),

Objects/stringlib/fastsearch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
357357
LOG("\n> "); LOG("%*s", window - haystack + i, "");
358358
LOG(" ^ <-- cut\n");
359359

360-
if (window[i] != needle[i++]) {
360+
if (window[i] != needle[i]) {
361361
// Sunday's trick: if we're going to jump, we might
362362
// as well jump to line up the character *after* the
363363
// current window.
@@ -376,6 +376,7 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
376376
continue;
377377
}
378378

379+
i++;
379380
while (i < len_needle && needle[i] == window[i]) {
380381
i++;
381382
}
@@ -681,3 +682,4 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n,
681682
return -1;
682683
return count;
683684
}
685+

0 commit comments

Comments
 (0)
0