Skip to content

Commit

Permalink
Bring some consistency to SetBytesN implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast authored and holiman committed Jun 5, 2020
1 parent 052e292 commit cf7da23
Showing 1 changed file with 17 additions and 61 deletions.
78 changes: 17 additions & 61 deletions conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (z *Int) Format(s fmt.State, ch rune) {
// SetBytes8 is identical to SetBytes(in[:8]), but panics is input is too short
func (z *Int) SetBytes8(in []byte) *Int {
_ = in[7] // bounds check hint to compiler; see golang.org/issue/14808

z[3], z[2], z[1] = 0, 0, 0
z[0] = binary.BigEndian.Uint64(in[0:8])
return z
Expand All @@ -118,7 +117,6 @@ func (z *Int) SetBytes8(in []byte) *Int {
// SetBytes16 is identical to SetBytes(in[:16]), but panics is input is too short
func (z *Int) SetBytes16(in []byte) *Int {
_ = in[15] // bounds check hint to compiler; see golang.org/issue/14808

z[3], z[2] = 0, 0
z[1] = binary.BigEndian.Uint64(in[0:8])
z[0] = binary.BigEndian.Uint64(in[8:16])
Expand All @@ -128,7 +126,6 @@ func (z *Int) SetBytes16(in []byte) *Int {
// SetBytes16 is identical to SetBytes(in[:24]), but panics is input is too short
func (z *Int) SetBytes24(in []byte) *Int {
_ = in[23] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = binary.BigEndian.Uint64(in[0:8])
z[1] = binary.BigEndian.Uint64(in[8:16])
Expand All @@ -138,7 +135,6 @@ func (z *Int) SetBytes24(in []byte) *Int {

func (z *Int) SetBytes32(in []byte) *Int {
_ = in[31] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = binary.BigEndian.Uint64(in[0:8])
z[2] = binary.BigEndian.Uint64(in[8:16])
z[1] = binary.BigEndian.Uint64(in[16:24])
Expand All @@ -147,20 +143,21 @@ func (z *Int) SetBytes32(in []byte) *Int {
}

func (z *Int) SetBytes1(in []byte) *Int {
z[3], z[2], z[1], z[0] = 0, 0, 0, uint64(in[0])
z[3], z[2], z[1] = 0, 0, 0
z[0] = uint64(in[0])
return z
}

func (z *Int) SetBytes9(in []byte) *Int {
_ = in[8] // bounds check hint to compiler; see golang.org/issue/14808

z[3], z[2], z[1], z[0] = 0, 0, uint64(in[0]), binary.BigEndian.Uint64(in[1:9])
z[3], z[2] = 0, 0
z[1] = uint64(in[0])
z[0] = binary.BigEndian.Uint64(in[1:9])
return z
}

func (z *Int) SetBytes17(in []byte) *Int {
_ = in[16] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = uint64(in[0])
z[1] = binary.BigEndian.Uint64(in[1:9])
Expand All @@ -170,7 +167,6 @@ func (z *Int) SetBytes17(in []byte) *Int {

func (z *Int) SetBytes25(in []byte) *Int {
_ = in[24] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = uint64(in[0])
z[2] = binary.BigEndian.Uint64(in[1:9])
z[1] = binary.BigEndian.Uint64(in[9:17])
Expand All @@ -180,27 +176,21 @@ func (z *Int) SetBytes25(in []byte) *Int {

func (z *Int) SetBytes2(in []byte) *Int {
_ = in[1] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = uint64(binary.BigEndian.Uint16(in[0:2]))
return z
}

func (z *Int) SetBytes10(in []byte) *Int {
_ = in[9] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = uint64(binary.BigEndian.Uint16(in[0:2]))
z[0] = binary.BigEndian.Uint64(in[2:10])
return z
}

func (z *Int) SetBytes18(in []byte) *Int {
_ = in[17] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = uint64(binary.BigEndian.Uint16(in[0:2]))
z[1] = binary.BigEndian.Uint64(in[2:10])
Expand All @@ -210,7 +200,6 @@ func (z *Int) SetBytes18(in []byte) *Int {

func (z *Int) SetBytes26(in []byte) *Int {
_ = in[25] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = uint64(binary.BigEndian.Uint16(in[0:2]))
z[2] = binary.BigEndian.Uint64(in[2:10])
z[1] = binary.BigEndian.Uint64(in[10:18])
Expand All @@ -220,25 +209,21 @@ func (z *Int) SetBytes26(in []byte) *Int {

func (z *Int) SetBytes3(in []byte) *Int {
_ = in[2] // bounds check hint to compiler; see golang.org/issue/14808
z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
return z
}

func (z *Int) SetBytes11(in []byte) *Int {
_ = in[10] // bounds check hint to compiler; see golang.org/issue/14808
z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
z[0] = binary.BigEndian.Uint64(in[3:11])
return z
}

func (z *Int) SetBytes19(in []byte) *Int {
_ = in[18] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
z[1] = binary.BigEndian.Uint64(in[3:11])
Expand All @@ -248,7 +233,6 @@ func (z *Int) SetBytes19(in []byte) *Int {

func (z *Int) SetBytes27(in []byte) *Int {
_ = in[26] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = uint64(binary.BigEndian.Uint16(in[1:3])) | uint64(in[0])<<16
z[2] = binary.BigEndian.Uint64(in[3:11])
z[1] = binary.BigEndian.Uint64(in[11:19])
Expand All @@ -258,27 +242,21 @@ func (z *Int) SetBytes27(in []byte) *Int {

func (z *Int) SetBytes4(in []byte) *Int {
_ = in[3] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = uint64(binary.BigEndian.Uint32(in[0:4]))
return z
}

func (z *Int) SetBytes12(in []byte) *Int {
_ = in[11] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = uint64(binary.BigEndian.Uint32(in[0:4]))
z[0] = binary.BigEndian.Uint64(in[4:12])
return z
}

func (z *Int) SetBytes20(in []byte) *Int {
_ = in[19] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = uint64(binary.BigEndian.Uint32(in[0:4]))
z[1] = binary.BigEndian.Uint64(in[4:12])
Expand All @@ -288,7 +266,6 @@ func (z *Int) SetBytes20(in []byte) *Int {

func (z *Int) SetBytes28(in []byte) *Int {
_ = in[27] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = uint64(binary.BigEndian.Uint32(in[0:4]))
z[2] = binary.BigEndian.Uint64(in[4:12])
z[1] = binary.BigEndian.Uint64(in[12:20])
Expand All @@ -298,27 +275,21 @@ func (z *Int) SetBytes28(in []byte) *Int {

func (z *Int) SetBytes5(in []byte) *Int {
_ = in[4] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = bigEndianUint40(in[0:5])
return z
}

func (z *Int) SetBytes13(in []byte) *Int {
_ = in[12] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = bigEndianUint40(in[0:5])
z[0] = binary.BigEndian.Uint64(in[5:13])
return z
}

func (z *Int) SetBytes21(in []byte) *Int {
_ = in[20] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = bigEndianUint40(in[0:5])
z[1] = binary.BigEndian.Uint64(in[5:13])
Expand All @@ -328,7 +299,6 @@ func (z *Int) SetBytes21(in []byte) *Int {

func (z *Int) SetBytes29(in []byte) *Int {
_ = in[23] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = bigEndianUint40(in[0:5])
z[2] = binary.BigEndian.Uint64(in[5:13])
z[1] = binary.BigEndian.Uint64(in[13:21])
Expand All @@ -338,27 +308,21 @@ func (z *Int) SetBytes29(in []byte) *Int {

func (z *Int) SetBytes6(in []byte) *Int {
_ = in[5] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = bigEndianUint48(in[0:6])
return z
}

func (z *Int) SetBytes14(in []byte) *Int {
_ = in[13] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = bigEndianUint48(in[0:6])
z[0] = binary.BigEndian.Uint64(in[6:14])
return z
}

func (z *Int) SetBytes22(in []byte) *Int {
_ = in[21] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = bigEndianUint48(in[0:6])
z[1] = binary.BigEndian.Uint64(in[6:14])
Expand All @@ -368,7 +332,6 @@ func (z *Int) SetBytes22(in []byte) *Int {

func (z *Int) SetBytes30(in []byte) *Int {
_ = in[29] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = bigEndianUint48(in[0:6])
z[2] = binary.BigEndian.Uint64(in[6:14])
z[1] = binary.BigEndian.Uint64(in[14:22])
Expand All @@ -378,27 +341,21 @@ func (z *Int) SetBytes30(in []byte) *Int {

func (z *Int) SetBytes7(in []byte) *Int {
_ = in[6] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[1] = 0
z[3], z[2], z[1] = 0, 0, 0
z[0] = bigEndianUint56(in[0:7])
return z
}

func (z *Int) SetBytes15(in []byte) *Int {
_ = in[14] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = 0
z[3], z[2] = 0, 0
z[1] = bigEndianUint56(in[0:7])
z[0] = binary.BigEndian.Uint64(in[7:15])
return z
}

func (z *Int) SetBytes23(in []byte) *Int {
_ = in[22] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = 0
z[2] = bigEndianUint56(in[0:7])
z[1] = binary.BigEndian.Uint64(in[7:15])
Expand All @@ -408,7 +365,6 @@ func (z *Int) SetBytes23(in []byte) *Int {

func (z *Int) SetBytes31(in []byte) *Int {
_ = in[30] // bounds check hint to compiler; see golang.org/issue/14808

z[3] = bigEndianUint56(in[0:7])
z[2] = binary.BigEndian.Uint64(in[7:15])
z[1] = binary.BigEndian.Uint64(in[15:23])
Expand Down

0 comments on commit cf7da23

Please sign in to comment.