|
sort.Slice(fields, func(i, j int) bool { |
|
ti, tj := fields[i].Type(), fields[j].Type() |
|
si, sj := sizes.Sizeof(ti), sizes.Sizeof(tj) |
|
|
|
if si == 0 && sj != 0 { |
|
return true |
|
} |
|
if sj == 0 && si != 0 { |
|
return false |
|
} |
|
|
|
ai, aj := sizes.Alignof(ti), sizes.Alignof(tj) |
|
if ai != aj { |
|
return ai > aj |
|
} |
|
|
|
if si != sj { |
|
return si > sj |
|
} |
|
|
|
return false |
|
}) |
why sort by <align of field, size of field> can minimize the sizeof struct?
is there some formal prove?
structslop/structslop.go
Lines 246 to 267 in 13637e2
why sort by <align of field, size of field> can minimize the sizeof struct?
is there some formal prove?