(a, b super.Value, nullsMax bool)
| 144 | } |
| 145 | |
| 146 | func compareValues(a, b super.Value, nullsMax bool) int { |
| 147 | a = a.Under() |
| 148 | b = b.Under() |
| 149 | // Handle nulls according to nullsMax |
| 150 | nullA := a.IsNull() |
| 151 | nullB := b.IsNull() |
| 152 | if nullA && nullB { |
| 153 | return 0 |
| 154 | } |
| 155 | if nullA { |
| 156 | if nullsMax { |
| 157 | return 1 |
| 158 | } else { |
| 159 | return -1 |
| 160 | } |
| 161 | } |
| 162 | if nullB { |
| 163 | if nullsMax { |
| 164 | return -1 |
| 165 | } else { |
| 166 | return 1 |
| 167 | } |
| 168 | } |
| 169 | switch aid, bid := a.Type().ID(), b.Type().ID(); { |
| 170 | case super.IsNumber(aid) && super.IsNumber(bid): |
| 171 | return compareNumbers(a, b, aid, bid) |
| 172 | case aid != bid: |
| 173 | return super.CompareTypes(a.Type(), b.Type()) |
| 174 | case aid == super.IDBool: |
| 175 | if av, bv := a.Bool(), b.Bool(); av == bv { |
| 176 | return 0 |
| 177 | } else if av { |
| 178 | return 1 |
| 179 | } |
| 180 | return -1 |
| 181 | case aid == super.IDBytes: |
| 182 | return bytes.Compare(super.DecodeBytes(a.Bytes()), super.DecodeBytes(b.Bytes())) |
| 183 | case aid == super.IDString: |
| 184 | return cmp.Compare(super.DecodeString(a.Bytes()), super.DecodeString(b.Bytes())) |
| 185 | case aid == super.IDIP: |
| 186 | return super.DecodeIP(a.Bytes()).Compare(super.DecodeIP(b.Bytes())) |
| 187 | case aid == super.IDType: |
| 188 | sctx := super.NewContext() // XXX This is expensive. |
| 189 | // XXX This isn't cheap eventually we should add |
| 190 | // super.CompareTypeValues(a, b scode.Bytes). |
| 191 | av, _ := sctx.DecodeTypeValue(a.Bytes()) |
| 192 | bv, _ := sctx.DecodeTypeValue(b.Bytes()) |
| 193 | return super.CompareTypes(av, bv) |
| 194 | } |
| 195 | // XXX record support easy to add here if we moved the creation of the |
| 196 | // field resolvers into this package. |
| 197 | if innerType := super.InnerType(a.Type()); innerType != nil { |
| 198 | ait, bit := a.ContainerIter(), b.ContainerIter() |
| 199 | for { |
| 200 | if ait.Done() { |
| 201 | if bit.Done() { |
| 202 | return 0 |
| 203 | } |
no test coverage detected