asaskevich / govalidator

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

`IsHash()` is highly inefficient #492

Open junyer opened 11 months ago

junyer commented 11 months 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.