Skip to content

Commit 6260982

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

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

replication/row_event.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,19 @@ 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; {
625+
if e.IsNumericColumn(i) {
626+
ret[i] = field&byte(c) != 0
627+
c >>= 1
628+
}
629+
i++
630+
if i >= int(e.ColumnCount) {
631+
return ret
632+
}
626633
}
627-
ret[i] = e.SignednessBitmap[p/8]&(1<<uint(7-p%8)) != 0
628-
p++
629634
}
630635
return ret
631636
}
@@ -747,11 +752,16 @@ 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
}
756766
return ret
757767
}

0 commit comments

Comments
 (0)