Skip to content

Commit a0526da

Browse files
authored
refactor: use slices.Equal to simplify code (#5635)
Signed-off-by: linghuying <1599935829@qq.com>
1 parent 516fa2d commit a0526da

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

services/horizon/internal/actions/orderbook.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package actions
22

33
import (
44
"net/http"
5+
"slices"
56

67
protocol "github.com/stellar/go/protocols/horizon"
78
"github.com/stellar/go/services/horizon/internal/context"
@@ -23,20 +24,6 @@ type OrderBookResponse struct {
2324
protocol.OrderBookSummary
2425
}
2526

26-
func priceLevelsEqual(a, b []protocol.PriceLevel) bool {
27-
if len(a) != len(b) {
28-
return false
29-
}
30-
31-
for i := range a {
32-
if a[i] != b[i] {
33-
return false
34-
}
35-
}
36-
37-
return true
38-
}
39-
4027
// Equals returns true if the OrderBookResponse is equal to `other`
4128
func (o OrderBookResponse) Equals(other StreamableObjectResponse) bool {
4229
otherOrderBook, ok := other.(OrderBookResponse)
@@ -45,8 +32,8 @@ func (o OrderBookResponse) Equals(other StreamableObjectResponse) bool {
4532
}
4633
return otherOrderBook.Selling == o.Selling &&
4734
otherOrderBook.Buying == o.Buying &&
48-
priceLevelsEqual(otherOrderBook.Bids, o.Bids) &&
49-
priceLevelsEqual(otherOrderBook.Asks, o.Asks)
35+
slices.Equal(otherOrderBook.Bids, o.Bids) &&
36+
slices.Equal(otherOrderBook.Asks, o.Asks)
5037
}
5138

5239
var invalidOrderBook = problem.P{

0 commit comments

Comments
 (0)