zigmod
zigmod copied to clipboard
Detect license hang for a long time
How to reproduce:
- Create a new directory
- Download https://gist.github.com/locriacyber/100837526561cc6b7f508868cfd33780 as
LICENSE zig init-exezigmod init
The process will hang for a long time.
I found the reason. Zig detect license gets the levenstein distance of the entire file (1KB).
pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
var min: ?usize = null;
var ind: ?usize = null;
for (licenses.spdx) |item, i| {
const distance = try leven.leven(u8, alloc, license_src, item[1], min);
if (min == null or distance < min.?) {
min = distance;
ind = i;
}
}
return licenses.spdx[ind.?][0];
}