Skip to content

Commit 52be225

Browse files
committed
fix: fix trim concurrent panic
1 parent 3464bbb commit 52be225

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

tool/trimmer/trim/mark.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ func (t *Trimmer) cleanServiceExtends() {
222222
}
223223
}
224224

225-
var keptPartCache = make(map[*parser.Thrift]bool, 200)
226-
227225
func (t *Trimmer) markKeptPart(ast *parser.Thrift, filename string) (ret bool) {
228-
if kept, ok := keptPartCache[ast]; ok {
226+
if kept, ok := t.keptPartCache[ast]; ok {
229227
return kept
230228
}
231229
defer func() {
232-
keptPartCache[ast] = ret
230+
t.keptPartCache[ast] = ret
233231
}()
234232

235233
for _, constant := range ast.Constants {

tool/trimmer/trim/trimmer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Trimmer struct {
4949
PreservedFiles []string
5050
preserveFileStructs map[*parser.StructLike]struct{}
5151
preserveCache map[*parser.StructLike]bool
52+
keptPartCache map[*parser.Thrift]bool
5253
}
5354

5455
type TrimASTArg struct {
@@ -257,6 +258,7 @@ func newTrimmer(files []string, outDir string) (*Trimmer, error) {
257258
pattern := `(?m)^[\s]*(\/\/|#)[\s]*@preserve[\s]*$`
258259
trimmer.preserveRegex = regexp.MustCompile(pattern)
259260
trimmer.preserveCache = make(map[*parser.StructLike]bool, 200)
261+
trimmer.keptPartCache = make(map[*parser.Thrift]bool, 200)
260262
return trimmer, nil
261263
}
262264

0 commit comments

Comments
 (0)