From 0b7843db6cd4ecce1351384ed8c4e10d77b3fb72 Mon Sep 17 00:00:00 2001 From: Billy Yip Date: Thu, 19 Aug 2021 22:19:30 +0800 Subject: [PATCH] refactor: todo comment and align coding style --- golang/internal/mathx/mathx.go | 2 +- golang/qrcodegen.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/golang/internal/mathx/mathx.go b/golang/internal/mathx/mathx.go index 44e8ea6..3e3502c 100644 --- a/golang/internal/mathx/mathx.go +++ b/golang/internal/mathx/mathx.go @@ -32,7 +32,7 @@ func AbsInt32(x int32) int32 { return x } -func BoolToUint8(b bool) uint8 { +func BoolToUint(b bool) uint { if b { return 1 } else { diff --git a/golang/qrcodegen.go b/golang/qrcodegen.go index 07c25a6..b649e2b 100644 --- a/golang/qrcodegen.go +++ b/golang/qrcodegen.go @@ -234,7 +234,7 @@ Donepad: // Pack bits into bytes in big endian datacodewords := make([]uint8, len(bb)/8) for i, bit := range bb { - datacodewords[i>>3] |= mathx.BoolToUint8(bit) << (7 - (i & 7)) + datacodewords[i>>3] |= uint8(mathx.BoolToUint(bit)) << (7 - (i & 7)) } // Create the QR Code object @@ -330,8 +330,8 @@ func (q QrCode) module(x, y int32) bool { return q.modules[uint(y*q.size+x)] } -// TODO: refactor to match closer to the semantics of rust counterpart // Returns a mutable reference to the module's color at the given coordinates, which must be in bounds. +// TODO: refactor to match closer to the semantics of rust counterpart, expose &bool instead? func (q *QrCode) moduleMut(x, y int32, mut bool) { q.modules[uint(y*q.size+x)] = mut } @@ -496,7 +496,7 @@ func (q *QrCode) addEccAndInterleave(data []uint8) []uint8 { var k uint for i, max := uint(0), numblocks; i < max; i++ { - datlen := shortblocklen - blockecclen + uint(mathx.BoolToUint8(i >= numshortblocks)) + datlen := shortblocklen - blockecclen + mathx.BoolToUint(i >= numshortblocks) dat := make([]uint8, datlen) _ = copy(dat, data[k:k+datlen]) k += datlen @@ -592,6 +592,7 @@ func (q *QrCode) applyMask(mask Mask) { default: panic("unreachable") } + // TODO: refactor to match closer to the semantics of rust counterpart, ^= operator alternative newModule := q.module(x, y) != (invert && !q.isfunction[(y*q.size+x)]) q.moduleMut(x, y, newModule) }