typenative 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +17 -1
- package/bin/cli.js +25 -11
- package/bin/go/convert.js +11 -1
- package/bin/index.js +221 -44
- package/bin/main.js +35 -14
- package/bin/node/assert.js +2 -2
- package/bin/node/buffer.js +9 -0
- package/bin/node/dns.js +1 -1
- package/bin/node/events.js +1 -1
- package/bin/node/fs.js +1 -1
- package/bin/node/fs_watch.js +407 -0
- package/bin/node/http2.js +33 -6
- package/bin/node/readline.js +1 -1
- package/bin/node/registry.js +2 -1
- package/bin/node/stream.js +6 -3
- package/bin/node/timers.js +1 -1
- package/bin/node/tls.js +3 -1
- package/bin/node/typed_arrays.js +608 -0
- package/bin/node/util.js +3 -0
- package/bin/node/zlib.js +131 -16
- package/bin/transpiler.js +684 -62
- package/bin/version.js +1 -1
- package/conformance.md +16 -4
- package/examples/README.md +54 -0
- package/examples/fibonacci/README.md +89 -0
- package/examples/fibonacci/bench.mjs +87 -0
- package/examples/fibonacci/main.ts +21 -0
- package/examples/hello-world/README.md +62 -0
- package/examples/hello-world/bench.mjs +66 -0
- package/examples/hello-world/main.ts +7 -0
- package/examples/json-server/README.md +125 -0
- package/examples/json-server/bench.mjs +171 -0
- package/examples/json-server/main.ts +67 -0
- package/govendor/github.com/andybalholm/brotli/LICENSE +19 -0
- package/govendor/github.com/andybalholm/brotli/README.md +19 -0
- package/govendor/github.com/andybalholm/brotli/backward_references.go +185 -0
- package/govendor/github.com/andybalholm/brotli/backward_references_hq.go +796 -0
- package/govendor/github.com/andybalholm/brotli/bit_cost.go +436 -0
- package/govendor/github.com/andybalholm/brotli/bit_reader.go +266 -0
- package/govendor/github.com/andybalholm/brotli/bitwriter.go +56 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter.go +144 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_command.go +434 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_distance.go +433 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_literal.go +433 -0
- package/govendor/github.com/andybalholm/brotli/brotli_bit_stream.go +1435 -0
- package/govendor/github.com/andybalholm/brotli/cluster.go +30 -0
- package/govendor/github.com/andybalholm/brotli/cluster_command.go +164 -0
- package/govendor/github.com/andybalholm/brotli/cluster_distance.go +326 -0
- package/govendor/github.com/andybalholm/brotli/cluster_literal.go +326 -0
- package/govendor/github.com/andybalholm/brotli/command.go +254 -0
- package/govendor/github.com/andybalholm/brotli/compress_fragment.go +834 -0
- package/govendor/github.com/andybalholm/brotli/compress_fragment_two_pass.go +775 -0
- package/govendor/github.com/andybalholm/brotli/constants.go +77 -0
- package/govendor/github.com/andybalholm/brotli/context.go +2176 -0
- package/govendor/github.com/andybalholm/brotli/decode.go +2570 -0
- package/govendor/github.com/andybalholm/brotli/dictionary.go +122890 -0
- package/govendor/github.com/andybalholm/brotli/dictionary_hash.go +32779 -0
- package/govendor/github.com/andybalholm/brotli/encode.go +1220 -0
- package/govendor/github.com/andybalholm/brotli/encoder.go +177 -0
- package/govendor/github.com/andybalholm/brotli/encoder_dict.go +22 -0
- package/govendor/github.com/andybalholm/brotli/encoder_fast.go +201 -0
- package/govendor/github.com/andybalholm/brotli/entropy_encode.go +592 -0
- package/govendor/github.com/andybalholm/brotli/entropy_encode_static.go +4399 -0
- package/govendor/github.com/andybalholm/brotli/fast_log.go +290 -0
- package/govendor/github.com/andybalholm/brotli/find_match_length.go +45 -0
- package/govendor/github.com/andybalholm/brotli/go.mod +3 -0
- package/govendor/github.com/andybalholm/brotli/h10.go +287 -0
- package/govendor/github.com/andybalholm/brotli/h5.go +214 -0
- package/govendor/github.com/andybalholm/brotli/h6.go +216 -0
- package/govendor/github.com/andybalholm/brotli/hash.go +342 -0
- package/govendor/github.com/andybalholm/brotli/hash_composite.go +93 -0
- package/govendor/github.com/andybalholm/brotli/hash_forgetful_chain.go +252 -0
- package/govendor/github.com/andybalholm/brotli/hash_longest_match_quickly.go +214 -0
- package/govendor/github.com/andybalholm/brotli/hash_rolling.go +168 -0
- package/govendor/github.com/andybalholm/brotli/histogram.go +226 -0
- package/govendor/github.com/andybalholm/brotli/http.go +201 -0
- package/govendor/github.com/andybalholm/brotli/huffman.go +653 -0
- package/govendor/github.com/andybalholm/brotli/literal_cost.go +182 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain1.go +212 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain2.go +248 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain3.go +278 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/emitter.go +34 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/m0.go +175 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/m4.go +339 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/matchfinder.go +103 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/pathfinder.go +328 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/textencoder.go +53 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/trio.go +327 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zdfast.go +258 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zfast.go +206 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zm.go +302 -0
- package/govendor/github.com/andybalholm/brotli/memory.go +66 -0
- package/govendor/github.com/andybalholm/brotli/metablock.go +574 -0
- package/govendor/github.com/andybalholm/brotli/metablock_command.go +165 -0
- package/govendor/github.com/andybalholm/brotli/metablock_distance.go +165 -0
- package/govendor/github.com/andybalholm/brotli/metablock_literal.go +165 -0
- package/govendor/github.com/andybalholm/brotli/params.go +37 -0
- package/govendor/github.com/andybalholm/brotli/platform.go +103 -0
- package/govendor/github.com/andybalholm/brotli/prefix.go +30 -0
- package/govendor/github.com/andybalholm/brotli/prefix_dec.go +723 -0
- package/govendor/github.com/andybalholm/brotli/quality.go +196 -0
- package/govendor/github.com/andybalholm/brotli/reader.go +127 -0
- package/govendor/github.com/andybalholm/brotli/ringbuffer.go +134 -0
- package/govendor/github.com/andybalholm/brotli/state.go +313 -0
- package/govendor/github.com/andybalholm/brotli/static_dict.go +662 -0
- package/govendor/github.com/andybalholm/brotli/static_dict_lut.go +75094 -0
- package/govendor/github.com/andybalholm/brotli/symbol_list.go +22 -0
- package/govendor/github.com/andybalholm/brotli/transform.go +641 -0
- package/govendor/github.com/andybalholm/brotli/utf8_util.go +70 -0
- package/govendor/github.com/andybalholm/brotli/util.go +7 -0
- package/govendor/github.com/andybalholm/brotli/write_bits.go +52 -0
- package/govendor/github.com/andybalholm/brotli/writer.go +162 -0
- package/govendor/github.com/fsnotify/fsnotify/.mailmap +2 -0
- package/govendor/github.com/fsnotify/fsnotify/CHANGELOG.md +651 -0
- package/govendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md +147 -0
- package/govendor/github.com/fsnotify/fsnotify/LICENSE +25 -0
- package/govendor/github.com/fsnotify/fsnotify/README.md +214 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_fen.go +469 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_inotify.go +597 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_kqueue.go +735 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_other.go +22 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_windows.go +702 -0
- package/govendor/github.com/fsnotify/fsnotify/fsnotify.go +526 -0
- package/govendor/github.com/fsnotify/fsnotify/go.mod +3 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/darwin.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_darwin.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_dragonfly.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_freebsd.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_kqueue.go +32 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_linux.go +56 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_openbsd.go +16 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_solaris.go +45 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_windows.go +40 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/freebsd.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/internal.go +2 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/unix.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/unix2.go +25 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/windows.go +40 -0
- package/govendor/github.com/fsnotify/fsnotify/shared.go +64 -0
- package/govendor/github.com/fsnotify/fsnotify/staticcheck.conf +3 -0
- package/govendor/github.com/fsnotify/fsnotify/system_bsd.go +7 -0
- package/govendor/github.com/fsnotify/fsnotify/system_darwin.go +8 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/types/typenative-npm.d.ts +72 -0
- package/types/typenative.d.ts +117 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
package matchfinder
|
|
2
|
+
|
|
3
|
+
import "encoding/binary"
|
|
4
|
+
|
|
5
|
+
const (
|
|
6
|
+
zmTableBits = 15
|
|
7
|
+
zmTableSize = 1 << zmTableBits
|
|
8
|
+
zmLongTableBits = 17
|
|
9
|
+
zmLongTableSize = 1 << zmLongTableBits
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// ZM is a MatchFinder that combines the cache tables of ZDFast with the
|
|
13
|
+
// overlap-based parsing of M4.
|
|
14
|
+
type ZM struct {
|
|
15
|
+
MaxDistance int
|
|
16
|
+
history []byte
|
|
17
|
+
table [zmTableSize]tableEntry
|
|
18
|
+
longTable [zmLongTableSize]tableEntry
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func (z *ZM) Reset() {
|
|
22
|
+
z.table = [zmTableSize]tableEntry{}
|
|
23
|
+
z.longTable = [zmLongTableSize]tableEntry{}
|
|
24
|
+
z.history = z.history[:0]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func (z *ZM) FindMatches(dst []Match, src []byte) []Match {
|
|
28
|
+
if z.MaxDistance == 0 {
|
|
29
|
+
z.MaxDistance = 1 << 16
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if len(z.history) > z.MaxDistance*2 {
|
|
33
|
+
delta := len(z.history) - z.MaxDistance
|
|
34
|
+
copy(z.history, z.history[delta:])
|
|
35
|
+
z.history = z.history[:z.MaxDistance]
|
|
36
|
+
|
|
37
|
+
for i := range z.table {
|
|
38
|
+
v := z.table[i].offset
|
|
39
|
+
v -= int32(delta)
|
|
40
|
+
if v < 0 {
|
|
41
|
+
z.table[i] = tableEntry{}
|
|
42
|
+
} else {
|
|
43
|
+
z.table[i].offset = v
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for i := range z.longTable {
|
|
47
|
+
v := z.longTable[i].offset
|
|
48
|
+
v -= int32(delta)
|
|
49
|
+
if v < 0 {
|
|
50
|
+
z.longTable[i] = tableEntry{}
|
|
51
|
+
} else {
|
|
52
|
+
z.longTable[i].offset = v
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
e := matchEmitter{
|
|
58
|
+
Dst: dst,
|
|
59
|
+
NextEmit: len(z.history),
|
|
60
|
+
}
|
|
61
|
+
z.history = append(z.history, src...)
|
|
62
|
+
|
|
63
|
+
if len(src) < 16 {
|
|
64
|
+
return append(dst, Match{
|
|
65
|
+
Unmatched: len(src),
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
src = z.history
|
|
70
|
+
|
|
71
|
+
// matches stores the matches that have been found but not emitted,
|
|
72
|
+
// in reverse order. (matches[0] is the most recent one.)
|
|
73
|
+
var matches [3]absoluteMatch
|
|
74
|
+
|
|
75
|
+
sLimit := int32(len(src)) - 10
|
|
76
|
+
|
|
77
|
+
mainLoop:
|
|
78
|
+
for {
|
|
79
|
+
// Search for a match, starting after the last match emitted.
|
|
80
|
+
s := int32(e.NextEmit)
|
|
81
|
+
if s > sLimit {
|
|
82
|
+
break mainLoop
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// t will contain the match offset when we find one.
|
|
86
|
+
var t int32
|
|
87
|
+
|
|
88
|
+
cv := binary.LittleEndian.Uint64(src[s:])
|
|
89
|
+
|
|
90
|
+
for {
|
|
91
|
+
nextHashL := z.hashLong(cv)
|
|
92
|
+
nextHashS := z.hashShort(cv)
|
|
93
|
+
candidateL := z.longTable[nextHashL]
|
|
94
|
+
candidateS := z.table[nextHashS]
|
|
95
|
+
|
|
96
|
+
entry := tableEntry{offset: s, val: uint32(cv)}
|
|
97
|
+
z.longTable[nextHashL] = entry
|
|
98
|
+
z.table[nextHashS] = entry
|
|
99
|
+
|
|
100
|
+
// Look for a repeat match one byte after the current position.
|
|
101
|
+
if len(e.Dst) > 0 {
|
|
102
|
+
prevDistance := int32(e.Dst[len(e.Dst)-1].Distance)
|
|
103
|
+
if prevDistance != 0 {
|
|
104
|
+
repIndex := s - prevDistance + 1
|
|
105
|
+
if repIndex >= 0 && binary.LittleEndian.Uint32(src[repIndex:]) == uint32(cv>>8) {
|
|
106
|
+
// There is a repeated match at s+2.
|
|
107
|
+
s++
|
|
108
|
+
t = repIndex
|
|
109
|
+
break
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if candidateL.offset < s && s-candidateL.offset < int32(z.MaxDistance) && uint32(cv) == candidateL.val &&
|
|
115
|
+
binary.LittleEndian.Uint32(src[candidateL.offset:]) == uint32(cv) {
|
|
116
|
+
// There is a long match at s.
|
|
117
|
+
t = candidateL.offset
|
|
118
|
+
break
|
|
119
|
+
}
|
|
120
|
+
if candidateS.offset < s && s-candidateS.offset < int32(z.MaxDistance) && uint32(cv) == candidateS.val &&
|
|
121
|
+
binary.LittleEndian.Uint32(src[candidateS.offset:]) == uint32(cv) {
|
|
122
|
+
// There is a regular match at s.
|
|
123
|
+
// See if we can find a long match at s+1.
|
|
124
|
+
cv := binary.LittleEndian.Uint64(src[s+1:])
|
|
125
|
+
nextHashL = z.hashLong(cv)
|
|
126
|
+
candidateL = z.longTable[nextHashL]
|
|
127
|
+
coffsetL := s - candidateL.offset + 1
|
|
128
|
+
z.longTable[nextHashL] = tableEntry{offset: s + 1, val: uint32(cv)}
|
|
129
|
+
if candidateL.offset < s+1 && coffsetL < int32(z.MaxDistance) && uint32(cv) == candidateL.val &&
|
|
130
|
+
binary.LittleEndian.Uint32(src[candidateL.offset:]) == uint32(cv) {
|
|
131
|
+
// We found a long match at s+1, so we'll use that instead
|
|
132
|
+
// of the regular match at s.
|
|
133
|
+
t = candidateL.offset
|
|
134
|
+
s++
|
|
135
|
+
break
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
t = candidateS.offset
|
|
139
|
+
break
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
s += 1 + ((s - int32(e.NextEmit)) >> 7)
|
|
143
|
+
if s > sLimit {
|
|
144
|
+
break mainLoop
|
|
145
|
+
}
|
|
146
|
+
cv = binary.LittleEndian.Uint64(src[s:])
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
currentMatch := extendMatch2(src, int(s), int(t), e.NextEmit)
|
|
150
|
+
matches[0] = currentMatch
|
|
151
|
+
|
|
152
|
+
// Store some table entries after s.
|
|
153
|
+
index0 := s + 1
|
|
154
|
+
cv0 := binary.LittleEndian.Uint64(src[index0:])
|
|
155
|
+
te0 := tableEntry{offset: index0, val: uint32(cv0)}
|
|
156
|
+
z.longTable[z.hashLong(cv0)] = te0
|
|
157
|
+
cv0 >>= 8
|
|
158
|
+
te0.offset++
|
|
159
|
+
te0.val = uint32(cv0)
|
|
160
|
+
z.table[z.hashShort(cv0)] = te0
|
|
161
|
+
|
|
162
|
+
// We have a match in matches[0].
|
|
163
|
+
// Now look for overlapping matches.
|
|
164
|
+
|
|
165
|
+
for {
|
|
166
|
+
if matches[0].End > int(sLimit) {
|
|
167
|
+
break
|
|
168
|
+
}
|
|
169
|
+
s = int32(max(matches[0].Start+2, matches[0].End-6))
|
|
170
|
+
cv = binary.LittleEndian.Uint64(src[s:])
|
|
171
|
+
|
|
172
|
+
nextHashL := z.hashLong(cv)
|
|
173
|
+
nextHashS := z.hashShort(cv)
|
|
174
|
+
candidateL := z.longTable[nextHashL]
|
|
175
|
+
candidateS := z.table[nextHashS]
|
|
176
|
+
|
|
177
|
+
entry := tableEntry{offset: s, val: uint32(cv)}
|
|
178
|
+
z.longTable[nextHashL] = entry
|
|
179
|
+
z.table[nextHashS] = entry
|
|
180
|
+
|
|
181
|
+
t = -1
|
|
182
|
+
if candidateL.offset < s && s-candidateL.offset < int32(z.MaxDistance) && uint32(cv) == candidateL.val &&
|
|
183
|
+
binary.LittleEndian.Uint32(src[candidateL.offset:]) == uint32(cv) {
|
|
184
|
+
// There is a long match at s.
|
|
185
|
+
t = candidateL.offset
|
|
186
|
+
} else if candidateS.offset < s && s-candidateS.offset < int32(z.MaxDistance) && uint32(cv) == candidateS.val &&
|
|
187
|
+
binary.LittleEndian.Uint32(src[candidateS.offset:]) == uint32(cv) {
|
|
188
|
+
// There is a regular match at s.
|
|
189
|
+
t = candidateS.offset
|
|
190
|
+
// See if we can find a long match at s+1.
|
|
191
|
+
cv := binary.LittleEndian.Uint64(src[s+1:])
|
|
192
|
+
nextHashL = z.hashLong(cv)
|
|
193
|
+
candidateL = z.longTable[nextHashL]
|
|
194
|
+
coffsetL := s - candidateL.offset + 1
|
|
195
|
+
z.longTable[nextHashL] = tableEntry{offset: s + 1, val: uint32(cv)}
|
|
196
|
+
if candidateL.offset < s+1 && coffsetL < int32(z.MaxDistance) && uint32(cv) == candidateL.val &&
|
|
197
|
+
binary.LittleEndian.Uint32(src[candidateL.offset:]) == uint32(cv) {
|
|
198
|
+
// We found a long match at s+1, so we'll use that instead
|
|
199
|
+
// of the regular match at s.
|
|
200
|
+
t = candidateL.offset
|
|
201
|
+
s++
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if t == -1 {
|
|
206
|
+
// No overlapping match was found.
|
|
207
|
+
break
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
newMatch := extendMatch2(src, int(s), int(t), e.NextEmit)
|
|
211
|
+
|
|
212
|
+
if newMatch.End-newMatch.Start <= matches[0].End-matches[0].Start {
|
|
213
|
+
// The new match isn't longer than the old one, so we break out of the loop
|
|
214
|
+
// of looking for overlapping matches.
|
|
215
|
+
break
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
matches = [3]absoluteMatch{
|
|
219
|
+
newMatch,
|
|
220
|
+
matches[0],
|
|
221
|
+
matches[1],
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if matches[2] == (absoluteMatch{}) {
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// We have three matches, so it's time to emit one and/or eliminate one.
|
|
229
|
+
switch {
|
|
230
|
+
case matches[0].Start < matches[2].End:
|
|
231
|
+
// The first and third matches overlap; discard the one in between.
|
|
232
|
+
matches = [3]absoluteMatch{
|
|
233
|
+
matches[0],
|
|
234
|
+
matches[2],
|
|
235
|
+
{},
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
case matches[0].Start < matches[2].End+4:
|
|
239
|
+
// The first and third matches don't overlap, but there's no room for
|
|
240
|
+
// another match between them. Emit the first match and discard the second.
|
|
241
|
+
e.emit(matches[2])
|
|
242
|
+
matches = [3]absoluteMatch{
|
|
243
|
+
matches[0],
|
|
244
|
+
{},
|
|
245
|
+
{},
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
default:
|
|
249
|
+
// Emit the first match, shortening it if necessary to avoid overlap with the second.
|
|
250
|
+
if matches[2].End > matches[1].Start {
|
|
251
|
+
matches[2].End = matches[1].Start
|
|
252
|
+
}
|
|
253
|
+
if matches[2].End-matches[2].Start >= 4 {
|
|
254
|
+
e.emit(matches[2])
|
|
255
|
+
}
|
|
256
|
+
matches[2] = absoluteMatch{}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Store some table entries at the end of the last match.
|
|
261
|
+
index1 := int32(matches[0].End - 2)
|
|
262
|
+
if index1 < sLimit {
|
|
263
|
+
cv1 := binary.LittleEndian.Uint64(src[index1:])
|
|
264
|
+
te1 := tableEntry{offset: index1, val: uint32(cv1)}
|
|
265
|
+
z.longTable[z.hashLong(cv1)] = te1
|
|
266
|
+
cv1 >>= 8
|
|
267
|
+
te1.offset++
|
|
268
|
+
te1.val = uint32(cv1)
|
|
269
|
+
z.table[z.hashShort(cv1)] = te1
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// We're done looking for overlapping matches; emit the ones we have.
|
|
273
|
+
|
|
274
|
+
if matches[1] != (absoluteMatch{}) {
|
|
275
|
+
if matches[1].End > matches[0].Start {
|
|
276
|
+
matches[1].End = matches[0].Start
|
|
277
|
+
}
|
|
278
|
+
if matches[1].End-matches[1].Start >= 4 {
|
|
279
|
+
e.emit(matches[1])
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
e.emit(matches[0])
|
|
283
|
+
matches = [3]absoluteMatch{}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
dst = e.Dst
|
|
287
|
+
if e.NextEmit < len(src) {
|
|
288
|
+
dst = append(dst, Match{
|
|
289
|
+
Unmatched: len(src) - e.NextEmit,
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return dst
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
func (z *ZM) hashShort(u uint64) uint32 {
|
|
297
|
+
return uint32(((u << 24) * 889523592379) >> (64 - zmTableBits))
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
func (z *ZM) hashLong(u uint64) uint32 {
|
|
301
|
+
return uint32((u * 0xcf1bbcdcb7a56463) >> (64 - zmLongTableBits))
|
|
302
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package brotli
|
|
2
|
+
|
|
3
|
+
/* Copyright 2016 Google Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
Distributed under MIT license.
|
|
6
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Dynamically grows array capacity to at least the requested size
|
|
11
|
+
T: data type
|
|
12
|
+
A: array
|
|
13
|
+
C: capacity
|
|
14
|
+
R: requested size
|
|
15
|
+
*/
|
|
16
|
+
func brotli_ensure_capacity_uint8_t(a *[]byte, c *uint, r uint) {
|
|
17
|
+
if *c < r {
|
|
18
|
+
var new_size uint = *c
|
|
19
|
+
if new_size == 0 {
|
|
20
|
+
new_size = r
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for new_size < r {
|
|
24
|
+
new_size *= 2
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if cap(*a) < int(new_size) {
|
|
28
|
+
var new_array []byte = make([]byte, new_size)
|
|
29
|
+
if *c != 0 {
|
|
30
|
+
copy(new_array, (*a)[:*c])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
*a = new_array
|
|
34
|
+
} else {
|
|
35
|
+
*a = (*a)[:new_size]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
*c = new_size
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func brotli_ensure_capacity_uint32_t(a *[]uint32, c *uint, r uint) {
|
|
43
|
+
var new_array []uint32
|
|
44
|
+
if *c < r {
|
|
45
|
+
var new_size uint = *c
|
|
46
|
+
if new_size == 0 {
|
|
47
|
+
new_size = r
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for new_size < r {
|
|
51
|
+
new_size *= 2
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if cap(*a) < int(new_size) {
|
|
55
|
+
new_array = make([]uint32, new_size)
|
|
56
|
+
if *c != 0 {
|
|
57
|
+
copy(new_array, (*a)[:*c])
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
*a = new_array
|
|
61
|
+
} else {
|
|
62
|
+
*a = (*a)[:new_size]
|
|
63
|
+
}
|
|
64
|
+
*c = new_size
|
|
65
|
+
}
|
|
66
|
+
}
|