zigmod icon indicating copy to clipboard operation
zigmod copied to clipboard

Detect license hang for a long time

Open iacore opened this issue 4 years ago • 1 comments

How to reproduce:

  1. Create a new directory
  2. Download https://gist.github.com/locriacyber/100837526561cc6b7f508868cfd33780 as LICENSE
  3. zig init-exe
  4. zigmod init

The process will hang for a long time.

iacore avatar Dec 31 '21 13:12 iacore

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];
}

iacore avatar Dec 31 '21 13:12 iacore