Skip to content

Commit cf7da23

Browse files
chfastholiman
authored andcommitted
Bring some consistency to SetBytesN implementations
1 parent 052e292 commit cf7da23

File tree

1 file changed

+17
-61
lines changed

1 file changed

+17
-61
lines changed

conversion.go

+17-61
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func (z *Int) Format(s fmt.State, ch rune) {
109109
// SetBytes8 is identical to SetBytes(in[:8]), but panics is input is too short
110110
func (z *Int) SetBytes8(in []byte) *Int {
111111
_ = in[7] // bounds check hint to compiler; see golang.org/issue/14808
112-
113112
z[3], z[2], z[1] = 0, 0, 0
114113
z[0] = binary.BigEndian.Uint64(in[0:8])
115114
return z
@@ -118,7 +117,6 @@ func (z *Int) SetBytes8(in []byte) *Int {
118117
// SetBytes16 is identical to SetBytes(in[:16]), but panics is input is too short
119118
func (z *Int) SetBytes16(in []byte) *Int {
120119
_ = in[15] // bounds check hint to compiler; see golang.org/issue/14808
121-
122120
z[3], z[2] = 0, 0
123121
z[1] = binary.BigEndian.Uint64(in[0:8])
124122
z[0] = binary.BigEndian.Uint64(in[8:16])
@@ -128,7 +126,6 @@ func (z *Int) SetBytes16(in []byte) *Int {
128126
// SetBytes16 is identical to SetBytes(in[:24]), but panics is input is too short
129127
func (z *Int) SetBytes24(in []byte) *Int {
130128
_ = in[23] // bounds check hint to compiler; see golang.org/issue/14808
131-
132129
z[3] = 0
133130
z[2] = binary.BigEndian.Uint64(in[0:8])
134131
z[1] = binary.BigEndian.Uint64(in[8:16])
@@ -138,7 +135,6 @@ func (z *Int) SetBytes24(in []byte) *Int {
138135

139136
func (z *Int) SetBytes32(in []byte) *Int {
140137
_ = in[31] // bounds check hint to compiler; see golang.org/issue/14808
141-
142138
z[3] = binary.BigEndian.Uint64(in[0:8])
143139
z[2] = binary.BigEndian.Uint64(in[8:16])
144140
z[1] = binary.BigEndian.Uint64(in[16:24])
@@ -147,20 +143,21 @@ func (z *Int) SetBytes32(in []byte) *Int {
147143
}
148144

149145
func (z *Int) SetBytes1(in []byte) *Int {
150-
z[3], z[2], z[1], z[0] = 0, 0, 0, uint64(in[0])
146+
z[3], z[2], z[1] = 0, 0, 0
147+
z[0] = uint64(in[0])
151148
return z
152149
}
153150

154151
func (z *Int) SetBytes9(in []byte) *Int {
155152
_ = in[8] // bounds check hint to compiler; see golang.org/issue/14808
156-
157-
z[3], z[2], z[1], z[0] = 0, 0, uint64(in[0]), binary.BigEndian.Uint64(in[1:9])
153+
z[3], z[2] = 0, 0
154+
z[1] = uint64(in[0])
155+
z[0] = binary.BigEndian.Uint64(in[1:9])
158156
return z
159157
}
160158

161159
func (z *Int) SetBytes17(in []byte) *Int {
162160
_ = in[16] // bounds check hint to compiler; see golang.org/issue/14808
163-
164161
z[3] = 0
165162
z[2] = uint64(in[0])
166163
z[1] = binary.BigEndian.Uint64(in[1:9])
@@ -170,7 +167,6 @@ func (z *Int) SetBytes17(in []byte) *Int {
170167

171168
func (z *Int) SetBytes25(in []byte) *Int {
172169
_ = in[24] // bounds check hint to compiler; see golang.org/issue/14808
173-
174170
z[3] = uint64(in[0])
175171
z[2] = binary.BigEndian.Uint64(in[1:9])
176172
z[1] = binary.BigEndian.Uint64(in[9:17])
@@ -180,27 +176,21 @@ func (z *Int) SetBytes25(in []byte) *Int {
180176

181177
func (z *Int) SetBytes2(in []byte) *Int {
182178
_ = in[1] // bounds check hint to compiler; see golang.org/issue/14808
183-
184-
z[3] = 0
185-
z[2] = 0
186-
z[1] = 0
179+
z[3], z[2], z[1] = 0, 0, 0
187180
z[0] = uint64(binary.BigEndian.Uint16(in[0:2]))
188181
return z
189182
}
190183

191184
func (z *Int) SetBytes10(in []byte) *Int {
192185
_ = in[9] // bounds check hint to compiler; see golang.org/issue/14808
193-
194-
z[3] = 0
195-
z[2] = 0
186+
z[3], z[2] = 0, 0
196187
z[1] = uint64(binary.BigEndian.Uint16(in[0:2]))
197188
z[0] = binary.BigEndian.Uint64(in[2:10])
198189
return z
199190
}
200191

201192
func (z *Int) SetBytes18(in []byte) *Int {
202193
_ = in[17] // bounds check hint to compiler; see golang.org/issue/14808
203-
204194
z[3] = 0
205195
z[2] = uint64(binary.BigEndian.Uint16(in[0:2]))
206196
z[1] = binary.BigEndian.Uint64(in[2:10])
@@ -210,7 +200,6 @@ func (z *Int) SetBytes18(in []byte) *Int {
210200

211201
func (z *Int) SetBytes26(in []byte) *Int {
212202
_ = in[25] // bounds check hint to compiler; see golang.org/issue/14808
213-
214203
z[3] = uint64(binary.BigEndian.Uint16(in[0:2]))
215204
z[2] = binary.BigEndian.Uint64(in[2:10])
216205
z[1] = binary.BigEndian.Uint64(in[10:18])
@@ -220,25 +209,21 @@ func (z *Int) SetBytes26(in []byte) *Int {
220209

221210
func (z *Int) SetBytes3(in []byte) *Int {
222211
_ = in[2] // bounds check hint to compiler; see golang.org/issue/14808
223-
z[3] = 0
224-
z[2] = 0
225-
z[1] = 0
212+
z[3], z[2], z[1] = 0, 0, 0
226213
z[0] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
227214
return z
228215
}
229216

230217
func (z *Int) SetBytes11(in []byte) *Int {
231218
_ = in[10] // bounds check hint to compiler; see golang.org/issue/14808
232-
z[3] = 0
233-
z[2] = 0
219+
z[3], z[2] = 0, 0
234220
z[1] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
235221
z[0] = binary.BigEndian.Uint64(in[3:11])
236222
return z
237223
}
238224

239225
func (z *Int) SetBytes19(in []byte) *Int {
240226
_ = in[18] // bounds check hint to compiler; see golang.org/issue/14808
241-
242227
z[3] = 0
243228
z[2] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
244229
z[1] = binary.BigEndian.Uint64(in[3:11])
@@ -248,7 +233,6 @@ func (z *Int) SetBytes19(in []byte) *Int {
248233

249234
func (z *Int) SetBytes27(in []byte) *Int {
250235
_ = in[26] // bounds check hint to compiler; see golang.org/issue/14808
251-
252236
z[3] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
253237
z[2] = binary.BigEndian.Uint64(in[3:11])
254238
z[1] = binary.BigEndian.Uint64(in[11:19])
@@ -258,27 +242,21 @@ func (z *Int) SetBytes27(in []byte) *Int {
258242

259243
func (z *Int) SetBytes4(in []byte) *Int {
260244
_ = in[3] // bounds check hint to compiler; see golang.org/issue/14808
261-
262-
z[3] = 0
263-
z[2] = 0
264-
z[1] = 0
245+
z[3], z[2], z[1] = 0, 0, 0
265246
z[0] = uint64(binary.BigEndian.Uint32(in[0:4]))
266247
return z
267248
}
268249

269250
func (z *Int) SetBytes12(in []byte) *Int {
270251
_ = in[11] // bounds check hint to compiler; see golang.org/issue/14808
271-
272-
z[3] = 0
273-
z[2] = 0
252+
z[3], z[2] = 0, 0
274253
z[1] = uint64(binary.BigEndian.Uint32(in[0:4]))
275254
z[0] = binary.BigEndian.Uint64(in[4:12])
276255
return z
277256
}
278257

279258
func (z *Int) SetBytes20(in []byte) *Int {
280259
_ = in[19] // bounds check hint to compiler; see golang.org/issue/14808
281-
282260
z[3] = 0
283261
z[2] = uint64(binary.BigEndian.Uint32(in[0:4]))
284262
z[1] = binary.BigEndian.Uint64(in[4:12])
@@ -288,7 +266,6 @@ func (z *Int) SetBytes20(in []byte) *Int {
288266

289267
func (z *Int) SetBytes28(in []byte) *Int {
290268
_ = in[27] // bounds check hint to compiler; see golang.org/issue/14808
291-
292269
z[3] = uint64(binary.BigEndian.Uint32(in[0:4]))
293270
z[2] = binary.BigEndian.Uint64(in[4:12])
294271
z[1] = binary.BigEndian.Uint64(in[12:20])
@@ -298,27 +275,21 @@ func (z *Int) SetBytes28(in []byte) *Int {
298275

299276
func (z *Int) SetBytes5(in []byte) *Int {
300277
_ = in[4] // bounds check hint to compiler; see golang.org/issue/14808
301-
302-
z[3] = 0
303-
z[2] = 0
304-
z[1] = 0
278+
z[3], z[2], z[1] = 0, 0, 0
305279
z[0] = bigEndianUint40(in[0:5])
306280
return z
307281
}
308282

309283
func (z *Int) SetBytes13(in []byte) *Int {
310284
_ = in[12] // bounds check hint to compiler; see golang.org/issue/14808
311-
312-
z[3] = 0
313-
z[2] = 0
285+
z[3], z[2] = 0, 0
314286
z[1] = bigEndianUint40(in[0:5])
315287
z[0] = binary.BigEndian.Uint64(in[5:13])
316288
return z
317289
}
318290

319291
func (z *Int) SetBytes21(in []byte) *Int {
320292
_ = in[20] // bounds check hint to compiler; see golang.org/issue/14808
321-
322293
z[3] = 0
323294
z[2] = bigEndianUint40(in[0:5])
324295
z[1] = binary.BigEndian.Uint64(in[5:13])
@@ -328,7 +299,6 @@ func (z *Int) SetBytes21(in []byte) *Int {
328299

329300
func (z *Int) SetBytes29(in []byte) *Int {
330301
_ = in[23] // bounds check hint to compiler; see golang.org/issue/14808
331-
332302
z[3] = bigEndianUint40(in[0:5])
333303
z[2] = binary.BigEndian.Uint64(in[5:13])
334304
z[1] = binary.BigEndian.Uint64(in[13:21])
@@ -338,27 +308,21 @@ func (z *Int) SetBytes29(in []byte) *Int {
338308

339309
func (z *Int) SetBytes6(in []byte) *Int {
340310
_ = in[5] // bounds check hint to compiler; see golang.org/issue/14808
341-
342-
z[3] = 0
343-
z[2] = 0
344-
z[1] = 0
311+
z[3], z[2], z[1] = 0, 0, 0
345312
z[0] = bigEndianUint48(in[0:6])
346313
return z
347314
}
348315

349316
func (z *Int) SetBytes14(in []byte) *Int {
350317
_ = in[13] // bounds check hint to compiler; see golang.org/issue/14808
351-
352-
z[3] = 0
353-
z[2] = 0
318+
z[3], z[2] = 0, 0
354319
z[1] = bigEndianUint48(in[0:6])
355320
z[0] = binary.BigEndian.Uint64(in[6:14])
356321
return z
357322
}
358323

359324
func (z *Int) SetBytes22(in []byte) *Int {
360325
_ = in[21] // bounds check hint to compiler; see golang.org/issue/14808
361-
362326
z[3] = 0
363327
z[2] = bigEndianUint48(in[0:6])
364328
z[1] = binary.BigEndian.Uint64(in[6:14])
@@ -368,7 +332,6 @@ func (z *Int) SetBytes22(in []byte) *Int {
368332

369333
func (z *Int) SetBytes30(in []byte) *Int {
370334
_ = in[29] // bounds check hint to compiler; see golang.org/issue/14808
371-
372335
z[3] = bigEndianUint48(in[0:6])
373336
z[2] = binary.BigEndian.Uint64(in[6:14])
374337
z[1] = binary.BigEndian.Uint64(in[14:22])
@@ -378,27 +341,21 @@ func (z *Int) SetBytes30(in []byte) *Int {
378341

379342
func (z *Int) SetBytes7(in []byte) *Int {
380343
_ = in[6] // bounds check hint to compiler; see golang.org/issue/14808
381-
382-
z[3] = 0
383-
z[2] = 0
384-
z[1] = 0
344+
z[3], z[2], z[1] = 0, 0, 0
385345
z[0] = bigEndianUint56(in[0:7])
386346
return z
387347
}
388348

389349
func (z *Int) SetBytes15(in []byte) *Int {
390350
_ = in[14] // bounds check hint to compiler; see golang.org/issue/14808
391-
392-
z[3] = 0
393-
z[2] = 0
351+
z[3], z[2] = 0, 0
394352
z[1] = bigEndianUint56(in[0:7])
395353
z[0] = binary.BigEndian.Uint64(in[7:15])
396354
return z
397355
}
398356

399357
func (z *Int) SetBytes23(in []byte) *Int {
400358
_ = in[22] // bounds check hint to compiler; see golang.org/issue/14808
401-
402359
z[3] = 0
403360
z[2] = bigEndianUint56(in[0:7])
404361
z[1] = binary.BigEndian.Uint64(in[7:15])
@@ -408,7 +365,6 @@ func (z *Int) SetBytes23(in []byte) *Int {
408365

409366
func (z *Int) SetBytes31(in []byte) *Int {
410367
_ = in[30] // bounds check hint to compiler; see golang.org/issue/14808
411-
412368
z[3] = bigEndianUint56(in[0:7])
413369
z[2] = binary.BigEndian.Uint64(in[7:15])
414370
z[1] = binary.BigEndian.Uint64(in[15:23])

0 commit comments

Comments
 (0)