authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2019-06-09 22:20:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 16:42:39-04:00
log05e92a51aaaacd0bf326e251763ab97da3d0cd18
tree928b5837a14bb9622bbdf9677fba9f6ca04a566f
parent12b2950bf294b3cfda0616b2e71b739cbda684d9

Use std.math.isPowerOfTwo across std lib


3 files changed, 3 insertions(+), 4 deletions(-)

std/hash_map.zig+1-2
...@@ -157,8 +157,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -157,8 +157,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
157 fn ensureCapacityExact(self: *Self, new_capacity: usize) !void {157 fn ensureCapacityExact(self: *Self, new_capacity: usize) !void {
158 // capacity must always be a power of two to allow for modulo158 // capacity must always be a power of two to allow for modulo
159 // optimization in the constrainIndex fn159 // optimization in the constrainIndex fn
160 const is_power_of_two = new_capacity & (new_capacity - 1) == 0;160 assert(math.isPowerOfTwo(new_capacity));
161 assert(is_power_of_two);
162161
163 if (new_capacity <= self.entries.len) {162 if (new_capacity <= self.entries.len) {
164 return;163 return;
std/math/big/int.zig+1-1
...@@ -447,7 +447,7 @@ pub const Int = struct {...@@ -447,7 +447,7 @@ pub const Int = struct {
447 }447 }
448448
449 // Power of two: can do a single pass and use masks to extract digits.449 // Power of two: can do a single pass and use masks to extract digits.
450 if (base & (base - 1) == 0) {450 if (math.isPowerOfTwo(base)) {
451 const base_shift = math.log2_int(Limb, base);451 const base_shift = math.log2_int(Limb, base);
452452
453 for (self.limbs[0..self.len()]) |limb| {453 for (self.limbs[0..self.len()]) |limb| {
std/segmented_list.zig+1-1
...@@ -80,9 +80,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -80,9 +80,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
80 const prealloc_exp = blk: {80 const prealloc_exp = blk: {
81 // we don't use the prealloc_exp constant when prealloc_item_count is 0.81 // we don't use the prealloc_exp constant when prealloc_item_count is 0.
82 assert(prealloc_item_count != 0);82 assert(prealloc_item_count != 0);
83 assert(std.math.isPowerOfTwo(prealloc_item_count));
8384
84 const value = std.math.log2_int(usize, prealloc_item_count);85 const value = std.math.log2_int(usize, prealloc_item_count);
85 assert((1 << value) == prealloc_item_count); // prealloc_item_count must be a power of 2
86 break :blk @typeOf(1)(value);86 break :blk @typeOf(1)(value);
87 };87 };
88 const ShelfIndex = std.math.Log2Int(usize);88 const ShelfIndex = std.math.Log2Int(usize);