MCPcopy
hub / github.com/expr-lang/expr / newValuesSorter

Function newValuesSorter

internal/spew/common.go:228–251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
228func 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

Callers 1

sortValuesFunction · 0.85

Calls 4

canSortSimplyFunction · 0.85
handleMethodsFunction · 0.85
SprintfFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…