diff mbox series

[GSoC,1/6] reftable: clean up reftable/pq.c

Message ID 20240606075601.6989-2-chandrapratap3519@gmail.com (mailing list archive)
State Superseded
Headers show
Series t: port reftable/pq_test.c to the unit testing | expand

Commit Message

Chandra Pratap June 6, 2024, 7:40 a.m. UTC
According to Documentation/CodingGuidelines, control-flow statements
with a single line as their body must omit curly braces. Make
reftable/pq.c conform to this guideline. Besides that, remove
unnecessary newlines and variable assignment.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
 reftable/pq.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Comments

Christian Couder June 6, 2024, 8:51 a.m. UTC | #1
On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap
<chandrapratap3519@gmail.com> wrote:
>
> According to Documentation/CodingGuidelines, control-flow statements
> with a single line as their body must omit curly braces. Make
> reftable/pq.c conform to this guideline. Besides that, remove
> unnecessary newlines and variable assignment.

A commit subject like "reftable/pq: remove unnecessary curly braces"
might be a bit more specific.
Chandra Pratap June 6, 2024, 10:07 a.m. UTC | #2
On Thu, 6 Jun 2024 at 14:21, Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap
> <chandrapratap3519@gmail.com> wrote:
> >
> > According to Documentation/CodingGuidelines, control-flow statements
> > with a single line as their body must omit curly braces. Make
> > reftable/pq.c conform to this guideline. Besides that, remove
> > unnecessary newlines and variable assignment.
>
> A commit subject like "reftable/pq: remove unnecessary curly braces"
> might be a bit more specific.

There are other forms of cleanup also being performed, like removing
unnecessary newlines and variable assignment. Would it still be okay
to sweep it all under 'removing unnecessary braces'?
Christian Couder June 6, 2024, 4:23 p.m. UTC | #3
On Thu, Jun 6, 2024 at 12:07 PM Chandra Pratap
<chandrapratap3519@gmail.com> wrote:
>
> On Thu, 6 Jun 2024 at 14:21, Christian Couder
> <christian.couder@gmail.com> wrote:
> >
> > On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap
> > <chandrapratap3519@gmail.com> wrote:
> > >
> > > According to Documentation/CodingGuidelines, control-flow statements
> > > with a single line as their body must omit curly braces. Make
> > > reftable/pq.c conform to this guideline. Besides that, remove
> > > unnecessary newlines and variable assignment.
> >
> > A commit subject like "reftable/pq: remove unnecessary curly braces"
> > might be a bit more specific.
>
> There are other forms of cleanup also being performed, like removing
> unnecessary newlines and variable assignment. Would it still be okay
> to sweep it all under 'removing unnecessary braces'?

I think the removal of unnecessary braces is the main change and other
changes are made while at it, so I think it's Ok.
diff mbox series

Patch

diff --git a/reftable/pq.c b/reftable/pq.c
index 7fb45d8c60..0401c47068 100644
--- a/reftable/pq.c
+++ b/reftable/pq.c
@@ -27,22 +27,16 @@  struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
 	pq->heap[0] = pq->heap[pq->len - 1];
 	pq->len--;
 
-	i = 0;
 	while (i < pq->len) {
 		int min = i;
 		int j = 2 * i + 1;
 		int k = 2 * i + 2;
-		if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {
+		if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))
 			min = j;
-		}
-		if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {
+		if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))
 			min = k;
-		}
-
-		if (min == i) {
+		if (min == i)
 			break;
-		}
-
 		SWAP(pq->heap[i], pq->heap[min]);
 		i = min;
 	}
@@ -53,19 +47,15 @@  struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
 void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)
 {
 	int i = 0;
-
 	REFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);
 	pq->heap[pq->len++] = *e;
 
 	i = pq->len - 1;
 	while (i > 0) {
 		int j = (i - 1) / 2;
-		if (pq_less(&pq->heap[j], &pq->heap[i])) {
+		if (pq_less(&pq->heap[j], &pq->heap[i]))
 			break;
-		}
-
 		SWAP(pq->heap[j], pq->heap[i]);
-
 		i = j;
 	}
 }