summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-09-29 04:05:41 +0800
committerGitHub <noreply@github.com>2022-09-28 16:05:41 -0400
commit65c2518d5cae79084190dfd9bdfc757572ed2e79 (patch)
tree96330f14f7d619486f900fc276499b42906e09e1 /lib/pure
parent919a889ba81b882844a90f65fb644bf6266316d7 (diff)
downloadNim-65c2518d5cae79084190dfd9bdfc757572ed2e79.tar.gz
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>
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/strutils.nim21
1 files changed, 1 insertions, 20 deletions
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: "<string.h>".}
-  func c_strstr(haystack, needle: cstring): cstring {.
-    importc: "strstr", header: "<string.h>".}
-
   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".} =