|
1 | 1 | package normalizer
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "regexp" |
5 | 4 | "testing"
|
6 |
| - "unicode/utf8" |
7 | 5 |
|
8 | 6 | "github.com/stretchr/testify/assert"
|
9 | 7 | "github.com/stretchr/testify/require"
|
@@ -70,69 +68,6 @@ func printDebug(t *testing.T, quoted, actual string) {
|
70 | 68 | }
|
71 | 69 | }
|
72 | 70 |
|
73 |
| -func BenchmarkReplacingNullEscape_Iterative(b *testing.B) { |
74 |
| - b.ReportAllocs() |
75 |
| - for _, test := range testCasesUnquote { |
76 |
| - for n := 0; n < b.N; n++ { |
77 |
| - replaceEscapedMaybeIter(test.quoted, '0', '\x00') |
78 |
| - } |
79 |
| - } |
80 |
| -} |
81 |
| - |
82 |
| -// replaceEscapedMaybeIter is alternative implementation of replaceEscapedMaybe |
83 |
| -// It is only used in benchmark tests for performance comparison. |
84 |
| -func replaceEscapedMaybeIter(s string, old, new rune) string { |
85 |
| - var runeTmp [utf8.UTFMax]byte |
86 |
| - n := utf8.EncodeRune(runeTmp[:], new) |
87 |
| - |
88 |
| - lastCp := 0 |
89 |
| - var buf []byte |
90 |
| - for i, w := 0, 0; i < len(s); i += w { |
91 |
| - r1, w1 := utf8.DecodeRuneInString(s[i:]) |
92 |
| - w = w1 |
93 |
| - if r1 == '\\' { // find sequence \\old[^0-9] |
94 |
| - r2, w2 := utf8.DecodeRuneInString(s[i+w1:]) |
95 |
| - if r2 == old { |
96 |
| - r3, _ := utf8.DecodeRuneInString(s[i+w1+w2:]) |
97 |
| - if 0 > r3 || r3 > 9 { // not a number after "\\old" |
98 |
| - w += w2 |
99 |
| - if len(buf) == 0 { |
100 |
| - buf = make([]byte, 0, 3*len(s)/2) |
101 |
| - } |
102 |
| - buf = append(buf, []byte(s[lastCp:i])...) |
103 |
| - buf = append(buf, runeTmp[:n]...) |
104 |
| - lastCp = i + w |
105 |
| - } |
106 |
| - } |
107 |
| - } |
108 |
| - } |
109 |
| - if lastCp == 0 { |
110 |
| - return s |
111 |
| - } |
112 |
| - |
113 |
| - if 0 < lastCp && lastCp < len(s) { |
114 |
| - return string(append(buf, []byte(s[lastCp:len(s)])...)) |
115 |
| - } |
116 |
| - return string(buf) |
117 |
| -} |
118 |
| - |
119 |
| -func BenchmarkReplacingNullEscape_Regexp(b *testing.B) { |
120 |
| - b.ReportAllocs() |
121 |
| - for _, test := range testCasesUnquote { |
122 |
| - for n := 0; n < b.N; n++ { |
123 |
| - replaceEscapedMaybeRegexp(test.quoted) |
124 |
| - } |
125 |
| - } |
126 |
| -} |
127 |
| - |
128 |
| -var re = regexp.MustCompile(`\\0([^0-9]|$)`) |
129 |
| - |
130 |
| -// replaceEscapedMaybeRegexp is alternative implementation of replaceEscapedMaybe |
131 |
| -// It is only used in benchmark tests for performance comparison. |
132 |
| -func replaceEscapedMaybeRegexp(s string) string { |
133 |
| - return re.ReplaceAllString(s, "\x00$1") |
134 |
| -} |
135 |
| - |
136 | 71 | func BenchmarkReplacingNullEscape_Simple(b *testing.B) {
|
137 | 72 | b.ReportAllocs()
|
138 | 73 | for _, test := range testCasesUnquote {
|
|
0 commit comments