Replace Go's slow regexp to strings.Replace
@@ -2,9 +2,9 @@ package bytecode
import (
"bytes"
- "github.com/goby-lang/goby/compiler/ast"
- "regexp"
"strings"
+
+ "github.com/goby-lang/goby/compiler/ast"
)
type scope struct {
@@ -51,7 +51,7 @@ func (g *Generator) GenerateByteCode(stmts []ast.Statement) string {
out.WriteString(is.compile())
}
- return strings.TrimSpace(removeEmptyLine(out.String()))
+ return strings.TrimSpace(strings.Replace(out.String(), "\n\n", "\n", -1))
}
// GenerateInstructions returns compiled instructions
@@ -72,13 +72,3 @@ func (g *Generator) endInstructions(is *InstructionSet) {
}
is.define(Leave)
}
-
-func removeEmptyLine(s string) string {
- regex, err := regexp.Compile("\n+")
- if err != nil {
- panic(err)
- }
- s = regex.ReplaceAllString(s, "\n")
-
- return s
-}
