Skip to content

Commit cad794a

Browse files
committed
fix: sync map impl
1 parent d5a0d6d commit cad794a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Diff for: internal/corazawaf/rule.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,12 @@ var transformationNameToID = sync.Map{} // map[string]int
591591
func transformationID(currentID int, transformationName string) int {
592592
currName := transformationIDToName[currentID]
593593
nextName := fmt.Sprintf("%s+%s", currName, transformationName)
594-
if id, ok := transformationNameToID.Load(nextName); ok {
595-
return id.(int)
596-
}
597-
598-
id := len(transformationIDToName)
599-
transformationIDToName = append(transformationIDToName, nextName)
600-
transformationNameToID.Store(nextName, id)
601-
return id
594+
id, _ := transformationNameToID.LoadOrStore(nextName, func() interface{} {
595+
txid := len(transformationIDToName)
596+
transformationIDToName = append(transformationIDToName, nextName)
597+
return txid
598+
}())
599+
return id.(int)
602600
}
603601

604602
// AddTransformation adds a transformation to the rule

0 commit comments

Comments
 (0)