Re: Remove some unnecessary if-condition

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Remove some unnecessary if-condition
Date: 2020-10-12 08:44:03
Message-ID: CAExHW5uqbTH1ktXNYjzW0A6X_7Q+AnbOC-fc-S7HJuEkMdbu_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 9, 2020 at 6:29 AM Hou, Zhijie <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com> wrote:
>
> Hi
>
> I found some likely unnecessary if-condition in code.
>
> 1. Some check in else branch seems unnecessary.
>
> In (/src/backend/replication/logical/reorderbuffer.c)
> ① @@ -4068,7 +4068,7 @@ ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *txn,
> > bool found;
> > if (!found)
> > {
> >...
> > }
> > else if (found && chunk_seq != ent->last_chunk_seq + 1)
> >...
>
> The check of "found" in else if branch seems unnecessary.
>
> ② (/src/backend/utils/init/postinit.c)
> @@ -924,11 +924,8 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
>
> > bool bootstrap = IsBootstrapProcessingMode();
> > if (bootstrap)
> > {
> >...
> > }
> > else if(...)
> > {...}
> > else
> > {
> > if (!bootstrap)
> > {
> > ...
> > }
> > }
>
> The check of "bootstrap" in else branch seems unnecessary.
>
>
> 2.In (/src/interfaces/ecpg/compatlib/informix.c)
> @@ -944,7 +944,7 @@ rupshift(char *str)
>
> > for (len--; str[len] && str[len] == ' '; len--);
>
> The first "str[len]" seems unnecessary since " str[len] == ' '" will check it as well.
>
> Do you think we should remove these if-condition for code clean ?

To me it looks good to clean up the conditions as you have done in the
patch. Please add this to commitfest so that it's not forgotten. I
have verified the code and indeed the conditions you are removing are
unnecessary. So the patch can be marked as CFP right away.

--
Best Wishes,
Ashutosh Bapat

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2020-10-12 08:52:43 Re: Parallel INSERT (INTO ... SELECT ...)
Previous Message Amit Langote 2020-10-12 08:36:48 Re: Wired if-statement in gen_partprune_steps_internal