Skip to content

Commit

Permalink
Improve lexer performance by using a byte array as source
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Einwag authored and Matthias247 committed Jun 12, 2016
1 parent 500a3ff commit d060075
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 118 deletions.
5 changes: 3 additions & 2 deletions gqlerrors/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"regexp"

"strings"

"github.com/graphql-go/graphql/language/ast"
"github.com/graphql-go/graphql/language/location"
"github.com/graphql-go/graphql/language/source"
"strings"
)

func NewSyntaxError(s *source.Source, position int, description string) *Error {
Expand Down Expand Up @@ -44,7 +45,7 @@ func highlightSourceAtLocation(s *source.Source, l location.SourceLocation) stri
lineNum := fmt.Sprintf("%d", line)
nextLineNum := fmt.Sprintf("%d", (line + 1))
padLen := len(nextLineNum)
lines := regexp.MustCompile("\r\n|[\n\r]").Split(s.Body, -1)
lines := regexp.MustCompile("\r\n|[\n\r]").Split(string(s.Body), -1)
var highlight string
if line >= 2 {
highlight += fmt.Sprintf("%s: %s\n", lpad(padLen, prevLineNum), printLine(lines[line-2]))
Expand Down
2 changes: 1 addition & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Params struct {

func Do(p Params) *Result {
source := source.NewSource(&source.Source{
Body: p.RequestString,
Body: []byte(p.RequestString),
Name: "GraphQL request",
})
AST, err := parser.Parse(parser.ParseParams{Source: source})
Expand Down
Loading

0 comments on commit d060075

Please sign in to comment.