Skip to content

Commit

Permalink
remove dead code - hashOneofFields not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Jun 21, 2023
1 parent b7335d2 commit e04dd43
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ func (h *hasher) hashMessage(msg protoreflect.Message) ([]byte, error) {
}
hashes = append(hashes, fieldHashes...)

// keeping this dead code here to remind myself that the hashFields code
// already deals with oneofs, we don't need additional separate handling of oneofs.
if false {
oneofHashes, err := h.hashOneofs(msg, md.Oneofs())
if err != nil {
return nil, fmt.Errorf("hashing oneofs: %w", err)
}
hashes = append(hashes, oneofHashes...)
}

sort.Slice(hashes, func(i, j int) bool {
return hashes[i].number < hashes[j].number
})
Expand All @@ -97,28 +87,6 @@ func (h *hasher) hashMessage(msg protoreflect.Message) ([]byte, error) {
return hash(identifier, buf.Bytes())
}

func (h *hasher) hashOneofs(msg protoreflect.Message, oneofs protoreflect.OneofDescriptors) ([]*fieldHashEntry, error) {
var hashes []*fieldHashEntry

for i := 0; i < oneofs.Len(); i++ {
od := oneofs.Get(i)
fd := msg.WhichOneof(od)
if fd == nil {
continue
}
if !msg.Has(fd) {
continue
}
hash, err := h.hashField(fd, msg.Get(fd))
if err != nil {
return nil, fmt.Errorf("hashing oneof field %s: %w", od.FullName(), err)
}
hashes = append(hashes, hash)
}

return hashes, nil
}

func (h *hasher) hashFields(msg protoreflect.Message, fields protoreflect.FieldDescriptors) ([]*fieldHashEntry, error) {
hashes := make([]*fieldHashEntry, 0, fields.Len())

Expand Down

0 comments on commit e04dd43

Please sign in to comment.