Skip to content

Commit e13fc4a

Browse files
fix: use memset in bitset_set and bitset_clear
1 parent 09e1c03 commit e13fc4a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

buddy_alloc.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,8 +2066,11 @@ static void bitset_set_range(unsigned char *bitset, struct bitset_range range) {
20662066
} else {
20672067
bitset[range.from_bucket] |= bitset_char_mask[range.from_index][7];
20682068
bitset[range.to_bucket] |= bitset_char_mask[0][range.to_index];
2069-
while(++range.from_bucket != range.to_bucket) {
2070-
bitset[range.from_bucket] = 255u;
2069+
2070+
range.from_bucket++;
2071+
2072+
if (range.to_bucket - range.from_bucket > 0) {
2073+
memset(bitset + range.from_bucket, 255u,range.to_bucket - range.from_bucket);
20712074
}
20722075
}
20732076
}
@@ -2079,8 +2082,11 @@ static void bitset_clear_range(unsigned char* bitset, struct bitset_range range)
20792082
else {
20802083
bitset[range.from_bucket] &= ~bitset_char_mask[range.from_index][7];
20812084
bitset[range.to_bucket] &= ~bitset_char_mask[0][range.to_index];
2082-
while (++range.from_bucket != range.to_bucket) {
2083-
bitset[range.from_bucket] = 0;
2085+
2086+
range.from_bucket++;
2087+
2088+
if (range.to_bucket - range.from_bucket > 0) {
2089+
memset(bitset + range.from_bucket, 0,range.to_bucket - range.from_bucket);
20842090
}
20852091
}
20862092
}

0 commit comments

Comments
 (0)