| ... | ... | @@ -65,7 +65,7 @@ pub fn LinearFifo(comptime T: type) type { |
| 65 | 65 | pub fn ensureTotalCapacity(self: *Self, size: usize) !void { |
| 66 | 66 | if (self.buf.len >= size) return; |
| 67 | 67 | self.realign(); |
| 68 | | const new_size = if (true) math.ceilPowerOfTwo(usize, size) catch return error.OutOfMemory else size; |
| 68 | const new_size = math.ceilPowerOfTwo(usize, size) catch return error.OutOfMemory; |
| 69 | 69 | self.buf = try self.allocator.realloc(self.buf, new_size); |
| 70 | 70 | } |
| 71 | 71 | |
| ... | ... | @@ -126,21 +126,12 @@ pub fn LinearFifo(comptime T: type) type { |
| 126 | 126 | @memset(unused2, undefined); |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | | if (false and self.count == count) { |
| 130 | | self.head = 0; |
| 131 | | self.count = 0; |
| 132 | | } else { |
| 133 | | var head = self.head + count; |
| 134 | | if (true) { |
| 135 | | // Note it is safe to do a wrapping subtract as |
| 136 | | // bitwise & with all 1s is a noop |
| 137 | | head &= self.buf.len -% 1; |
| 138 | | } else { |
| 139 | | head %= self.buf.len; |
| 140 | | } |
| 141 | | self.head = head; |
| 142 | | self.count -= count; |
| 143 | | } |
| 129 | var head = self.head + count; |
| 130 | // Note it is safe to do a wrapping subtract as |
| 131 | // bitwise & with all 1s is a noop |
| 132 | head &= self.buf.len -% 1; |
| 133 | self.head = head; |
| 134 | self.count -= count; |
| 144 | 135 | } |
| 145 | 136 | |
| 146 | 137 | /// Read the next item from the fifo |
| ... | ... | @@ -270,11 +261,7 @@ pub fn LinearFifo(comptime T: type) type { |
| 270 | 261 | |
| 271 | 262 | pub fn writeItemAssumeCapacity(self: *Self, item: T) void { |
| 272 | 263 | var tail = self.head + self.count; |
| 273 | | if (true) { |
| 274 | | tail &= self.buf.len - 1; |
| 275 | | } else { |
| 276 | | tail %= self.buf.len; |
| 277 | | } |
| 264 | tail &= self.buf.len - 1; |
| 278 | 265 | self.buf[tail] = item; |
| 279 | 266 | self.update(1); |
| 280 | 267 | } |
| ... | ... | @@ -333,11 +320,7 @@ pub fn LinearFifo(comptime T: type) type { |
| 333 | 320 | assert(self.writableLength() >= count); |
| 334 | 321 | |
| 335 | 322 | var head = self.head + (self.buf.len - count); |
| 336 | | if (true) { |
| 337 | | head &= self.buf.len - 1; |
| 338 | | } else { |
| 339 | | head %= self.buf.len; |
| 340 | | } |
| 323 | head &= self.buf.len - 1; |
| 341 | 324 | self.head = head; |
| 342 | 325 | self.count += count; |
| 343 | 326 | } |
| ... | ... | @@ -364,11 +347,7 @@ pub fn LinearFifo(comptime T: type) type { |
| 364 | 347 | assert(offset < self.count); |
| 365 | 348 | |
| 366 | 349 | var index = self.head + offset; |
| 367 | | if (true) { |
| 368 | | index &= self.buf.len - 1; |
| 369 | | } else { |
| 370 | | index %= self.buf.len; |
| 371 | | } |
| 350 | index &= self.buf.len - 1; |
| 372 | 351 | return self.buf[index]; |
| 373 | 352 | } |
| 374 | 353 | |