Use sync.OnceValue for lazy regexp initialization
Fixes Or Enhances
Replaces the local lazy initialization implementation with the stdlib sync.OnceValue.
Using sync.OnceValue instead of the local implementation brings some benefits in allocations, panic handling and mutex usage after initialization.
sync.OnceValue was introduced in go1.21 so backwards compatibility is provided via lazy_compat.go and build tags.
Make sure that you've checked the boxes below before you submit PR:
- [X] Tests exist or have been written that cover this particular change.
@go-playground/validator-maintainers
sync.OnceValue was introduced in go1.21, so there has to be two files with buildtags as validator supports older go versions.
coverage: 74.285% (-0.006%) from 74.291% when pulling 2c1e6659ad625ced14afa3798bdad7f2c61d7d38 on kke:sync-oncevalue-regex into a947377040f8ebaee09f20d09a745ec369396793 on go-playground:master.
coverage: 74.285% (-0.006%) from 74.291% when pulling 61e16c9e89e13580119bae96e686f5888068ecf8 on kke:sync-oncevalue-regex into a947377040f8ebaee09f20d09a745ec369396793 on go-playground:master.
coverage: 74.285% (-0.006%) from 74.291% when pulling dac5fe65522bc02695d7cacf05ecaca6e2fb9a85 on kke:sync-oncevalue-regex into a947377040f8ebaee09f20d09a745ec369396793 on go-playground:master.
coverage: 74.285% (-0.006%) from 74.291%
The coverage check does not seem to calculate correctly when files with build tags are involved.