From cb382fa87376061e77d6a875cd2ebd7f128def9f Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Tue, 23 Jun 2015 13:13:54 -0700 Subject: [PATCH] tar/storage: switch to map[string]struct{} for set Using an empty struct is more idiomatic/efficient for representing a set-like container. --- tar/storage/packer.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tar/storage/packer.go b/tar/storage/packer.go index d750110..580f716 100644 --- a/tar/storage/packer.go +++ b/tar/storage/packer.go @@ -65,7 +65,7 @@ func (jup *jsonUnpacker) Next() (*Entry, error) { if _, ok := jup.seen[cName]; ok { return nil, ErrDuplicatePath } - jup.seen[cName] = emptyByte + jup.seen[cName] = struct{}{} } return &e, err @@ -90,11 +90,7 @@ type jsonPacker struct { seen seenNames } -type seenNames map[string]byte - -// used in the seenNames map. byte is a uint8, and we'll re-use the same one -// for minimalism. -const emptyByte byte = 0 +type seenNames map[string]struct{} func (jp *jsonPacker) AddEntry(e Entry) (int, error) { // check early for dup name @@ -103,7 +99,7 @@ func (jp *jsonPacker) AddEntry(e Entry) (int, error) { if _, ok := jp.seen[cName]; ok { return -1, ErrDuplicatePath } - jp.seen[cName] = emptyByte + jp.seen[cName] = struct{}{} } e.Position = jp.pos