asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.05k stars 555 forks source link

`IsHash()` is highly inefficient #492

Open junyer opened 1 year ago

junyer commented 1 year ago

https://github.com/asaskevich/govalidator/blob/a9d515a09cc289c60d55064edec5ef189859f172/validator.go#L708

Currently, IsHash() parses, compiles and matches a regular expression each time, which is highly inefficient in terms of CPU and RAM. Instead, it should check the length of str and then iterate over str to check the digits, which will be a lot faster and won't allocate any memory at all.