Speedup digest validation by avoiding regex (#639)

* Speedup digest validation by avoiding regex.

Using a simple loop to check for hex characters is ~14x faster on my
machine than using a regex.

```bash
$ GOTOOLCHAIN=go1.20.7 go test -run='^$' -bench=. -count=10 ./go/pkg/digest > ~/bench.txt

$ cat ~/bench.txt
goos: linux
goarch: amd64
pkg: github.com/bazelbuild/remote-apis-sdks/go/pkg/digest
cpu: AMD Ryzen 9 9950X3D 16-Core Processor
BenchmarkIsHex-32               42152578                29.57 ns/op
BenchmarkIsHex-32               41104626                29.80 ns/op
BenchmarkIsHex-32               40768939                29.43 ns/op
BenchmarkIsHex-32               38164249                29.78 ns/op
BenchmarkIsHex-32               41709770                29.62 ns/op
BenchmarkIsHex-32               36868351                30.04 ns/op
BenchmarkIsHex-32               41430778                29.11 ns/op
BenchmarkIsHex-32               40080670                29.34 ns/op
BenchmarkIsHex-32               42535590                29.54 ns/op
BenchmarkIsHex-32               39850868                29.71 ns/op
BenchmarkHexStringRegex-32       2697667               444.3 ns/op
BenchmarkHexStringRegex-32       2686531               444.9 ns/op
BenchmarkHexStringRegex-32       2718772               442.0 ns/op
BenchmarkHexStringRegex-32       2680062               441.6 ns/op
BenchmarkHexStringRegex-32       2707995               440.6 ns/op
BenchmarkHexStringRegex-32       2725570               443.0 ns/op
BenchmarkHexStringRegex-32       2723361               440.8 ns/op
BenchmarkHexStringRegex-32       2716153               441.3 ns/op
BenchmarkHexStringRegex-32       2707498               441.0 ns/op
BenchmarkHexStringRegex-32       2658169               443.4 ns/op
PASS
ok      github.com/bazelbuild/remote-apis-sdks/go/pkg/digest    28.745s

$ benchstat -col .name ~/bench.txt
goos: linux
goarch: amd64
pkg: github.com/bazelbuild/remote-apis-sdks/go/pkg/digest
cpu: AMD Ryzen 9 9950X3D 16-Core Processor
     │    IsHex    │             HexStringRegex             │
     │   sec/op    │    sec/op     vs base                  │
*-32   29.59n ± 1%   441.80n ± 1%  +1392.82% (p=0.000 n=10)
```

* Use bentekkie@'s suggested variant, which is more readable and has similar performance
2 files changed
tree: 78d500b1027549297667952fa715d8b7701ac9c4
  1. .bazelci/
  2. .githooks/
  3. .github/
  4. external/
  5. go/
  6. .bazelversion
  7. .gitignore
  8. .golangci.yml
  9. AUTHORS
  10. BUILD.bazel
  11. check-gofmt.sh
  12. check-golint.sh
  13. CONTRIBUTING.md
  14. CONTRIBUTORS
  15. go.mod
  16. go.sum
  17. go_deps.bzl
  18. LICENSE
  19. README.md
  20. setup-githooks.sh
  21. WORKSPACE
README.md

Remote Execution API SDKs

CI status: Build Status

PkgGoDev

This repository contains SDKs for the Remote Execution API.

See each language subdirectory's README.md for more specific instructions on using the SDK for that language.