-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
I noticed that when using -switch that the resulting code seems to be sub-par and does checks multiple times. For instance, I see
switch buffer[position] {
// [...]
case ' ':
if buffer[position] != rune(' ') {
goto l0
}
position++The if is completely redundant (and slightly removes the point of switch if the ifs are just kept but now inside a switch :))
There are other, more involved examples:
switch buffer[position] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
{
position5, tokenIndex5 := position, tokenIndex
if c := buffer[position]; c < rune('0') || c > rune('9') {
goto l6
}
position++
goto l5
l6:
position, tokenIndex = position5, tokenIndex5
if c := buffer[position]; c < rune('0') || c > rune('9') {
goto l0
}
position++
}
l5:
breakHere the whole code except for position++ is superfluous.
Example PEG:
package minimal
type Parser Peg {
}
OtherAttr <- [[A-Z_ 0-9]]+ _ ':' [^\n]*
_ <- [ \t]*
Metadata
Metadata
Assignees
Labels
No labels