Make CountLabel faster

We don't need an allocation here, it works ok for non-fqdns and fqdns
This commit is contained in:
Miek Gieben 2013-09-12 09:11:19 +01:00
parent b663a82eb3
commit 9764818db3
2 changed files with 16 additions and 1 deletions

View File

@ -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 {

View File

@ -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"},