@@ -22,7 +22,7 @@ import (
2222 "go/ast"
2323 "go/token"
2424 "go/types"
25- "sort "
25+ "slices "
2626 "strings"
2727
2828 apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -173,10 +173,10 @@ func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *api
173173 }
174174 }
175175
176- cmpPriority := func (markers [] schemaMarkerWithName , i , j int ) bool {
176+ cmpPriority := func (i , j schemaMarkerWithName ) int {
177177 var iPriority , jPriority crdmarkers.ApplyPriority
178178
179- switch m := markers [ i ] .SchemaMarker .(type ) {
179+ switch m := i .SchemaMarker .(type ) {
180180 case crdmarkers.ApplyPriorityMarker :
181181 iPriority = m .ApplyPriority ()
182182 case applyFirstMarker :
@@ -185,7 +185,7 @@ func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *api
185185 iPriority = crdmarkers .ApplyPriorityDefault
186186 }
187187
188- switch m := markers [ j ] .SchemaMarker .(type ) {
188+ switch m := j .SchemaMarker .(type ) {
189189 case crdmarkers.ApplyPriorityMarker :
190190 jPriority = m .ApplyPriority ()
191191 case applyFirstMarker :
@@ -194,10 +194,10 @@ func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *api
194194 jPriority = crdmarkers .ApplyPriorityDefault
195195 }
196196
197- return iPriority < jPriority
197+ return int ( iPriority - jPriority )
198198 }
199- sort . Slice (markers , func (i , j int ) bool { return cmpPriority (markers , i , j ) })
200- sort . Slice (itemsMarkers , func (i , j int ) bool { return cmpPriority (itemsMarkers , i , j ) })
199+ slices . SortStableFunc (markers , func (i , j schemaMarkerWithName ) int { return cmpPriority (i , j ) })
200+ slices . SortStableFunc (itemsMarkers , func (i , j schemaMarkerWithName ) int { return cmpPriority (i , j ) })
201201
202202 for _ , schemaMarker := range markers {
203203 if err := schemaMarker .SchemaMarker .ApplyToSchema (props ); err != nil {
@@ -519,7 +519,7 @@ func structToSchema(ctx *schemaContext, structType *ast.StructType) *apiext.JSON
519519 }
520520
521521 // Ensure the required fields are always listed alphabetically.
522- sort . Strings (props .Required )
522+ slices . Sort (props .Required )
523523
524524 return props
525525}
0 commit comments