Skip to content

Commit 97cd14b

Browse files
committed
common/math: delete some further dead code (ethereum#30639)
1 parent 9d9a1a9 commit 97cd14b

File tree

2 files changed

+0
-132
lines changed

2 files changed

+0
-132
lines changed

common/math/big.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ import (
2323
)
2424

2525
var (
26-
tt255 = BigPow(2, 255)
2726
tt256 = BigPow(2, 256)
2827
tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
2928
MaxBig256 = new(big.Int).Set(tt256m1)
30-
tt63 = BigPow(2, 63)
31-
MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1))
3229
)
3330

3431
const (
@@ -127,16 +124,6 @@ func BigMin(x, y *big.Int) *big.Int {
127124
return x
128125
}
129126

130-
// FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
131-
func FirstBitSet(v *big.Int) int {
132-
for i := 0; i < v.BitLen(); i++ {
133-
if v.Bit(i) > 0 {
134-
return i
135-
}
136-
}
137-
return v.BitLen()
138-
}
139-
140127
// PaddedBigBytes encodes a big integer as a big-endian byte slice. The length
141128
// of the slice is at least n bytes.
142129
func PaddedBigBytes(bigint *big.Int, n int) []byte {
@@ -148,34 +135,6 @@ func PaddedBigBytes(bigint *big.Int, n int) []byte {
148135
return ret
149136
}
150137

151-
// bigEndianByteAt returns the byte at position n,
152-
// in Big-Endian encoding
153-
// So n==0 returns the least significant byte
154-
func bigEndianByteAt(bigint *big.Int, n int) byte {
155-
words := bigint.Bits()
156-
// Check word-bucket the byte will reside in
157-
i := n / wordBytes
158-
if i >= len(words) {
159-
return byte(0)
160-
}
161-
word := words[i]
162-
// Offset of the byte
163-
shift := 8 * uint(n%wordBytes)
164-
165-
return byte(word >> shift)
166-
}
167-
168-
// Byte returns the byte at position n,
169-
// with the supplied padlength in Little-Endian encoding.
170-
// n==0 returns the MSB
171-
// Example: bigint '5', padlength 32, n=31 => 5
172-
func Byte(bigint *big.Int, padlength, n int) byte {
173-
if n >= padlength {
174-
return byte(0)
175-
}
176-
return bigEndianByteAt(bigint, padlength-1-n)
177-
}
178-
179138
// ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure
180139
// that buf has enough space. If buf is too short the result will be incomplete.
181140
func ReadBits(bigint *big.Int, buf []byte) {

common/math/big_test.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"encoding/hex"
2222
"math/big"
2323
"testing"
24-
25-
"github.com/XinFinOrg/XDPoSChain/common"
2624
)
2725

2826
func TestHexOrDecimal256(t *testing.T) {
@@ -100,23 +98,6 @@ func TestBigMin(t *testing.T) {
10098
}
10199
}
102100

103-
func TestFirstBigSet(t *testing.T) {
104-
tests := []struct {
105-
num *big.Int
106-
ix int
107-
}{
108-
{big.NewInt(0), 0},
109-
{big.NewInt(1), 0},
110-
{big.NewInt(2), 1},
111-
{big.NewInt(0x100), 8},
112-
}
113-
for _, test := range tests {
114-
if ix := FirstBitSet(test.num); ix != test.ix {
115-
t.Errorf("FirstBitSet(b%b) = %d, want %d", test.num, ix, test.ix)
116-
}
117-
}
118-
}
119-
120101
func TestPaddedBigBytes(t *testing.T) {
121102
tests := []struct {
122103
num *big.Int
@@ -156,20 +137,6 @@ func BenchmarkPaddedBigBytesSmallOnePadding(b *testing.B) {
156137
}
157138
}
158139

159-
func BenchmarkByteAtBrandNew(b *testing.B) {
160-
bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
161-
for i := 0; i < b.N; i++ {
162-
bigEndianByteAt(bigint, 15)
163-
}
164-
}
165-
166-
func BenchmarkByteAt(b *testing.B) {
167-
bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
168-
for i := 0; i < b.N; i++ {
169-
bigEndianByteAt(bigint, 15)
170-
}
171-
}
172-
173140
func BenchmarkByteAtOld(b *testing.B) {
174141
bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
175142
for i := 0; i < b.N; i++ {
@@ -220,61 +187,3 @@ func TestU256Bytes(t *testing.T) {
220187
t.Errorf("expected %x got %x", ubytes, unsigned)
221188
}
222189
}
223-
224-
func TestBigEndianByteAt(t *testing.T) {
225-
tests := []struct {
226-
x string
227-
y int
228-
exp byte
229-
}{
230-
{"00", 0, 0x00},
231-
{"01", 1, 0x00},
232-
{"00", 1, 0x00},
233-
{"01", 0, 0x01},
234-
{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x30},
235-
{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x20},
236-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0xAB},
237-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
238-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 500, 0x00},
239-
}
240-
for _, test := range tests {
241-
v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
242-
actual := bigEndianByteAt(v, test.y)
243-
if actual != test.exp {
244-
t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
245-
}
246-
}
247-
}
248-
249-
func TestLittleEndianByteAt(t *testing.T) {
250-
tests := []struct {
251-
x string
252-
y int
253-
exp byte
254-
}{
255-
{"00", 0, 0x00},
256-
{"01", 1, 0x00},
257-
{"00", 1, 0x00},
258-
{"01", 0, 0x00},
259-
{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x00},
260-
{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x00},
261-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0x00},
262-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
263-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, 0xAB},
264-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, 0xCD},
265-
{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, 0x00},
266-
{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, 0xCD},
267-
{"0000000000000000000000000000000000000000000000000000000000102030", 31, 0x30},
268-
{"0000000000000000000000000000000000000000000000000000000000102030", 30, 0x20},
269-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, 0x0},
270-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 31, 0xFF},
271-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFF, 0x0},
272-
}
273-
for _, test := range tests {
274-
v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
275-
actual := Byte(v, 32, test.y)
276-
if actual != test.exp {
277-
t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
278-
}
279-
}
280-
}

0 commit comments

Comments
 (0)