Skip to content

Commit ba9bb16

Browse files
committed
rename appendString to appendLoggerString
1 parent 70b0e29 commit ba9bb16

2 files changed

Lines changed: 38 additions & 40 deletions

File tree

fastescape.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package log
22

3-
import "unsafe"
4-
53
// simdEscapeThreshold keeps values shorter than two vectors on the scalar path.
64
const simdEscapeThreshold = 31
75

@@ -125,8 +123,8 @@ func appendEscapedString(dst []byte, s string) []byte {
125123
return append(dst, s[j:]...)
126124
}
127125

128-
// appendString appends a string using the scalar escape scan.
129-
func appendString(dst []byte, s string) []byte {
126+
// appendLoggerString appends a string using the scalar escape scan.
127+
func appendLoggerString(dst []byte, s string) []byte {
130128
for _, c := range []byte(s) {
131129
if escapes[c] {
132130
return appendEscapedString(dst, s)
@@ -135,8 +133,8 @@ func appendString(dst []byte, s string) []byte {
135133
return append(dst, s...)
136134
}
137135

138-
// appendBytes appends bytes using the scalar escape scan.
139-
func appendBytes(dst, b []byte) []byte {
136+
// appendLoggerBytes appends bytes using the scalar escape scan.
137+
func appendLoggerBytes(dst, b []byte) []byte {
140138
for _, c := range b {
141139
if escapes[c] {
142140
return appendEscapedBytes(dst, b)
@@ -145,20 +143,18 @@ func appendBytes(dst, b []byte) []byte {
145143
return append(dst, b...)
146144
}
147145

148-
// appendString2 appends a string after the SIMD escape scan.
149-
func appendString2(dst []byte, s string) []byte {
146+
// appendLoggerString2 appends a string after the SIMD escape scan.
147+
func appendLoggerString2(dst []byte, s string) []byte {
150148
if needEscapeSIMD(s) {
151149
return appendEscapedString(dst, s)
152150
}
153151
return append(dst, s...)
154152
}
155153

156-
// appendBytes2 appends bytes after the SIMD escape scan.
157-
func appendBytes2(dst, b []byte) []byte {
154+
// appendLoggerBytes2 appends bytes after the SIMD escape scan.
155+
func appendLoggerBytes2(dst, b []byte) []byte {
158156
if needEscapeSIMD(b2s(b)) {
159157
return appendEscapedBytes(dst, b)
160158
}
161159
return append(dst, b...)
162160
}
163-
164-
func b2s(b []byte) string { return *(*string)(unsafe.Pointer(&b)) }

logger.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,9 @@ func (e *Entry) AnErr(key string, err error) *Entry {
10601060
e.buf = append(e.buf, '"')
10611061
s := err.Error()
10621062
if !hasSIMDEscape || len(s) <= simdEscapeThreshold {
1063-
e.buf = appendString(e.buf, s)
1063+
e.buf = appendLoggerString(e.buf, s)
10641064
} else {
1065-
e.buf = appendString2(e.buf, s)
1065+
e.buf = appendLoggerString2(e.buf, s)
10661066
}
10671067
e.buf = append(e.buf, '"')
10681068
}
@@ -1088,9 +1088,9 @@ func (e *Entry) Errs(key string, errs []error) *Entry {
10881088
e.buf = append(e.buf, '"')
10891089
s := err.Error()
10901090
if !hasSIMDEscape || len(s) <= simdEscapeThreshold {
1091-
e.buf = appendString(e.buf, s)
1091+
e.buf = appendLoggerString(e.buf, s)
10921092
} else {
1093-
e.buf = appendString2(e.buf, s)
1093+
e.buf = appendLoggerString2(e.buf, s)
10941094
}
10951095
e.buf = append(e.buf, '"')
10961096
}
@@ -1562,9 +1562,9 @@ func (e *Entry) Str(key string, val string) *Entry {
15621562
buf = append(buf, key...)
15631563
buf = append(buf, '"', ':', '"')
15641564
if !hasSIMDEscape || len(val) <= simdEscapeThreshold {
1565-
buf = appendString(buf, val)
1565+
buf = appendLoggerString(buf, val)
15661566
} else {
1567-
buf = appendString2(buf, val)
1567+
buf = appendLoggerString2(buf, val)
15681568
}
15691569
buf = append(buf, '"')
15701570
e.buf = buf
@@ -1598,9 +1598,9 @@ func (e *Entry) Stringer(key string, val fmt.Stringer) *Entry {
15981598
e.buf = append(e.buf, '"')
15991599
s := val.String()
16001600
if !hasSIMDEscape || len(s) <= simdEscapeThreshold {
1601-
e.buf = appendString(e.buf, s)
1601+
e.buf = appendLoggerString(e.buf, s)
16021602
} else {
1603-
e.buf = appendString2(e.buf, s)
1603+
e.buf = appendLoggerString2(e.buf, s)
16041604
}
16051605
e.buf = append(e.buf, '"')
16061606
} else {
@@ -1622,9 +1622,9 @@ func (e *Entry) GoStringer(key string, val fmt.GoStringer) *Entry {
16221622
e.buf = append(e.buf, '"')
16231623
s := val.GoString()
16241624
if !hasSIMDEscape || len(s) <= simdEscapeThreshold {
1625-
e.buf = appendString(e.buf, s)
1625+
e.buf = appendLoggerString(e.buf, s)
16261626
} else {
1627-
e.buf = appendString2(e.buf, s)
1627+
e.buf = appendLoggerString2(e.buf, s)
16281628
}
16291629
e.buf = append(e.buf, '"')
16301630
} else {
@@ -1648,9 +1648,9 @@ func (e *Entry) Strs(key string, vals []string) *Entry {
16481648
}
16491649
e.buf = append(e.buf, '"')
16501650
if !hasSIMDEscape || len(val) <= simdEscapeThreshold {
1651-
e.buf = appendString(e.buf, val)
1651+
e.buf = appendLoggerString(e.buf, val)
16521652
} else {
1653-
e.buf = appendString2(e.buf, val)
1653+
e.buf = appendLoggerString2(e.buf, val)
16541654
}
16551655
e.buf = append(e.buf, '"')
16561656
}
@@ -1705,9 +1705,9 @@ func (e *Entry) Bytes(key string, val []byte) *Entry {
17051705
buf = append(buf, key...)
17061706
buf = append(buf, '"', ':', '"')
17071707
if !hasSIMDEscape || len(val) <= simdEscapeThreshold {
1708-
buf = appendBytes(buf, val)
1708+
buf = appendLoggerBytes(buf, val)
17091709
} else {
1710-
buf = appendBytes2(buf, val)
1710+
buf = appendLoggerBytes2(buf, val)
17111711
}
17121712
buf = append(buf, '"')
17131713
e.buf = buf
@@ -1728,9 +1728,9 @@ func (e *Entry) BytesOrNil(key string, val []byte) *Entry {
17281728
} else {
17291729
e.buf = append(e.buf, '"')
17301730
if !hasSIMDEscape || len(val) <= simdEscapeThreshold {
1731-
e.buf = appendBytes(e.buf, val)
1731+
e.buf = appendLoggerBytes(e.buf, val)
17321732
} else {
1733-
e.buf = appendBytes2(e.buf, val)
1733+
e.buf = appendLoggerBytes2(e.buf, val)
17341734
}
17351735
e.buf = append(e.buf, '"')
17361736
}
@@ -1996,9 +1996,9 @@ func (e *Entry) Stack() *Entry {
19961996
e.buf = append(e.buf, "\":\""...)
19971997
b := stacks(false)
19981998
if !hasSIMDEscape || len(b) <= simdEscapeThreshold {
1999-
e.buf = appendBytes(e.buf, b)
1999+
e.buf = appendLoggerBytes(e.buf, b)
20002000
} else {
2001-
e.buf = appendBytes2(e.buf, b)
2001+
e.buf = appendLoggerBytes2(e.buf, b)
20022002
}
20032003
e.buf = append(e.buf, '"')
20042004
return e
@@ -2055,9 +2055,9 @@ func (e *Entry) Msg(msg string) {
20552055
e.buf = append(e.buf, MessageKey...)
20562056
e.buf = append(e.buf, "\":\""...)
20572057
if !hasSIMDEscape || len(msg) <= simdEscapeThreshold {
2058-
e.buf = appendString(e.buf, msg)
2058+
e.buf = appendLoggerString(e.buf, msg)
20592059
} else {
2060-
e.buf = appendString2(e.buf, msg)
2060+
e.buf = appendLoggerString2(e.buf, msg)
20612061
}
20622062
e.buf = append(e.buf, "\"}\n"...)
20632063
} else {
@@ -2121,9 +2121,9 @@ func (e *Entry) Msgf(format string, v ...any) {
21212121
e.buf = append(e.buf, "\":\""...)
21222122
fmt.Fprintf(b, format, v...)
21232123
if !hasSIMDEscape || len(b.B) <= simdEscapeThreshold {
2124-
e.buf = appendBytes(e.buf, b.B)
2124+
e.buf = appendLoggerBytes(e.buf, b.B)
21252125
} else {
2126-
e.buf = appendBytes2(e.buf, b.B)
2126+
e.buf = appendLoggerBytes2(e.buf, b.B)
21272127
}
21282128
e.buf = append(e.buf, '"')
21292129
if cap(b.B) <= bbcap {
@@ -2145,9 +2145,9 @@ func (e *Entry) Msgs(args ...any) {
21452145
e.buf = append(e.buf, "\":\""...)
21462146
fmt.Fprint(b, args...)
21472147
if !hasSIMDEscape || len(b.B) <= simdEscapeThreshold {
2148-
e.buf = appendBytes(e.buf, b.B)
2148+
e.buf = appendLoggerBytes(e.buf, b.B)
21492149
} else {
2150-
e.buf = appendBytes2(e.buf, b.B)
2150+
e.buf = appendLoggerBytes2(e.buf, b.B)
21512151
}
21522152
e.buf = append(e.buf, '"')
21532153
if cap(b.B) <= bbcap {
@@ -2227,9 +2227,9 @@ func (e *Entry) Interface(key string, i any) *Entry {
22272227
fmt.Fprintf(b, `marshaling error: %+v`, err)
22282228
e.buf = append(e.buf, '"')
22292229
if !hasSIMDEscape || len(b.B) <= simdEscapeThreshold {
2230-
e.buf = appendBytes(e.buf, b.B)
2230+
e.buf = appendLoggerBytes(e.buf, b.B)
22312231
} else {
2232-
e.buf = appendBytes2(e.buf, b.B)
2232+
e.buf = appendLoggerBytes2(e.buf, b.B)
22332233
}
22342234
e.buf = append(e.buf, '"')
22352235
} else {
@@ -2421,9 +2421,9 @@ func (e *Entry) Any(key string, value any) *Entry {
24212421
fmt.Fprintf(b, `%+v`, value)
24222422
e.buf = append(e.buf, '"')
24232423
if !hasSIMDEscape || len(b.B) <= simdEscapeThreshold {
2424-
e.buf = appendBytes(e.buf, b.B)
2424+
e.buf = appendLoggerBytes(e.buf, b.B)
24252425
} else {
2426-
e.buf = appendBytes2(e.buf, b.B)
2426+
e.buf = appendLoggerBytes2(e.buf, b.B)
24272427
}
24282428
e.buf = append(e.buf, '"')
24292429
} else {
@@ -2581,3 +2581,5 @@ func wlprintf(w Writer, level Level, format string, args ...any) (int, error) {
25812581
//go:noescape
25822582
//go:linkname now time.now
25832583
func now() (sec int64, nsec int32, mono int64)
2584+
2585+
func b2s(b []byte) string { return *(*string)(unsafe.Pointer(&b)) }

0 commit comments

Comments
 (0)