reuse algorithm.fill while building SkipTable (#18138)

* reuse algorithm.fill while building SkipTable

* Update lib/pure/strutils.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
n5m
2021-06-03 12:25:52 +00:00
committed by GitHub
parent 282d61bafa
commit 9df631a379

View File

@@ -72,7 +72,7 @@ runnableExamples:
import parseutils
from math import pow, floor, log10
from algorithm import reverse
from algorithm import fill, reverse
import std/enumutils
from unicode import toLower, toUpper
@@ -1779,17 +1779,7 @@ func initSkipTable*(a: var SkipTable, sub: string) {.rtl,
extern: "nsuInitSkipTable".} =
## Preprocess table `a` for `sub`.
let m = len(sub)
var i = 0
while i <= 0xff-7:
a[chr(i + 0)] = m
a[chr(i + 1)] = m
a[chr(i + 2)] = m
a[chr(i + 3)] = m
a[chr(i + 4)] = m
a[chr(i + 5)] = m
a[chr(i + 6)] = m
a[chr(i + 7)] = m
i += 8
fill(a, m)
for i in 0 ..< m - 1:
a[sub[i]] = m - 1 - i