Simplify if/else logic of walsender CreateReplicationSlot

Started by Peter Smithover 2 years ago4 messageshackers
Jump to latest
#1Peter Smith
smithpb2250@gmail.com

Hi,

While reviewing another patch I was looking at the walsender's static
function CreateReplicationSlot

I found that the current logic seemed to have some unnecessary if/else
checking which can be simplified.

~~

To summarise:

CURRENT
if (cmd->kind == REPLICATION_KIND_PHYSICAL)
{
...
}
else
{
...
}
if (cmd->kind == REPLICATION_KIND_LOGICAL)
{
...
}
else if (cmd->kind == REPLICATION_KIND_PHYSICAL && reserve_wal)
{
...
}

SUGGESTION
if (cmd->kind == REPLICATION_KIND_PHYSICAL)
{
...
if (reserve_wal)
{
...
}
}
else /* REPLICATION_KIND_LOGICAL */
{
...
}

~~~

PSA a small patch for making this change.

(I ran make check-world after this change and it was successful)

======
Kind Regards,
Peter Smith.
Fujitsu Australia

Attachments:

v1-0001-Simplify-if-else-logic-of-walsender-CreateReplica.patchapplication/octet-stream; name=v1-0001-Simplify-if-else-logic-of-walsender-CreateReplica.patchDownload+16-17
#2Michael Paquier
michael@paquier.xyz
In reply to: Peter Smith (#1)
Re: Simplify if/else logic of walsender CreateReplicationSlot

On Mon, Nov 20, 2023 at 06:01:42PM +1100, Peter Smith wrote:

While reviewing another patch I was looking at the walsender's static
function CreateReplicationSlot

I found that the current logic seemed to have some unnecessary if/else
checking which can be simplified.

Good idea. What you are suggesting here improves the readability of
this code, so +1.
--
Michael

#3Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#2)
Re: Simplify if/else logic of walsender CreateReplicationSlot

On Mon, Nov 20, 2023 at 05:07:38PM +0900, Michael Paquier wrote:

Good idea. What you are suggesting here improves the readability of
this code, so +1.

And applied this one, thanks!
--
Michael

#4Peter Smith
smithpb2250@gmail.com
In reply to: Michael Paquier (#3)
Re: Simplify if/else logic of walsender CreateReplicationSlot

On Tue, Nov 21, 2023 at 3:57 PM Michael Paquier <michael@paquier.xyz> wrote:

On Mon, Nov 20, 2023 at 05:07:38PM +0900, Michael Paquier wrote:

Good idea. What you are suggesting here improves the readability of
this code, so +1.

And applied this one, thanks!

Thanks for pushing.

======
Kind Regards,
Peter Smith.
Fujitsu Australia