Daniel Morsing
unread,Aug 15, 2012, 8:16:24 AM8/15/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jesse McNelis, Lunix Watt, golan...@googlegroups.com, Vladimir Mihailenco
On Wed, Aug 15, 2012 at 11:03 AM, Jesse McNelis <
jes...@jessta.id.au> wrote:
> Hash.Hash.Sum() appends to the given slice because often the caller
> won't actually know how big to make the slice to fit the hashsum.
> A caller to Read() knows how much they want to read.
>
Sum() taking an argument is actually a bit of a hack.
Originally, the Sum() function only returned a byte slice, but this
caused way too much memory allocation.
The intended use for Sum() is:
var x [hashsize]byte
for _, h := range collection {
result := h.Sum(x[:0])
// use result for something
}
This way, you don't need to allocate a new slice for every call to Sum().
Maybe it would make sense to make Sum() into a Read() when go 2 comes around.
Regards,
Daniel Morsing