Move typeStack to ScanContext, so it is shared between rows.Scan calls. Use string.Builder for string concatenations. Simplify value assign logic. Move convert value to the last assign step (needs for type conversions are rare).
40 lines
554 B
Go
40 lines
554 B
Go
package qrm
|
|
|
|
import "reflect"
|
|
|
|
type typeStack []*reflect.Type
|
|
|
|
func newTypeStack() typeStack {
|
|
stack := make(typeStack, 0, 20)
|
|
return stack
|
|
}
|
|
|
|
func (s *typeStack) isEmpty() bool {
|
|
return len(*s) == 0
|
|
}
|
|
|
|
func (s *typeStack) push(t *reflect.Type) {
|
|
*s = append(*s, t)
|
|
}
|
|
|
|
func (s *typeStack) pop() bool {
|
|
if s.isEmpty() {
|
|
return false
|
|
}
|
|
*s = (*s)[:len(*s)-1]
|
|
return true
|
|
}
|
|
|
|
func (s *typeStack) contains(t *reflect.Type) bool {
|
|
if s.isEmpty() {
|
|
return false
|
|
}
|
|
|
|
for _, typ := range *s {
|
|
if *typ == *t {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|