-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Sum256 and Sum224 no-allocation functions #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good apart from test (see comments)
blake256_test.go
Outdated
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"hash" | ||
"testing" | ||
|
||
"github.com/teknico/blake256" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, sorry, will fix it.
blake256_test.go
Outdated
@@ -5,13 +5,15 @@ | |||
// worldwide. This software is distributed without any warranty. | |||
// http://creativecommons.org/publicdomain/zero/1.0/ | |||
|
|||
package blake256 | |||
package blake256_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't rename please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will revert if you want me to. Care to mention why, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just like the simplicity of it, I guess 🤷♂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this way tests cannot change code internals, which makes them more effective (blackbox vs. whitebox testing, basically). But again, happy to revert if you don't like it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it's a few letters more to type for a theoretical benefit! Reading the code is the best guarantee that it can't change internals :) Whatever, let's do a separate package test if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, then it would have hardcoded package path, so let's not do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, the mistake with import in PR was caused by a having a separate test package, so I guess my kind of testing wins :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you wish.
…nternals anyway" This reverts commit c5d8354 as requested.
Thanks again! |
I just noticed I neglected to mention the two new functions in the README, sorry about that. |
Ah, no worries. I should just like to godoc there instead of listing functions. |
The
New
andSum
methods, part of theHash
stdlib interface, allocate memory on the heap. The stdlibsha256
package uses a different method,Sum256
, that does not allocate memory.This change adds two functions,
Sum256
andSum224
, and optimizes the code so that calling them does not allocate any memory on the heap. The standardNew+Write+Sum
API allocations are also reduced:New tests and benchmarks are also added, and the tests package is made different from the code one. The tests do not need access to code internals anyway.