From 5f849b2060f0539db1da327bfb43a86c8f2cb02d Mon Sep 17 00:00:00 2001 From: yunusey Date: Sun, 1 Jun 2025 20:01:28 -0400 Subject: [PATCH] Avoid unnecessary memory allocation and redundant checks --- src/renderer/OpenGL.zig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index fe8a7c1ce..ce3db9644 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -1236,15 +1236,13 @@ pub fn prepBackgroundImage(self: *OpenGL, path: []const u8) !void { return error.InvalidData; } }; - defer self.alloc.free(decoded_image.data); + errdefer self.alloc.free(decoded_image.data); // Copy the data into the pending state - const data = try self.alloc.dupe(u8, decoded_image.data); - errdefer self.alloc.free(data); const pending: Image.Pending = .{ .width = decoded_image.width, .height = decoded_image.height, - .data = data.ptr, + .data = @constCast(decoded_image.data).ptr, }; // Store the image @@ -1253,7 +1251,6 @@ pub fn prepBackgroundImage(self: *OpenGL, path: []const u8) !void { /// Reads the content of the given image path and returns it pub fn readImageContent(self: *OpenGL, path: []const u8) ![]u8 { - assert(std.fs.path.isAbsolute(path)); // Open the file var file = std.fs.openFileAbsolute(path, .{}) catch |err| { log.warn("failed to open file {s}: {}", .{ path, err });