Skip to content

Commit

Permalink
Do the []rune conversion once
Browse files Browse the repository at this point in the history
  • Loading branch information
matthinrichsen-wf committed Aug 1, 2023
1 parent 67ab918 commit 0e98821
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions efp.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type Tokens struct {
// tokens.
type Parser struct {
Formula string
fRune []rune
Tokens Tokens
TokenStack Tokens
Offset int
Expand Down Expand Up @@ -257,6 +258,7 @@ func (ps *Parser) getTokens() Tokens {
ps.Formula = "=" + ps.Formula
}
}
ps.fRune = []rune(ps.Formula)

var token []rune

Expand Down Expand Up @@ -613,28 +615,28 @@ func (ps *Parser) getTokens() Tokens {
// doubleChar provides function to get two characters after the current
// position.
func (ps *Parser) doubleChar() string {
if len([]rune(ps.Formula)) >= ps.Offset+2 {
return string([]rune(ps.Formula)[ps.Offset : ps.Offset+2])
if len(ps.fRune) >= ps.Offset+2 {
return string(ps.fRune[ps.Offset : ps.Offset+2])
}
return ""
}

// currentChar provides function to get the character of the current position.
func (ps *Parser) currentChar() rune {
return []rune(ps.Formula)[ps.Offset]
return ps.fRune[ps.Offset]
}

// nextChar provides function to get the next character of the current position.
func (ps *Parser) nextChar() rune {
if len([]rune(ps.Formula)) >= ps.Offset+2 {
return []rune(ps.Formula)[ps.Offset+1]
if len(ps.fRune) >= ps.Offset+2 {
return ps.fRune[ps.Offset+1]
}
return 0
}

// EOF provides function to check whether end of tokens stack.
func (ps *Parser) EOF() bool {
return ps.Offset >= len([]rune(ps.Formula))
return ps.Offset >= len(ps.fRune)
}

// Parse provides function to parse formula as a token stream (list).
Expand Down

0 comments on commit 0e98821

Please sign in to comment.