@@ -16,52 +16,45 @@ func TestSetMapping(t *testing.T) {
1616	m .SetMemoryLimit (1 )
1717	m2  :=  NewMapping ()
1818	m2 .SetMemoryLimit (2 )
19- 	loc  :=  NewLocation ()
2019
2120	// Put a first mapping 
22- 	require .NoError (t , SetMapping (table , loc , m ))
21+ 	idx , err  :=  SetMapping (table , m )
22+ 	require .NoError (t , err )
2323	assert .Equal (t , 1 , table .Len ())
24- 	assert .Equal (t , int32 (0 ), loc . MappingIndex () )
24+ 	assert .Equal (t , int32 (0 ), idx )
2525
2626	// Put the same mapping 
2727	// This should be a no-op. 
28- 	require .NoError (t , SetMapping (table , loc , m ))
28+ 	idx , err  =  SetMapping (table , m )
29+ 	require .NoError (t , err )
2930	assert .Equal (t , 1 , table .Len ())
30- 	assert .Equal (t , int32 (0 ), loc . MappingIndex () )
31+ 	assert .Equal (t , int32 (0 ), idx )
3132
3233	// Set a new mapping 
3334	// This sets the index and adds to the table. 
34- 	require .NoError (t , SetMapping (table , loc , m2 ))
35+ 	idx , err  =  SetMapping (table , m2 )
36+ 	require .NoError (t , err )
3537	assert .Equal (t , 2 , table .Len ())
36- 	assert .Equal (t , int32 (table .Len ()- 1 ), loc . MappingIndex () ) //nolint:gosec // G115 
38+ 	assert .Equal (t , int32 (table .Len ()- 1 ), idx ) //nolint:gosec // G115 
3739
3840	// Set an existing mapping 
39- 	require .NoError (t , SetMapping (table , loc , m ))
41+ 	idx , err  =  SetMapping (table , m )
42+ 	require .NoError (t , err )
4043	assert .Equal (t , 2 , table .Len ())
41- 	assert .Equal (t , int32 (0 ), loc . MappingIndex () )
44+ 	assert .Equal (t , int32 (0 ), idx )
4245	// Set another existing mapping 
43- 	require .NoError (t , SetMapping (table , loc , m2 ))
46+ 	idx , err  =  SetMapping (table , m2 )
47+ 	require .NoError (t , err )
4448	assert .Equal (t , 2 , table .Len ())
45- 	assert .Equal (t , int32 (table .Len ()- 1 ), loc .MappingIndex ()) //nolint:gosec // G115 
46- }
47- 
48- func  TestSetMappingCurrentTooHigh (t  * testing.T ) {
49- 	table  :=  NewMappingSlice ()
50- 	loc  :=  NewLocation ()
51- 	loc .SetMappingIndex (42 )
52- 
53- 	err  :=  SetMapping (table , loc , NewMapping ())
54- 	require .Error (t , err )
55- 	assert .Equal (t , 0 , table .Len ())
56- 	assert .Equal (t , int32 (42 ), loc .MappingIndex ())
49+ 	assert .Equal (t , int32 (table .Len ()- 1 ), idx ) //nolint:gosec // G115 
5750}
5851
5952func  BenchmarkSetMapping (b  * testing.B ) {
6053	for  _ , bb  :=  range  []struct  {
6154		name     string 
6255		mapping  Mapping 
6356
64- 		runBefore  func (* testing.B , MappingSlice ,  Location )
57+ 		runBefore  func (* testing.B , MappingSlice )
6558	}{
6659		{
6760			name :    "with a new mapping" ,
@@ -75,7 +68,7 @@ func BenchmarkSetMapping(b *testing.B) {
7568				return  m 
7669			}(),
7770
78- 			runBefore : func (_  * testing.B , table  MappingSlice ,  _   Location ) {
71+ 			runBefore : func (_  * testing.B , table  MappingSlice ) {
7972				m  :=  table .AppendEmpty ()
8073				m .SetMemoryLimit (1 )
8174			},
@@ -84,8 +77,9 @@ func BenchmarkSetMapping(b *testing.B) {
8477			name :    "with a duplicate mapping" ,
8578			mapping : NewMapping (),
8679
87- 			runBefore : func (_  * testing.B , table  MappingSlice , obj  Location ) {
88- 				require .NoError (b , SetMapping (table , obj , NewMapping ()))
80+ 			runBefore : func (_  * testing.B , table  MappingSlice ) {
81+ 				_ , err  :=  SetMapping (table , NewMapping ())
82+ 				require .NoError (b , err )
8983			},
9084		},
9185		{
@@ -96,7 +90,7 @@ func BenchmarkSetMapping(b *testing.B) {
9690				return  m 
9791			}(),
9892
99- 			runBefore : func (_  * testing.B , table  MappingSlice ,  _   Location ) {
93+ 			runBefore : func (_  * testing.B , table  MappingSlice ) {
10094				for  i  :=  range  100  {
10195					m  :=  table .AppendEmpty ()
10296					m .SetMemoryLimit (uint64 (i )) //nolint:gosec // overflow checked 
@@ -106,17 +100,16 @@ func BenchmarkSetMapping(b *testing.B) {
106100	} {
107101		b .Run (bb .name , func (b  * testing.B ) {
108102			table  :=  NewMappingSlice ()
109- 			obj  :=  NewLocation ()
110103
111104			if  bb .runBefore  !=  nil  {
112- 				bb .runBefore (b , table ,  obj )
105+ 				bb .runBefore (b , table )
113106			}
114107
115108			b .ResetTimer ()
116109			b .ReportAllocs ()
117110
118111			for  b .Loop () {
119- 				_   =  SetMapping (table ,  obj , bb .mapping )
112+ 				_ ,  _   =  SetMapping (table , bb .mapping )
120113			}
121114		})
122115	}
0 commit comments