Parsing: make it faster.
This commit is contained in:
parent
37500c5a59
commit
fdf0bff324
17
zgenerate.go
17
zgenerate.go
|
@ -1,6 +1,7 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -62,7 +63,7 @@ BuildRR:
|
||||||
for i := start; i <= end; i += step {
|
for i := start; i <= end; i += step {
|
||||||
var (
|
var (
|
||||||
escape bool
|
escape bool
|
||||||
dom string
|
dom bytes.Buffer
|
||||||
mod string
|
mod string
|
||||||
err string
|
err string
|
||||||
offset int
|
offset int
|
||||||
|
@ -72,7 +73,7 @@ BuildRR:
|
||||||
switch s[j] {
|
switch s[j] {
|
||||||
case '\\':
|
case '\\':
|
||||||
if escape {
|
if escape {
|
||||||
dom += "\\"
|
dom.WriteByte('\\')
|
||||||
escape = false
|
escape = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -81,17 +82,17 @@ BuildRR:
|
||||||
mod = "%d"
|
mod = "%d"
|
||||||
offset = 0
|
offset = 0
|
||||||
if escape {
|
if escape {
|
||||||
dom += "$"
|
dom.WriteByte('$')
|
||||||
escape = false
|
escape = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
escape = false
|
escape = false
|
||||||
if j+1 >= len(s) { // End of the string
|
if j+1 >= len(s) { // End of the string
|
||||||
dom += fmt.Sprintf(mod, i+offset)
|
dom.WriteString(fmt.Sprintf(mod, i+offset))
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
if s[j+1] == '$' {
|
if s[j+1] == '$' {
|
||||||
dom += "$"
|
dom.WriteByte('$')
|
||||||
j++
|
j++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -108,17 +109,17 @@ BuildRR:
|
||||||
}
|
}
|
||||||
j += 2 + sep // Jump to it
|
j += 2 + sep // Jump to it
|
||||||
}
|
}
|
||||||
dom += fmt.Sprintf(mod, i+offset)
|
dom.WriteString(fmt.Sprintf(mod, i+offset))
|
||||||
default:
|
default:
|
||||||
if escape { // Pretty useless here
|
if escape { // Pretty useless here
|
||||||
escape = false
|
escape = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dom += string(s[j])
|
dom.WriteByte(s[j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Re-parse the RR and send it on the current channel t
|
// Re-parse the RR and send it on the current channel t
|
||||||
rx, e := NewRR("$ORIGIN " + o + "\n" + dom)
|
rx, e := NewRR("$ORIGIN " + o + "\n" + dom.String())
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e.(*ParseError).err
|
return e.(*ParseError).err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue