Skip to content

Commit

Permalink
refactor&optimization for PushAsserter
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Dec 3, 2024
1 parent d46afd8 commit f9d9b30
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,27 +1062,23 @@ func PushAsserter(i Asserter) (retFn function) {
var (
prevFound bool
prevAsserter asserter
currentGID int
)

// get pkg lvl asserter
curAsserter := defAsserter[def]
// .. to check if we are doing unit tests
if !curAsserter.isUnitTesting() {
// .. allow GLS specific asserter. NOTE see current()
curGoRID := goid()
//asserterMap.Set(curGoRID, defAsserter[i])
currentGID = goid()
asserterMap.Tx(func(m map[int]asserter) {
cur, found := m[curGoRID]
if found {
prevAsserter = cur
prevFound = found
}
m[curGoRID] = defAsserter[i]
prevAsserter, prevFound = m[currentGID]
m[currentGID] = defAsserter[i]
})
}
if prevFound {
return func() {
asserterMap.Set(goid(), prevAsserter)
asserterMap.Set(currentGID, prevAsserter)
}
}
return PopAsserter
Expand Down

0 comments on commit f9d9b30

Please sign in to comment.