remove uneccessary alloc from playtwitch

This commit is contained in:
LordMZTE 2022-11-05 13:47:21 +01:00
parent 82a39bf326
commit 7da71e6865
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 6 additions and 13 deletions

View file

@ -23,7 +23,7 @@ chatty: bool,
chatty_alive: bool,
/// an array of channels, composed of slices into `channels_file_data`
channels: ?[]*ChannelEntry,
channels: ?[]ChannelEntry,
/// the data of the channels configuration file
channels_file_data: ?[]u8,
@ -90,9 +90,6 @@ pub fn deinit(self: *Self) void {
self.freeStreamlinkMemfd();
if (self.channels) |ch| {
for (ch) |e| {
std.heap.c_allocator.destroy(e);
}
std.heap.c_allocator.free(ch);
}

View file

@ -26,7 +26,7 @@ pub fn configLoaderThread(state: *State) !void {
defer file.close();
const channels_data = try file.readToEndAlloc(std.heap.c_allocator, std.math.maxInt(usize));
var channels = std.ArrayList(*State.ChannelEntry).init(std.heap.c_allocator);
var channels = std.ArrayList(State.ChannelEntry).init(std.heap.c_allocator);
var channels_iter = std.mem.split(u8, channels_data, "\n");
while (channels_iter.next()) |line| {
@ -49,14 +49,10 @@ pub fn configLoaderThread(state: *State) !void {
break :blk comment_trimmed;
};
const entry = try std.heap.c_allocator.create(State.ChannelEntry);
entry.* = .{
try channels.append(.{
.name = channel_trimmed,
.comment = comment_trimmed,
};
try channels.append(entry);
});
}
const end_time = std.time.milliTimestamp();

View file

@ -8,7 +8,7 @@ pub fn reloadLiveThread(s: *State) !void {
s.mutex.lock();
defer s.mutex.unlock();
for (s.channels.?) |chan| {
for (s.channels.?) |*chan| {
chan.live = .loading;
}
}
@ -45,7 +45,7 @@ pub fn fetchChannelsLive(s: *State) !void {
// we shouldn't need to aquire the mutex here, this data isnt being read and we're
// only doing atomic writes.
var fmt_buf: [512]u8 = undefined;
for (s.channels.?) |chan| {
for (s.channels.?) |*chan| {
page_buf.clearRetainingCapacity();
log.info("requesting live state for channel {s}", .{chan.name});