Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Performance tweak for the Go version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedrosa committed Nov 22, 2011
1 parent 8798704 commit 9379dc4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions luhny.go
Expand Up @@ -33,14 +33,14 @@ func NewLuhn() *Luhn {
return &Luhn{}
}

func (Luhn) TestIt(a []byte, startAt int, maxLen int) bool {
func (Luhn) TestIt(a *[]byte, startAt int, maxLen int) bool {
total := uint8(0)
doubleDigit := false
for i := startAt + maxLen - 1; i >= startAt; i-- {
if doubleDigit {
total += doubleDigits[a[i]]
total += doubleDigits[(*a)[i]]
} else {
total += a[i]
total += (*a)[i]
}
doubleDigit = !doubleDigit
}
Expand All @@ -63,7 +63,7 @@ func (lu Luhn) Mask(s string) string {
if digitCount < 16 { theLen = digitCount }
for ; theLen >= 14; theLen-- {
startAt := digitCount - theLen
if lu.TestIt(digits, startAt, theLen) {
if lu.TestIt(&digits, startAt, theLen) {
if masked == nil { masked = []byte(s) }
j := i
for maskLen := theLen; maskLen > 0; {
Expand Down Expand Up @@ -147,8 +147,7 @@ func (lu Luhn) TapStdin() {

func main() {
// sampleTest()
luhn := NewLuhn()
luhn.TapStdin()
(NewLuhn()).TapStdin()
}


Expand Down

0 comments on commit 9379dc4

Please sign in to comment.