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