Skip to content

Commit 20bf956

Browse files
committed
Refactor bitmap iteration to align with MySQL source code
Changes: - Refactpred `UnsignedMap` - Refactored `VisibilityMap` Suggested by: go-mysql-org#813 (comment)
1 parent ccabd26 commit 20bf956

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

replication/row_event.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (e *TableMapEvent) Dump(w io.Writer) {
427427
fmt.Fprintf(w, "Primary key prefix: %v\n", e.PrimaryKeyPrefix)
428428
fmt.Fprintf(w, "Enum/set default charset: %v\n", e.EnumSetDefaultCharset)
429429
fmt.Fprintf(w, "Enum/set column charset: %v\n", e.EnumSetColumnCharset)
430-
fmt.Fprintf(w, "Invisible Column bitmap: \n%s", hex.Dump(e.VisibilityBitmap))
430+
fmt.Fprintf(w, "Visible Column bitmap: \n%s", hex.Dump(e.VisibilityBitmap))
431431

432432
unsignedMap := e.UnsignedMap()
433433
fmt.Fprintf(w, "UnsignedMap: %#v\n", unsignedMap)
@@ -618,16 +618,21 @@ func (e *TableMapEvent) UnsignedMap() map[int]bool {
618618
if len(e.SignednessBitmap) == 0 {
619619
return nil
620620
}
621-
p := 0
622621
ret := make(map[int]bool)
623-
for i := 0; i < int(e.ColumnCount); i++ {
624-
if !e.IsNumericColumn(i) {
625-
continue
622+
i := 0
623+
for _, field := range e.SignednessBitmap {
624+
for c := 0x80; c != 0; c >>= 1 {
625+
if !e.IsNumericColumn(i) {
626+
continue
627+
}
628+
ret[i] = field&byte(c) != 0
629+
i++
630+
if uint64(i) >= e.ColumnCount {
631+
return ret
632+
}
626633
}
627-
ret[i] = e.SignednessBitmap[p/8]&(1<<uint(7-p%8)) != 0
628-
p++
629634
}
630-
return ret
635+
return nil
631636
}
632637

633638
// CollationMap returns a map: column index -> collation id.
@@ -747,13 +752,18 @@ func (e *TableMapEvent) VisibilityMap() map[int]bool {
747752
if len(e.VisibilityBitmap) == 0 {
748753
return nil
749754
}
750-
p := 0
751755
ret := make(map[int]bool)
752-
for i := 0; i < int(e.ColumnCount); i++ {
753-
ret[i] = e.VisibilityBitmap[p/8]&(1<<uint(7-p%8)) != 0
754-
p++
756+
i := 0
757+
for _, field := range e.VisibilityBitmap {
758+
for c := 0x80; c != 0; c >>= 1 {
759+
ret[i] = field&byte(c) != 0
760+
i++
761+
if uint64(i) >= e.ColumnCount {
762+
return ret
763+
}
764+
}
755765
}
756-
return ret
766+
return nil
757767
}
758768

759769
// Below realType and IsXXXColumn are base from:

0 commit comments

Comments
 (0)