Skip to content

Commit

Permalink
Reuse calculated block and feature
Browse files Browse the repository at this point in the history
```
name                         old time/op    new time/op    delta
GetUnicodeBlockAndFeature-8    79.9ns ± 6%    78.7ns ± 6%   -1.46%  (p=0.036 n=30+28)
Parse-8                        40.5µs ± 4%    34.6µs ± 1%  -14.49%  (p=0.000 n=30+27)

name                         old alloc/op   new alloc/op   delta
GetUnicodeBlockAndFeature-8     8.00B ± 0%     8.00B ± 0%     ~     (all equal)
Parse-8                        1.03kB ± 0%    0.47kB ± 0%  -54.26%  (p=0.000 n=30+30)

name                         old allocs/op  new allocs/op  delta
GetUnicodeBlockAndFeature-8      2.00 ± 0%      2.00 ± 0%     ~     (all equal)
Parse-8                           184 ± 0%        46 ± 0%  -75.00%  (p=0.000 n=30+30)
```
  • Loading branch information
sg0hsmt committed Feb 8, 2022
1 parent 49e0009 commit 57c74bc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func ParseWithThreshold(model Model, in string, threshold int) []string {
p2 := "U" // unknown
p3 := "U" // unknown

w1, b1 := getUnicodeBlockAndFeature(runes, 0) // i-3
w2, b2 := getUnicodeBlockAndFeature(runes, 1) // i-2
w3, b3 := getUnicodeBlockAndFeature(runes, 2) // i-1
w4, b4 := getUnicodeBlockAndFeature(runes, 3) // i
w5, b5 := getUnicodeBlockAndFeature(runes, 4) // i+1

for i := 3; i < len(runes); i++ {
w1, b1 := getUnicodeBlockAndFeature(runes, i-3)
w2, b2 := getUnicodeBlockAndFeature(runes, i-2)
w3, b3 := getUnicodeBlockAndFeature(runes, i-1)
w4, b4 := getUnicodeBlockAndFeature(runes, i)
w5, b5 := getUnicodeBlockAndFeature(runes, i+1)
w6, b6 := getUnicodeBlockAndFeature(runes, i+2)

score := getScore(model, w1, w2, w3, w4, w5, w6, b1, b2, b3, b4, b5, b6, p1, p2, p3)
Expand All @@ -55,6 +56,12 @@ func ParseWithThreshold(model Model, in string, threshold int) []string {
} else {
p3 = "O" // negative
}

w1, b1 = w2, b2
w2, b2 = w3, b3
w3, b3 = w4, b4
w4, b4 = w5, b5
w5, b5 = w6, b6
}

if buf.Len() != 0 {
Expand Down

0 comments on commit 57c74bc

Please sign in to comment.