Skip to content

Commit 5c5cc21

Browse files
author
Dean Karn
authored
refactor NanoTime because of upcoming Go1.23 breaking changes (#53)
Go1.23 is going to introduce `BREAKING CHANGES!` to `go:linkname`, this change is getting ahead of that. Yes maybe the changes don't break the Go1 compatibility guarantee but it is a breaking change and adding a way to opt-out doesn't make it not so. This has been happening a lot in the last few Go releases.
1 parent 80c2604 commit 5c5cc21

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [5.30.0] - 2024-06-01
10+
### Changed
11+
- Changed NanoTome to not use linkname due to Go1.23 upcoming breaking changes.
12+
913
## [5.29.1] - 2024-04-04
1014
### Fixed
1115
- Added HTTP 404 to non retryable status codes.
@@ -132,7 +136,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
132136
### Added
133137
- Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision.
134138

135-
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.29.1...HEAD
139+
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.30.0...HEAD
140+
[5.30.0]: https://github.com/go-playground/pkg/compare/v5.29.1..v5.30.0
136141
[5.29.1]: https://github.com/go-playground/pkg/compare/v5.29.0..v5.29.1
137142
[5.29.0]: https://github.com/go-playground/pkg/compare/v5.28.1..v5.29.0
138143
[5.28.1]: https://github.com/go-playground/pkg/compare/v5.28.0..v5.28.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pkg
22

3-
![Project status](https://img.shields.io/badge/version-5.29.1-green.svg)
3+
![Project status](https://img.shields.io/badge/version-5.30.0-green.svg)
44
[![Lint & Test](https://github.com/go-playground/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/pkg/actions/workflows/go.yml)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master)
66
[![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5)

time/nanotime.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
package timeext
55

66
import (
7-
_ "unsafe"
7+
"time"
88
)
99

10-
//go:noescape
11-
//go:linkname nanotime runtime.nanotime
12-
func nanotime() int64
10+
var base = time.Now()
1311

14-
// NanoTime returns the time from the monotonic clock in nanoseconds.
12+
// NanoTime returns a monotonically increasing time in nanoseconds.
1513
func NanoTime() int64 {
16-
return nanotime()
14+
return int64(time.Since(base))
1715
}

time/nanotime_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestNanoTime(t *testing.T) {
1919

2020
func BenchmarkNanoTime(b *testing.B) {
2121
for i := 0; i < b.N; i++ {
22-
_ = nanotime()
22+
_ = NanoTime()
2323
}
2424
}
2525

0 commit comments

Comments
 (0)