<code>
// GroupValue returns a new Value for a list of Attrs.
// The caller must not subsequently mutate the argument slice.
func GroupValue(as ...Attr) Value {
// Remove empty groups.
// It is simpler overall to do this at construction than
// to check each Group recursively for emptiness.
var write int
for read := range as {
if as[read].isEmptyGroup() {
as[read] = Attr{} // no need to keep a reference to the string Key
} else {
if read != write {
as[write] = as[read]
}
write++
}
}
as = as[:write]
return Value{num: uint64(len(as)), any: groupptr(unsage.SliceData(as))}
}
</code>
This, considering that the documentation of the func already states that the user must not mutate the argument slice, so not only the elements but the whole slice could be reused.
In the case of having lots of attributes with empty group elements, then the stored slice will be unnecessarily larger by that number of Attr elements, but I wonder if that would be negligible, probably an edge case of misuse.
Kind regards.