Skip to content

Commit

Permalink
Lazy evaluate pairs for where
Browse files Browse the repository at this point in the history
  • Loading branch information
grafov committed Nov 22, 2018
1 parent becb665 commit eb10374
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions where/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,41 @@ func What(parts int) []*kiwi.Pair {
pairs []*kiwi.Pair
skip = stackJump
)
start:
pc, file, _, _ := runtime.Caller(skip)

if parts&Line > 0 {
pairs = []*kiwi.Pair{{
Key: "lineno",
Eval: func() string {
_, _, line, _ := runtime.Caller(skip)
start:
pc, _, line, _ := runtime.Caller(skip)
function := runtime.FuncForPC(pc).Name()
if strings.LastIndex(function, "grafov/kiwi.") != -1 {
skip++
goto start
}
return strconv.Itoa(line)
},
Type: kiwi.IntegerVal}}
}
if parts&File > 0 {
pairs = append(pairs, &kiwi.Pair{
Key: "file",
Val: file,
Key: "file",
Eval: func() string {
_, file, _, _ := runtime.Caller(skip)
return file
},
Type: kiwi.StringVal,
})
}
function := runtime.FuncForPC(pc).Name()
if parts&Func > 0 {
pairs = append(pairs, &kiwi.Pair{
Key: "function",
Val: function,
Key: "function",
Eval: func() string {
pc, _, _, _ := runtime.Caller(skip)
function := runtime.FuncForPC(pc).Name()
return function
},
Type: kiwi.StringVal,
})
}
if strings.LastIndex(function, "grafov/kiwi.") != -1 {
skip++
goto start
}
return pairs
}

0 comments on commit eb10374

Please sign in to comment.