this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

irc: heap allocate Channel

+12 -9
+2 -2
src/app.zig
··· 959 959 var i: usize = 0; 960 960 for (self.clients.items) |client| { 961 961 i += 1; 962 - for (client.channels.items) |*channel| { 962 + for (client.channels.items) |channel| { 963 963 if (cl == client) { 964 964 if (std.mem.eql(u8, name, channel.name)) { 965 965 self.state.buffers.selected_idx = i; ··· 1131 1131 for (self.clients.items) |client| { 1132 1132 if (i == self.state.buffers.selected_idx) return .{ .client = client }; 1133 1133 i += 1; 1134 - for (client.channels.items) |*channel| { 1134 + for (client.channels.items) |channel| { 1135 1135 if (i == self.state.buffers.selected_idx) return .{ .channel = channel }; 1136 1136 i += 1; 1137 1137 }
+10 -7
src/irc.zig
··· 144 144 self.messages.deinit(); 145 145 } 146 146 147 - pub fn compare(_: void, lhs: Channel, rhs: Channel) bool { 147 + pub fn compare(_: void, lhs: *Channel, rhs: *Channel) bool { 148 148 return std.ascii.orderIgnoreCase(lhs.name, rhs.name).compare(std.math.CompareOperator.lt); 149 149 } 150 150 ··· 483 483 stream: std.net.Stream, 484 484 config: Config, 485 485 486 - channels: std.ArrayList(Channel), 486 + channels: std.ArrayList(*Channel), 487 487 users: std.StringHashMap(*User), 488 488 489 489 should_close: bool = false, ··· 516 516 .client = undefined, 517 517 .stream = undefined, 518 518 .config = cfg, 519 - .channels = std.ArrayList(Channel).init(alloc), 519 + .channels = std.ArrayList(*Channel).init(alloc), 520 520 .users = std.StringHashMap(*User).init(alloc), 521 521 .batches = std.StringHashMap(*Channel).init(alloc), 522 522 .write_queue = wq, ··· 545 545 546 546 for (self.channels.items) |channel| { 547 547 channel.deinit(self.alloc); 548 + self.alloc.destroy(channel); 548 549 } 549 550 self.channels.deinit(); 550 551 ··· 936 937 var chan = client.channels.orderedRemove(i); 937 938 self.app.state.buffers.selected_idx -|= 1; 938 939 chan.deinit(self.app.alloc); 940 + self.alloc.destroy(chan); 939 941 break; 940 942 } 941 943 } else { ··· 1213 1215 } 1214 1216 1215 1217 pub fn getOrCreateChannel(self: *Client, name: []const u8) !*Channel { 1216 - for (self.channels.items) |*channel| { 1218 + for (self.channels.items) |channel| { 1217 1219 if (caseFold(name, channel.name)) return channel; 1218 1220 } 1219 - const channel: Channel = .{ 1221 + const channel = try self.alloc.create(Channel); 1222 + channel.* = .{ 1220 1223 .name = try self.alloc.dupe(u8, name), 1221 1224 .members = std.ArrayList(Channel.Member).init(self.alloc), 1222 1225 .messages = std.ArrayList(Message).init(self.alloc), ··· 1224 1227 }; 1225 1228 try self.channels.append(channel); 1226 1229 1227 - std.sort.insertion(Channel, self.channels.items, {}, Channel.compare); 1228 - return self.getOrCreateChannel(name); 1230 + std.sort.insertion(*Channel, self.channels.items, {}, Channel.compare); 1231 + return channel; 1229 1232 } 1230 1233 1231 1234 var color_indices = [_]u8{ 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14 };