From 65c2518d5cae79084190dfd9bdfc757572ed2e79 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 29 Sep 2022 04:05:41 +0800 Subject: fix #19500; remove find optimization [backport: 1.6] (#19714) * remove find optimization close #19500 * save find to std * add simple tests * Apply suggestions from code review Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> --- lib/pure/strutils.nim | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'lib/pure/strutils.nim') diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 3ae953a55..b6c0d6917 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1882,9 +1882,6 @@ func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = -1): int {. when not (defined(js) or defined(nimdoc) or defined(nimscript)): func c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. importc: "memchr", header: "".} - func c_strstr(haystack, needle: cstring): cstring {. - importc: "strstr", header: "".} - const hasCStringBuiltin = true else: const hasCStringBuiltin = false @@ -1954,23 +1951,7 @@ func find*(s, sub: string, start: Natural = 0, last = -1): int {.rtl, if sub.len > s.len - start: return -1 if sub.len == 1: return find(s, sub[0], start, last) - template useSkipTable = - result = find(initSkipTable(sub), s, sub, start, last) - - when nimvm: - useSkipTable() - else: - when hasCStringBuiltin: - if last < 0 and start < s.len: - let found = c_strstr(s[start].unsafeAddr, sub) - result = if not found.isNil: - cast[ByteAddress](found) -% cast[ByteAddress](s.cstring) - else: - -1 - else: - useSkipTable() - else: - useSkipTable() + result = find(initSkipTable(sub), s, sub, start, last) func rfind*(s: string, sub: char, start: Natural = 0, last = -1): int {.rtl, extern: "nsuRFindChar".} = -- cgit 1.4.1-2-gfad0 lue='author'>author
blob: 50a95eeec82235c07508c334576ca6767957a39f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30