Prepare item and enemy event sort keys once
This commit is contained in:
@@ -92,6 +92,7 @@ type normalizedRecord struct {
|
||||
occurrence dnd.ItemOccurrence
|
||||
identity string
|
||||
inputIndex int
|
||||
orderKey itemoccurrencemodel.CanonicalOrderKey
|
||||
}
|
||||
|
||||
func normalizeList(input dnd.ItemOccurrenceList, index source.DocumentIndex, order shared.SourceRefOrder, registry *itemregistry.Registry) (dnd.ItemOccurrenceList, []diagnostics.Finding) {
|
||||
@@ -103,7 +104,7 @@ func normalizeList(input dnd.ItemOccurrenceList, index source.DocumentIndex, ord
|
||||
findings := make([]diagnostics.Finding, 0)
|
||||
for index, inputOccurrence := range input.Occurrences {
|
||||
occurrence, changedFields, found, refsChanged := normalizeOccurrence(inputOccurrence, order, registry)
|
||||
records[index] = normalizedRecord{occurrence: occurrence, identity: itemoccurrencemodel.CanonicalExactIdentity(occurrence), inputIndex: index}
|
||||
records[index] = normalizedRecord{occurrence: occurrence, identity: itemoccurrencemodel.CanonicalExactIdentity(occurrence), inputIndex: index, orderKey: itemoccurrencemodel.PrepareCanonicalOrder(order, occurrence)}
|
||||
if len(changedFields) != 0 {
|
||||
findings = append(findings, diagnostics.Finding{
|
||||
Scope: occurrenceScope(index),
|
||||
@@ -131,7 +132,8 @@ func normalizeList(input dnd.ItemOccurrenceList, index source.DocumentIndex, ord
|
||||
}
|
||||
|
||||
sort.SliceStable(records, func(left, right int) bool {
|
||||
return itemoccurrencemodel.CanonicalLess(order, records[left].occurrence, records[right].occurrence)
|
||||
l, r := records[left], records[right]
|
||||
return itemoccurrencemodel.CanonicalLessPrepared(order, l.occurrence, r.occurrence, l.orderKey, r.orderKey)
|
||||
})
|
||||
for position, record := range records {
|
||||
if position == record.inputIndex {
|
||||
|
||||
Reference in New Issue
Block a user