Make CountLabel faster
We don't need an allocation here, it works ok for non-fqdns and fqdns
This commit is contained in:
parent
b663a82eb3
commit
9764818db3
|
@ -89,7 +89,7 @@ func CountLabel(s string) (labels int) {
|
|||
if s == "." {
|
||||
return
|
||||
}
|
||||
s = Fqdn(s) // TODO(miek): annoyed I need this
|
||||
// s = Fqdn(s) // TODO(miek): annoyed I need this
|
||||
off := 0
|
||||
end := false
|
||||
for {
|
||||
|
|
|
@ -78,6 +78,21 @@ func TestSplit2(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCountLabel(t *testing.T) {
|
||||
splitter := map[string]int{
|
||||
"www.miek.nl.": 3,
|
||||
"www.miek.nl": 3,
|
||||
".": 0,
|
||||
}
|
||||
for s, i := range splitter {
|
||||
x := CountLabel(s)
|
||||
if x != i {
|
||||
t.Logf("CountLabel should have %d, got %d\n", i, x)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitDomainName(t *testing.T) {
|
||||
labels := map[string][]string{
|
||||
"miek.nl": []string{"miek", "nl"},
|
||||
|
|
Loading…
Reference in New Issue