MCPcopy
hub / github.com/tinylib/msgp / resizeSliceNoNil

Method resizeSliceNoNil

gen/spec.go:470–474  ·  view source on GitHub ↗

resizeSliceNoNil will resize a slice and will not allow nil slices.

(size string, s *Slice)

Source from the content-addressed store, hash-verified

468
469// resizeSliceNoNil will resize a slice and will not allow nil slices.
470func (p *printer) resizeSliceNoNil(size string, s *Slice) {
471 p.printf("\nif %[1]s != nil && cap(%[1]s) >= int(%[2]s) {", s.Varname(), size)
472 p.printf("\n%[1]s = (%[1]s)[:%[2]s]", s.Varname(), size)
473 p.printf("\n} else { %[1]s = make(%[3]s, %[2]s) }", s.Varname(), size, s.TypeName())
474}
475
476func (p *printer) arrayCheck(want string, got string) {
477 p.printf("\nif %[1]s != %[2]s { err = msgp.ArrayError{Wanted: %[2]s, Got: %[1]s}; return }", got, want)

Callers 2

gSliceMethod · 0.80
gSliceMethod · 0.80

Calls 3

printfMethod · 0.95
VarnameMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected