Skip to content

Commit

Permalink
Simplify Defer: do not wrap first deferred func
Browse files Browse the repository at this point in the history
Faster call to the deferred function for the most common case (a single
Defer call).
  • Loading branch information
dolmen committed Jun 10, 2023
1 parent d07c1d3 commit ee6dcaa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions quicktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ func (c *C) Defer(f func()) {
}

oldDeferred := c.deferred
c.deferred = func() {
if oldDeferred != nil {
if oldDeferred != nil {
c.deferred = func() {
defer oldDeferred()
f()
}
f()
} else {
c.deferred = f
}
}

Expand Down

0 comments on commit ee6dcaa

Please sign in to comment.