-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_64.go
More file actions
50 lines (45 loc) · 1010 Bytes
/
code_64.go
File metadata and controls
50 lines (45 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build amd64 || amd64p32 || arm64
// +build amd64 amd64p32 arm64
package errors
import (
"fmt"
"runtime"
)
func NewCode(skip, code int, format string, a ...interface{}) (c *Code) {
if len(a) > 0 {
format = fmt.Sprintf(format, a...)
}
c = &Code{code: code, msg: format, skip: skip}
pcs := pool.Get().(*[DefaultDepth]uintptr)
for i := range pcs {
pcs[i] = 0
}
n := buildStack(pcs[:])
// for i := n; i < DefaultDepth; i++ {
// pcs[i] = 0
// }
//
cs := cacheStack.Get(pcs, n)
if cs == nil {
pcs1 := make([]uintptr, DefaultDepth)
npc1 := runtime.Callers(baseSkip, pcs1[:DefaultDepth])
cs = &callers{}
for _, c := range parseSlow(pcs1[:npc1]) {
cs.stack = append(cs.stack, c.String())
}
l := 0
for i, str := range cs.stack {
// 检查是否需要转换 JSON 特殊字符串
lStack, yes := countEscape(str)
l += lStack
if yes {
cs.attr |= 1 << i
}
}
cs.attr |= uint64(l) << 32
cacheStack.Set(pcs, n, cs)
}
pool.Put(pcs)
c.cache = cs
return
}