Skip to content

Commit 193db9a

Browse files
committed
try.Out.Handle() inlined + benchmark
1 parent 30032f8 commit 193db9a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

err2_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,12 @@ func BenchmarkTryVarCall(b *testing.B) {
844844
}
845845
}
846846

847+
func BenchmarkTryOut_ErrVarNoRetval(b *testing.B) {
848+
for n := 0; n < b.N; n++ {
849+
try.Out(noErr()).Handle()
850+
}
851+
}
852+
847853
func BenchmarkTryOut_ErrVar(b *testing.B) {
848854
for n := 0; n < b.N; n++ {
849855
_, err := noThrow()
@@ -863,6 +869,14 @@ func BenchmarkTryOut_StringGenerics(b *testing.B) {
863869
}
864870
}
865871

872+
func BenchmarkTryOut_StringGenericsNoVal(b *testing.B) {
873+
for n := 0; n < b.N; n++ {
874+
_ = try.Out1(noThrow()).Logf("test").Val1
875+
r := try.Out1(noThrow()).Handle()
876+
_ = r.Val1
877+
}
878+
}
879+
866880
func BenchmarkT_ErrVar(b *testing.B) {
867881
for n := 0; n < b.N; n++ {
868882
_, err := noThrow()

try/out.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func (o *Result) Handle(a ...any) *Result {
9797
if o.Err == nil {
9898
return o
9999
}
100+
o.transportErr(a)
101+
return o
102+
}
103+
104+
func (o *Result) transportErr(a []any) {
100105
noArguments := len(a) == 0
101106
if noArguments {
102107
panic(o.Err)
@@ -117,11 +122,11 @@ func (o *Result) Handle(a ...any) *Result {
117122
}
118123
}
119124
}
120-
// someone of the handler functions might reset the error value.
125+
126+
// some of the handler functions might reset the error value.
121127
if o.Err != nil {
122128
panic(o.Err)
123129
}
124-
return o
125130
}
126131

127132
// Handle allows you to add an error handler to [try.Out] handler chain. Handle

0 commit comments

Comments
 (0)