xtaci / gaio

High performance minimalism async-io(proactor) networking for Golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

关于 loop 函数中 copy(pending, w.pending) 的疑问

fumeboy opened this issue · comments

请问

// func (w *watcher) loop()
if cap(pending) < cap(w.pending) {
    pending = make([]*aiocb, 0, cap(w.pending))
}
pending = pending[:len(w.pending)]
copy(pending, w.pending)

既然 copy 的长度是 len(w.pending) ,为什么这里的第一句是以 cap(w.pending) 来扩容的?

commented

其实无所谓了,len 和cap都可以作为slice同步指标,只不过cap更准确一点