func (b *Buffer) String() string {
	var buf strings.Builder
	b.FormatToString(&buf)
	return buf.String()
}
String returns a string representation of the tags.
package logtags
import (
	"fmt"
	"strings"
)
const staticSlots = 4
type Buffer struct {
	tags     []Tag
	prealloc [staticSlots]Tag
}
func SingleTagBuffer(key string, value interface{}) *Buffer {
	b := &Buffer{}
	b.init(1, 1)
	b.tags[0] = Tag{key: key, value: value}
	return b
}
func (b *Buffer) Get() []Tag {
	return b.tags
}
func (b *Buffer) Add(key string, value interface{}) *Buffer {
	if b == nil {
		return SingleTagBuffer(key, value)
	}
	res := &Buffer{}
	res.init(len(b.tags), len(b.tags)+1)
	copy(res.tags, b.tags)
	res.addOrReplace(key, value)
	return res
}
func (b *Buffer) Merge(other *Buffer) *Buffer {
	if b == nil || len(b.tags) == 0 {
		return other
	}
	if len(other.tags) == 0 {
		return b
	}
	if diff := len(other.tags) - len(b.tags); diff >= 0 {
		i, j := 0, 0
		for i < len(b.tags) && j-i <= diff {
			if b.tags[i].key == other.tags[j].key {
				i++
			}
			j++
		}
		if i == len(b.tags) {
			return other
		}
	}
	i := 0
	for ; i < len(other.tags); i++ {
		idx := b.find(other.tags[i].key)
		if idx == -1 || b.tags[idx].value != other.tags[i].value {
			break
		}
	}
	if i == len(other.tags) {
		return b
	}
	res := &Buffer{}
	res.init(len(b.tags), len(b.tags)+len(other.tags)-i)
	copy(res.tags, b.tags)
	for ; i < len(other.tags); i++ {
		res.addOrReplace(other.tags[i].key, other.tags[i].value)
	}
	return res
}