Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of an unnecessary slice in Promise. #310

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions answer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type Promise struct {
// clients is a table of promised clients created to proxy the eventual
// result's clients. Even after resolution, this table may still have
// entries until the clients are released. Cannot be read or written
// in either of the pending states.
clients map[clientPath][]clientAndPromise
// in the pending state.
clients map[clientPath]*clientAndPromise

// releasedClients is true after ReleaseClients has been called on this
// promise. Only the receiver of ReleaseClients should set this to true.
Expand Down Expand Up @@ -197,12 +197,10 @@ func (p *Promise) resolve(r Ptr, e error) {
}
syncutil.Without(&p.mu, func() {
res := resolution{p.method, r, e}
for path, row := range p.clients {
for path, cp := range p.clients {
t := path.transform()
for i := range row {
row[i].promise.Fulfill(res.client(t))
row[i].promise = nil
}
cp.promise.Fulfill(res.client(t))
cp.promise = nil
}
if p.callsStopped != nil {
<-p.callsStopped
Expand Down Expand Up @@ -243,10 +241,8 @@ func (p *Promise) ReleaseClients() {
clients := p.clients
p.clients = nil
p.mu.Unlock()
for _, row := range clients {
for _, cp := range row {
cp.client.Release()
}
for _, cp := range clients {
cp.client.Release()
}
}

Expand Down Expand Up @@ -449,17 +445,17 @@ func (f *Future) Client() Client {
case p.isUnresolved():
ft := f.transform()
cpath := clientPathFromTransform(ft)
if row := p.clients[cpath]; len(row) > 0 {
return row[0].client
if cp := p.clients[cpath]; cp != nil {
return cp.client
}
c, pr := NewPromisedClient(PipelineClient{
p: p,
transform: ft,
})
if p.clients == nil {
p.clients = make(map[clientPath][]clientAndPromise)
p.clients = make(map[clientPath]*clientAndPromise)
}
p.clients[cpath] = []clientAndPromise{{c, pr}}
p.clients[cpath] = &clientAndPromise{c, pr}
p.mu.Unlock()
return c
case p.isPendingResolution():
Expand Down