fix: i will not prematurely optimization

This commit is contained in:
Vikram Rangnekar 2020-05-29 02:23:54 -04:00
parent b3dfb2bc7b
commit bac89d8301
2 changed files with 20 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"strconv"
"strings" "strings"
"github.com/dosco/super-graph/core/internal/qcode" "github.com/dosco/super-graph/core/internal/qcode"
@ -108,6 +109,8 @@ func (co *Compiler) compileQueryWithMetadata(
st := NewIntStack() st := NewIntStack()
i := 0 i := 0
fmt.Println(">", len(qc.Roots))
io.WriteString(c.w, `SELECT jsonb_build_object(`) io.WriteString(c.w, `SELECT jsonb_build_object(`)
for _, id := range qc.Roots { for _, id := range qc.Roots {
if i != 0 { if i != 0 {
@ -260,6 +263,11 @@ func (c *compilerContext) renderPluralSelect(sel *qcode.Select, ti *DBTableInfo)
} }
func (c *compilerContext) renderRootSelect(sel *qcode.Select) error { func (c *compilerContext) renderRootSelect(sel *qcode.Select) error {
b := &bytes.Buffer{}
int32String(b, sel.ID)
fmt.Println(">>", sel.ID, sel.ParentID, " --- ", b.String())
io.WriteString(c.w, `'`) io.WriteString(c.w, `'`)
io.WriteString(c.w, sel.FieldName) io.WriteString(c.w, sel.FieldName)
io.WriteString(c.w, `', `) io.WriteString(c.w, `', `)
@ -1355,23 +1363,5 @@ func squoted(w io.Writer, identifier string) {
const charset = "0123456789" const charset = "0123456789"
func int32String(w io.Writer, val int32) { func int32String(w io.Writer, val int32) {
if val < 10 { io.WriteString(w, strconv.FormatInt(int64(val), 10))
w.Write([]byte{charset[val]})
return
}
temp := int32(0)
val2 := val
for val2 > 0 {
temp *= 10
temp += val2 % 10
val2 = int32(float64(val2 / 10))
}
val3 := temp
for val3 > 0 {
d := val3 % 10
val3 /= 10
w.Write([]byte{charset[d]})
}
} }

View File

@ -0,0 +1,11 @@
goos: darwin
goarch: amd64
pkg: github.com/dosco/super-graph/core/internal/qcode
BenchmarkQCompile-16 136509 8310 ns/op 3756 B/op 28 allocs/op
BenchmarkQCompileP-16 482752 2237 ns/op 3793 B/op 28 allocs/op
BenchmarkParse-16 139410 8552 ns/op 3902 B/op 18 allocs/op
BenchmarkParseP-16 540768 2132 ns/op 3903 B/op 18 allocs/op
BenchmarkSchemaParse-16 222925 5259 ns/op 3968 B/op 57 allocs/op
BenchmarkSchemaParseP-16 775363 1595 ns/op 3968 B/op 57 allocs/op
PASS
ok github.com/dosco/super-graph/core/internal/qcode 8.311s