Skip to content

Commit be39d41

Browse files
author
Matthias Einwag
committed
Improve lexer performance by using a byte array as source
1 parent a5cf5f2 commit be39d41

File tree

8 files changed

+132
-118
lines changed

8 files changed

+132
-118
lines changed

gqlerrors/syntax.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"fmt"
55
"regexp"
66

7+
"strings"
8+
79
"github.com/graphql-go/graphql/language/ast"
810
"github.com/graphql-go/graphql/language/location"
911
"github.com/graphql-go/graphql/language/source"
10-
"strings"
1112
)
1213

1314
func NewSyntaxError(s *source.Source, position int, description string) *Error {
@@ -44,7 +45,7 @@ func highlightSourceAtLocation(s *source.Source, l location.SourceLocation) stri
4445
lineNum := fmt.Sprintf("%d", line)
4546
nextLineNum := fmt.Sprintf("%d", (line + 1))
4647
padLen := len(nextLineNum)
47-
lines := regexp.MustCompile("\r\n|[\n\r]").Split(s.Body, -1)
48+
lines := regexp.MustCompile("\r\n|[\n\r]").Split(string(s.Body), -1)
4849
var highlight string
4950
if line >= 2 {
5051
highlight += fmt.Sprintf("%s: %s\n", lpad(padLen, prevLineNum), printLine(lines[line-2]))

graphql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Params struct {
3434

3535
func Do(p Params) *Result {
3636
source := source.NewSource(&source.Source{
37-
Body: p.RequestString,
37+
Body: []byte(p.RequestString),
3838
Name: "GraphQL request",
3939
})
4040
AST, err := parser.Parse(parser.ParseParams{Source: source})

0 commit comments

Comments
 (0)