Skip to content

Commit

Permalink
REFACTOR: prettysort should unify FQDN to "@" earlier (#3323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli authored Jan 8, 2025
1 parent f971885 commit 2461f3d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pkg/prettyzone/sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ func (z *ZoneGenData) Less(i, j int) bool {

// Sort by name.

// If we are at the apex, use "@" in the sorting.
compA, compB := a.NameFQDN, b.NameFQDN
//fmt.Printf("DEBUG: LabelLess(%q, %q) = %v %q %q\n", compA, compB, LabelLess(compA, compB), a.Name, b.Name)
compA, compB := a.NameFQDN, b.NameFQDN
// If we are at the apex, pass "@" to the Less function.
if a.Name == "@" {
compA = "@"
}
if b.Name == "@" {
compB = "@"
}
if compA != compB {
if a.Name == "@" {
compA = "@"
}
if b.Name == "@" {
compB = "@"
}
return LabelLess(compA, compB)
}

Expand Down Expand Up @@ -132,8 +132,7 @@ func (z *ZoneGenData) Less(i, j int) bool {
func LabelLess(a, b string) bool {
// Compare two zone labels for the purpose of sorting the RRs in a Zone.

// If they are equal, we are done. All other code is simplified
// because we can assume a!=b.
// If they are equal, we are done. The remainingi code can assume a != b.
if a == b {
return false
}
Expand Down Expand Up @@ -161,15 +160,15 @@ func LabelLess(a, b string) bool {
ia := len(as) - 1
ib := len(bs) - 1

var min int
var minIdx int
if ia < ib {
min = len(as) - 1
minIdx = len(as) - 1
} else {
min = len(bs) - 1
minIdx = len(bs) - 1
}

// Skip the matching highest elements, then compare the next item.
for i, j := ia, ib; min >= 0; i, j, min = i-1, j-1, min-1 {
for i, j := ia, ib; minIdx >= 0; i, j, minIdx = i-1, j-1, minIdx-1 {
// Compare as[i] < bs[j]
// Sort @ at the top, then *, then everything else.
// i.e. @ always is less. * is is less than everything but @.
Expand Down

0 comments on commit 2461f3d

Please # to comment.