From f9d9b30ff2d973f23437d7150a3f50f2e40b95c6 Mon Sep 17 00:00:00 2001 From: Harri Lainio Date: Tue, 3 Dec 2024 19:00:43 +0200 Subject: [PATCH] refactor&optimization for PushAsserter --- assert/assert.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/assert/assert.go b/assert/assert.go index 13b78f1..1df956b 100644 --- a/assert/assert.go +++ b/assert/assert.go @@ -1062,6 +1062,7 @@ func PushAsserter(i Asserter) (retFn function) { var ( prevFound bool prevAsserter asserter + currentGID int ) // get pkg lvl asserter @@ -1069,20 +1070,15 @@ func PushAsserter(i Asserter) (retFn function) { // .. 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