Skip to content

Commit b6b77ba

Browse files
committed
slog: Record methods take value receivers
Change most Record methods to take value receivers, to provide a consistent view of Record as a value type. AddAttrs' receiver is modified so it must remain a pointer. This change did not significantly affect benchmarks. Change-Id: I14763a5043ce8dcd537fa71d28ccc01508b7b35b Reviewed-on: https://go-review.googlesource.com/c/exp/+/439056 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent 9ed1532 commit b6b77ba

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

slog/record.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ func NewRecord(t time.Time, level Level, msg string, calldepth int) Record {
6868
}
6969

7070
// Time returns the time of the log event.
71-
func (r *Record) Time() time.Time { return r.time }
71+
func (r Record) Time() time.Time { return r.time }
7272

7373
// Message returns the log message.
74-
func (r *Record) Message() string { return r.message }
74+
func (r Record) Message() string { return r.message }
7575

7676
// Level returns the level of the log event.
77-
func (r *Record) Level() Level { return r.level }
77+
func (r Record) Level() Level { return r.level }
7878

7979
// SourceLine returns the file and line of the log event.
8080
// If the Record was created without the necessary information,
8181
// or if the location is unavailable, it returns ("", 0).
82-
func (r *Record) SourceLine() (file string, line int) {
82+
func (r Record) SourceLine() (file string, line int) {
8383
fs := runtime.CallersFrames([]uintptr{r.pc})
8484
// TODO: error-checking?
8585
f, _ := fs.Next()
@@ -89,19 +89,18 @@ func (r *Record) SourceLine() (file string, line int) {
8989
// Clone returns a copy of the record with no shared state.
9090
// The original record and the clone can both be modified
9191
// without interfering with each other.
92-
func (r *Record) Clone() Record {
93-
c := *r
94-
c.back = slices.Clip(c.back) // prevent append from mutating shared array
95-
return c
92+
func (r Record) Clone() Record {
93+
r.back = slices.Clip(r.back) // prevent append from mutating shared array
94+
return r
9695
}
9796

9897
// NumAttrs returns the number of attributes in the Record.
99-
func (r *Record) NumAttrs() int {
98+
func (r Record) NumAttrs() int {
10099
return r.nFront + len(r.back)
101100
}
102101

103102
// Attrs calls f on each Attr in the Record.
104-
func (r *Record) Attrs(f func(Attr)) {
103+
func (r Record) Attrs(f func(Attr)) {
105104
for i := 0; i < r.nFront; i++ {
106105
f(r.front[i])
107106
}

0 commit comments

Comments
 (0)