Avoid redundant memory allocations and copies when simpler alternatives exist. This includes: 1. Use in-place comparison functions instead of allocating for string operations
Avoid redundant memory allocations and copies when simpler alternatives exist. This includes:
Example - Instead of:
const ext_lower = try std.ascii.allocLowerString(alloc, ext);
defer alloc.free(ext_lower);
if (std.mem.eql(u8, ext_lower, ".png")) {
Prefer:
if (std.ascii.eqlIgnoreCase(ext, ".png")) {
This guidance helps reduce memory pressure and improve performance by eliminating unnecessary allocations and copies. When working with data structures that handle their own memory management, verify if they copy inputs before performing manual duplication.
Enter the URL of a public GitHub repository