From cc1dbb5677dda60c317e885ad00d44367053e791 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 4 May 2020 12:13:47 -0700 Subject: [PATCH] channeldb: eliminate extra copy in QueryPayments In this commit, we eliminate an extraneous copy in the `QueryPayments` method. Before this commit, we would copy each payment from the initial FetchPayments call into a new slice. However, pointers to payments are return from `FetchPayments`, so we can just maintain that same reference rather than copying again when we want to limit our response. --- channeldb/payments.go | 4 ++-- rpcserver.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 7c5f49a2..3956dd78 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -460,7 +460,7 @@ type PaymentsQuery struct { type PaymentsResponse struct { // Payments is the set of payments returned from the database for the // PaymentsQuery. - Payments []MPPayment + Payments []*MPPayment // FirstIndexOffset is the index of the first element in the set of // returned MPPayments. Callers can use this to resume their query @@ -536,7 +536,7 @@ func (db *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { continue } - resp.Payments = append(resp.Payments, *payment) + resp.Payments = append(resp.Payments, payment) } // Need to swap the payments slice order if reversed order. diff --git a/rpcserver.go b/rpcserver.go index 05c9fa88..0fbca115 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -5191,7 +5191,7 @@ func (r *rpcServer) ListPayments(ctx context.Context, for _, payment := range paymentsQuerySlice.Payments { payment := payment - rpcPayment, err := r.routerBackend.MarshallPayment(&payment) + rpcPayment, err := r.routerBackend.MarshallPayment(payment) if err != nil { return nil, err }