forked from mirrors/tar-split
tar/storage: switch to map[string]struct{} for set
Using an empty struct is more idiomatic/efficient for representing a set-like container.
This commit is contained in:
parent
002d19f0b0
commit
caf6a872c9
1 changed files with 3 additions and 7 deletions
|
@ -65,7 +65,7 @@ func (jup *jsonUnpacker) Next() (*Entry, error) {
|
||||||
if _, ok := jup.seen[cName]; ok {
|
if _, ok := jup.seen[cName]; ok {
|
||||||
return nil, ErrDuplicatePath
|
return nil, ErrDuplicatePath
|
||||||
}
|
}
|
||||||
jup.seen[cName] = emptyByte
|
jup.seen[cName] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &e, err
|
return &e, err
|
||||||
|
@ -90,11 +90,7 @@ type jsonPacker struct {
|
||||||
seen seenNames
|
seen seenNames
|
||||||
}
|
}
|
||||||
|
|
||||||
type seenNames map[string]byte
|
type seenNames map[string]struct{}
|
||||||
|
|
||||||
// used in the seenNames map. byte is a uint8, and we'll re-use the same one
|
|
||||||
// for minimalism.
|
|
||||||
const emptyByte byte = 0
|
|
||||||
|
|
||||||
func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
||||||
// check early for dup name
|
// check early for dup name
|
||||||
|
@ -103,7 +99,7 @@ func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
||||||
if _, ok := jp.seen[cName]; ok {
|
if _, ok := jp.seen[cName]; ok {
|
||||||
return -1, ErrDuplicatePath
|
return -1, ErrDuplicatePath
|
||||||
}
|
}
|
||||||
jp.seen[cName] = emptyByte
|
jp.seen[cName] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Position = jp.pos
|
e.Position = jp.pos
|
||||||
|
|
Loading…
Reference in a new issue