Browse Source

style: make MaxShardCount type casting explicit in loops

Improved code clarity by explicitly casting MaxShardCount to the
appropriate type when used in loop comparisons:

- ShardId comparisons: Cast to ShardId(MaxShardCount)
- uint32 comparisons: Cast to uint32(MaxShardCount)

Changed in 5 locations:
- Minus() loop (line 90)
- ShardIds() loop (line 143)
- ToUint32Slice() loop (line 152)
- IndexToShardId() loop (line 219)
- resizeShardSizes() loop (line 248)

This makes the intent explicit and improves type safety readability.
No functional changes - purely a style improvement.
pull/7396/head
chrislu 2 months ago
parent
commit
14e4fcadd3
  1. 10
      weed/storage/erasure_coding/ec_volume_info.go

10
weed/storage/erasure_coding/ec_volume_info.go

@ -87,7 +87,7 @@ func (ecInfo *EcVolumeInfo) Minus(other *EcVolumeInfo) *EcVolumeInfo {
// Copy shard sizes for remaining shards // Copy shard sizes for remaining shards
retIndex := 0 retIndex := 0
for shardId := ShardId(0); shardId < MaxShardCount && retIndex < len(ret.ShardSizes); shardId++ {
for shardId := ShardId(0); shardId < ShardId(MaxShardCount) && retIndex < len(ret.ShardSizes); shardId++ {
if ret.ShardBits.HasShardId(shardId) { if ret.ShardBits.HasShardId(shardId) {
if size, exists := ecInfo.GetShardSize(shardId); exists { if size, exists := ecInfo.GetShardSize(shardId); exists {
ret.ShardSizes[retIndex] = size ret.ShardSizes[retIndex] = size
@ -140,7 +140,7 @@ func (b ShardBits) HasShardId(id ShardId) bool {
} }
func (b ShardBits) ShardIds() (ret []ShardId) { func (b ShardBits) ShardIds() (ret []ShardId) {
for i := ShardId(0); i < MaxShardCount; i++ {
for i := ShardId(0); i < ShardId(MaxShardCount); i++ {
if b.HasShardId(i) { if b.HasShardId(i) {
ret = append(ret, i) ret = append(ret, i)
} }
@ -149,7 +149,7 @@ func (b ShardBits) ShardIds() (ret []ShardId) {
} }
func (b ShardBits) ToUint32Slice() (ret []uint32) { func (b ShardBits) ToUint32Slice() (ret []uint32) {
for i := uint32(0); i < MaxShardCount; i++ {
for i := uint32(0); i < uint32(MaxShardCount); i++ {
if b.HasShardId(ShardId(i)) { if b.HasShardId(ShardId(i)) {
ret = append(ret, i) ret = append(ret, i)
} }
@ -216,7 +216,7 @@ func (b ShardBits) IndexToShardId(index int) (shardId ShardId, found bool) {
} }
currentIndex := 0 currentIndex := 0
for i := ShardId(0); i < MaxShardCount; i++ {
for i := ShardId(0); i < ShardId(MaxShardCount); i++ {
if b.HasShardId(i) { if b.HasShardId(i) {
if currentIndex == index { if currentIndex == index {
return i, true return i, true
@ -245,7 +245,7 @@ func (ecInfo *EcVolumeInfo) resizeShardSizes(prevShardBits ShardBits) {
// Copy existing sizes to new positions based on current ShardBits // Copy existing sizes to new positions based on current ShardBits
if len(ecInfo.ShardSizes) > 0 { if len(ecInfo.ShardSizes) > 0 {
newIndex := 0 newIndex := 0
for shardId := ShardId(0); shardId < MaxShardCount && newIndex < expectedLength; shardId++ {
for shardId := ShardId(0); shardId < ShardId(MaxShardCount) && newIndex < expectedLength; shardId++ {
if ecInfo.ShardBits.HasShardId(shardId) { if ecInfo.ShardBits.HasShardId(shardId) {
// Try to find the size for this shard in the old array using previous ShardBits // Try to find the size for this shard in the old array using previous ShardBits
if oldIndex, found := prevShardBits.ShardIdToIndex(shardId); found && oldIndex < len(ecInfo.ShardSizes) { if oldIndex, found := prevShardBits.ShardIdToIndex(shardId); found && oldIndex < len(ecInfo.ShardSizes) {

Loading…
Cancel
Save