newValuesSorter initializes a valuesSorter instance, which holds a set of surrogate keys on which the data should be sorted. It uses flags in ConfigState to decide if and how to populate those surrogate keys.
(values []reflect.Value, cs *ConfigState)
| 226 | // surrogate keys on which the data should be sorted. It uses flags in |
| 227 | // ConfigState to decide if and how to populate those surrogate keys. |
| 228 | func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { |
| 229 | vs := &valuesSorter{values: values, cs: cs} |
| 230 | if canSortSimply(vs.values[0].Kind()) { |
| 231 | return vs |
| 232 | } |
| 233 | if !cs.DisableMethods { |
| 234 | vs.strings = make([]string, len(values)) |
| 235 | for i := range vs.values { |
| 236 | b := bytes.Buffer{} |
| 237 | if !handleMethods(cs, &b, vs.values[i]) { |
| 238 | vs.strings = nil |
| 239 | break |
| 240 | } |
| 241 | vs.strings[i] = b.String() |
| 242 | } |
| 243 | } |
| 244 | if vs.strings == nil && cs.SpewKeys { |
| 245 | vs.strings = make([]string, len(values)) |
| 246 | for i := range vs.values { |
| 247 | vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) |
| 248 | } |
| 249 | } |
| 250 | return vs |
| 251 | } |
| 252 | |
| 253 | // canSortSimply tests whether a reflect.Kind is a primitive that can be sorted |
| 254 | // directly, or whether it should be considered for sorting by surrogate keys |
no test coverage detected
searching dependent graphs…