Skip to content

Commit

Permalink
Reuse context at Scanner (#487)
Browse files Browse the repository at this point in the history
* reuse context

* refactor scan function

* remove unused function
  • Loading branch information
goccy authored Oct 29, 2024
1 parent 87ddfd1 commit c9f75fe
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 80 deletions.
22 changes: 8 additions & 14 deletions scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/goccy/go-yaml/token"
)

const whitespace = ' '

// Context context at scanning
type Context struct {
idx int
Expand Down Expand Up @@ -49,6 +47,14 @@ func (c *Context) release() {
ctxPool.Put(c)
}

func (c *Context) clear() {
c.resetBuffer()
c.isRawFolded = false
c.isLiteral = false
c.isFolded = false
c.literalOpt = ""
}

func (c *Context) reset(src []rune) {
c.idx = 0
c.size = len(src)
Expand Down Expand Up @@ -144,18 +150,6 @@ func (c *Context) currentChar() rune {
return rune(0)
}

func (c *Context) currentCharWithSkipWhitespace() rune {
idx := c.idx
for c.size > idx {
ch := c.src[idx]
if ch != whitespace {
return ch
}
idx++
}
return rune(0)
}

func (c *Context) nextChar() rune {
if c.size > c.idx+1 {
return c.src[c.idx+1]
Expand Down
Loading

0 comments on commit c9f75fe

Please sign in to comment.