Merge pull request #24 from z7zmey/issue-21

#21 scanner.Lexer.charsToBytes optimization
This commit is contained in:
Vadym Slizov
2018-06-05 02:47:09 +03:00
committed by GitHub

View File

@@ -441,6 +441,7 @@ type Lexer struct {
PhpDocComment string
Comments []comment.Comment
heredocLabel []lex.Char
tokenBytesBuf *bytes.Buffer
}
// Rune2Class returns the rune integer id
@@ -468,7 +469,7 @@ func NewLexer(src io.Reader, fName string) *Lexer {
if err != nil {
panic(err)
}
return &Lexer{lx, []int{0}, "", nil, nil}
return &Lexer{lx, []int{0}, "", nil, nil, &bytes.Buffer{}}
}
func (l *Lexer) ungetChars(n int) []lex.Char {
@@ -527,11 +528,13 @@ func (l *Lexer) addComment(c comment.Comment) {
}
func (l *Lexer) charsToBytes(chars []lex.Char) []byte {
bytesBuf := bytes.Buffer{}
for _, c := range chars {
bytesBuf.WriteRune(c.Rune)
l.tokenBytesBuf.WriteRune(c.Rune)
}
return bytesBuf.Bytes()
r := l.tokenBytesBuf.Bytes()
l.tokenBytesBuf.Reset()
return r
}