Exemple #1
0
func getBuffer(w io.Writer) *tempBuffer {
	w = getWriter(w)
	// If either is nil, something will eventually panic, so we might as well do it here
	switch w := w.(type) {
	case *bytes.Buffer:
		if w == nil {
			panic("dagr: getBuffer: target *bytes.Buffer is nil")
		}
		return &tempBuffer{w, false, int64(w.Len())}
	}

	if b, ok := tempBuffers.Get().(*tempBuffer); ok {
		return b
	}

	// Bizzaro case: tempBuffers.New didn't work? Something should've panicked by now.
	return allocMinimumBuffer()
}