@@ -18,52 +18,45 @@ func TestSetLink(t *testing.T) {
1818	l .SetTraceID (pcommon .TraceID ([16 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 }))
1919	l2  :=  NewLink ()
2020	l .SetTraceID (pcommon .TraceID ([16 ]byte {2 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 2 }))
21- 	smpl  :=  NewSample ()
2221
2322	// Put a first link 
24- 	require .NoError (t , SetLink (table , smpl , l ))
23+ 	idx , err  :=  SetLink (table , l )
24+ 	require .NoError (t , err )
2525	assert .Equal (t , 1 , table .Len ())
26- 	assert .Equal (t , int32 (0 ), smpl . LinkIndex () )
26+ 	assert .Equal (t , int32 (0 ), idx )
2727
2828	// Put the same link 
2929	// This should be a no-op. 
30- 	require .NoError (t , SetLink (table , smpl , l ))
30+ 	idx , err  =  SetLink (table , l )
31+ 	require .NoError (t , err )
3132	assert .Equal (t , 1 , table .Len ())
32- 	assert .Equal (t , int32 (0 ), smpl . LinkIndex () )
33+ 	assert .Equal (t , int32 (0 ), idx )
3334
3435	// Set a new link 
3536	// This sets the index and adds to the table. 
36- 	require .NoError (t , SetLink (table , smpl , l2 ))
37+ 	idx , err  =  SetLink (table , l2 )
38+ 	require .NoError (t , err )
3739	assert .Equal (t , 2 , table .Len ())
38- 	assert .Equal (t , int32 (table .Len ()- 1 ), smpl . LinkIndex () ) //nolint:gosec // G115 
40+ 	assert .Equal (t , int32 (table .Len ()- 1 ), idx ) //nolint:gosec // G115 
3941
4042	// Set an existing link 
41- 	require .NoError (t , SetLink (table , smpl , l ))
43+ 	idx , err  =  SetLink (table , l )
44+ 	require .NoError (t , err )
4245	assert .Equal (t , 2 , table .Len ())
43- 	assert .Equal (t , int32 (0 ), smpl . LinkIndex () )
46+ 	assert .Equal (t , int32 (0 ), idx )
4447	// Set another existing link 
45- 	require .NoError (t , SetLink (table , smpl , l2 ))
48+ 	idx , err  =  SetLink (table , l2 )
49+ 	require .NoError (t , err )
4650	assert .Equal (t , 2 , table .Len ())
47- 	assert .Equal (t , int32 (table .Len ()- 1 ), smpl .LinkIndex ()) //nolint:gosec // G115 
48- }
49- 
50- func  TestSetLinkCurrentTooHigh (t  * testing.T ) {
51- 	table  :=  NewLinkSlice ()
52- 	smpl  :=  NewSample ()
53- 	smpl .SetLinkIndex (42 )
54- 
55- 	err  :=  SetLink (table , smpl , NewLink ())
56- 	require .Error (t , err )
57- 	assert .Equal (t , 0 , table .Len ())
58- 	assert .Equal (t , int32 (42 ), smpl .LinkIndex ())
51+ 	assert .Equal (t , int32 (table .Len ()- 1 ), idx ) //nolint:gosec // G115 
5952}
6053
6154func  BenchmarkSetLink (b  * testing.B ) {
6255	for  _ , bb  :=  range  []struct  {
6356		name  string 
6457		link  Link 
6558
66- 		runBefore  func (* testing.B , LinkSlice ,  Sample )
59+ 		runBefore  func (* testing.B , LinkSlice )
6760	}{
6861		{
6962			name : "with a new link" ,
@@ -77,7 +70,7 @@ func BenchmarkSetLink(b *testing.B) {
7770				return  l 
7871			}(),
7972
80- 			runBefore : func (_  * testing.B , table  LinkSlice ,  _   Sample ) {
73+ 			runBefore : func (_  * testing.B , table  LinkSlice ) {
8174				l  :=  table .AppendEmpty ()
8275				l .SetTraceID (pcommon .NewTraceIDEmpty ())
8376			},
@@ -86,8 +79,9 @@ func BenchmarkSetLink(b *testing.B) {
8679			name : "with a duplicate link" ,
8780			link : NewLink (),
8881
89- 			runBefore : func (_  * testing.B , table  LinkSlice , obj  Sample ) {
90- 				require .NoError (b , SetLink (table , obj , NewLink ()))
82+ 			runBefore : func (b  * testing.B , table  LinkSlice ) {
83+ 				_ , err  :=  SetLink (table , NewLink ())
84+ 				require .NoError (b , err )
9185			},
9286		},
9387		{
@@ -98,7 +92,7 @@ func BenchmarkSetLink(b *testing.B) {
9892				return  l 
9993			}(),
10094
101- 			runBefore : func (_  * testing.B , table  LinkSlice ,  _   Sample ) {
95+ 			runBefore : func (_  * testing.B , table  LinkSlice ) {
10296				for  range  100  {
10397					table .AppendEmpty ()
10498				}
@@ -107,17 +101,16 @@ func BenchmarkSetLink(b *testing.B) {
107101	} {
108102		b .Run (bb .name , func (b  * testing.B ) {
109103			table  :=  NewLinkSlice ()
110- 			obj  :=  NewSample ()
111104
112105			if  bb .runBefore  !=  nil  {
113- 				bb .runBefore (b , table ,  obj )
106+ 				bb .runBefore (b , table )
114107			}
115108
116109			b .ResetTimer ()
117110			b .ReportAllocs ()
118111
119112			for  b .Loop () {
120- 				_   =  SetLink (table ,  obj , bb .link )
113+ 				_ ,  _   =  SetLink (table , bb .link )
121114			}
122115		})
123116	}
0 commit comments