Use append() instead of doing it manually.

This commit is contained in:
Alex Bramley 2010-11-03 23:50:43 +00:00
parent 38eb150850
commit 7935d2e939
1 changed files with 1 additions and 11 deletions

View File

@ -24,17 +24,7 @@ import (
func (conn *Conn) AddHandler(name string, f func(*Conn, *Line)) {
n := strings.ToUpper(name)
if e, ok := conn.events[n]; ok {
if len(e) == cap(e) {
// crap, we're full. expand e by another 10 handler slots
ne := make([]func(*Conn, *Line), len(e), len(e)+10)
for i := 0; i < len(e); i++ {
ne[i] = e[i]
}
e = ne
}
e = e[0 : len(e)+1]
e[len(e)-1] = f
conn.events[n] = e
conn.events[n] = append(e, f)
} else {
e := make([]func(*Conn, *Line), 1, 10)
e[0] = f