Improve D&D registry normalization efficiency
This commit is contained in:
@@ -241,20 +241,15 @@ func normalizeRecord(input dnd.Item, order shared.SourceRefOrder) (dnd.Item, boo
|
||||
|
||||
func comparisonNameGroups(records []normalizedRecord) [][]int {
|
||||
groups := make([][]int, 0, len(records))
|
||||
groupPositions := make(map[string]int, len(records))
|
||||
for index, record := range records {
|
||||
key := identity.ComparisonKey(record.item.Name)
|
||||
found := false
|
||||
for groupIndex, members := range groups {
|
||||
first := records[members[0]]
|
||||
if identity.ComparisonKey(first.item.Name) == key {
|
||||
groups[groupIndex] = append(groups[groupIndex], index)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
groups = append(groups, []int{index})
|
||||
if groupIndex, found := groupPositions[key]; found {
|
||||
groups[groupIndex] = append(groups[groupIndex], index)
|
||||
continue
|
||||
}
|
||||
groupPositions[key] = len(groups)
|
||||
groups = append(groups, []int{index})
|
||||
}
|
||||
return groups
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user