tighter loop

This commit is contained in:
Ted Unangst 2019-06-01 16:11:04 -04:00
parent e7a770bac2
commit ce850eb0cb
1 changed files with 7 additions and 16 deletions

19
fun.go
View File

@ -79,28 +79,19 @@ func reverbolate(honks []*Honk) {
func osmosis(honks []*Honk, userid int64) []*Honk { func osmosis(honks []*Honk, userid int64) []*Honk {
zwords := getzwords(userid) zwords := getzwords(userid)
collapse := false j := 0
for i, h := range honks { outer:
for _, h := range honks {
for _, z := range zwords { for _, z := range zwords {
if z.MatchString(h.Precis) || z.MatchString(h.Noise) { if z.MatchString(h.Precis) || z.MatchString(h.Noise) {
honks[i] = nil continue outer
collapse = true
break
} }
} }
} honks[j] = h
if collapse {
j := 0
for i := 0; i < len(honks); i++ {
if honks[i] != nil {
honks[j] = honks[i]
j++ j++
} }
}
return honks[0:j] return honks[0:j]
} }
return honks
}
func shortxid(xid string) string { func shortxid(xid string) string {
idx := strings.LastIndexByte(xid, '/') idx := strings.LastIndexByte(xid, '/')