Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove superfluous bitmasking in `encode` We only need to mask with `&0x1F` once per generated character, rather than twice as we did in many cases. As long as the `&0x1F` operation is last, we will always throw away the top three bits as expected. * Remove use of `unsafe` in `String()` method Now that an `Encode()` method was added in #56, it is less necessary to resort to unsafe methods in `String()`. This also appears to have minimal benefit, as seen by these before (using unsafe) and after (without unsafe) benchmarks: Before (using unsafe): % go test -benchmem -bench . goos: darwin goarch: arm64 pkg: github.com/rs/xid BenchmarkNew-8 21845306 52.34 ns/op 0 B/op 0 allocs/op BenchmarkNewString-8 22674129 51.18 ns/op 0 B/op 0 allocs/op BenchmarkFromString-8 286217863 4.233 ns/op 0 B/op 0 allocs/op PASS ok github.com/rs/xid 4.142s After (without unsafe): % go test -benchmem -bench . goos: darwin goarch: arm64 pkg: github.com/rs/xid BenchmarkNew-8 21423278 53.01 ns/op 0 B/op 0 allocs/op BenchmarkNewString-8 21977233 53.67 ns/op 0 B/op 0 allocs/op BenchmarkFromString-8 289641164 4.162 ns/op 0 B/op 0 allocs/op PASS ok github.com/rs/xid 4.181s
- Loading branch information