Re: Duplicated assignment of slot_name in walsender.c - Mailing list pgsql-hackers
From | Alvaro Herrera |
---|---|
Subject | Re: Duplicated assignment of slot_name in walsender.c |
Date | |
Msg-id | 20151021223616.GG3391@alvherre.pgsql Whole thread Raw |
In response to | Re: Duplicated assignment of slot_name in walsender.c (Andres Freund <andres@anarazel.de>) |
Responses |
Re: Duplicated assignment of slot_name in walsender.c
Re: Duplicated assignment of slot_name in walsender.c |
List | pgsql-hackers |
Andres Freund wrote: > That seems fairly insignificant. For one this is a rather infrequent and > expensive operation, for another every decent compiler can optimize > those away. Note that those duplicate strlen() calls are there in a lot > of places in walsender.c diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index c6043cd..5487cc0 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -762,10 +762,10 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqstatic voidCreateReplicationSlot(CreateReplicationSlotCmd*cmd){ - const char *slot_name; const char *snapshot_name = NULL; char xpos[MAXFNAMELEN]; StringInfoData buf; + int len; Assert(!MyReplicationSlot); @@ -791,14 +791,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) initStringInfo(&output_message); - slot_name = NameStr(MyReplicationSlot->data.name); - if (cmd->kind == REPLICATION_KIND_LOGICAL) { LogicalDecodingContext *ctx; - ctx = CreateInitDecodingContext( - cmd->plugin, NIL, + ctx = CreateInitDecodingContext(cmd->plugin, NIL, logical_read_xlog_page, WalSndPrepareWrite, WalSndWriteData); @@ -834,7 +831,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) ReplicationSlotSave(); } - slot_name = NameStr(MyReplicationSlot->data.name); snprintf(xpos, sizeof(xpos), "%X/%X", (uint32) (MyReplicationSlot->data.confirmed_flush>> 32), (uint32) MyReplicationSlot->data.confirmed_flush); @@ -885,18 +881,21 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) pq_sendint(&buf, 4, 2); /* # of columns*/ /* slot_name */ - pq_sendint(&buf, strlen(slot_name), 4); /* col1 len */ - pq_sendbytes(&buf, slot_name, strlen(slot_name)); + len = strlen(NameStr(MyReplicationSlot->data.name)); + pq_sendint(&buf, len, 4); /* col1 len */ + pq_sendbytes(&buf, NameStr(MyReplicationSlot->data.name), len); /* consistent wal location */ - pq_sendint(&buf, strlen(xpos), 4); /* col2 len */ - pq_sendbytes(&buf, xpos, strlen(xpos)); + len = strlen(xpos); + pq_sendint(&buf, len, 4); /* col2 len */ + pq_sendbytes(&buf, xpos, len); /* snapshot name */ if (snapshot_name != NULL) { - pq_sendint(&buf, strlen(snapshot_name), 4); /* col3 len */ - pq_sendbytes(&buf, snapshot_name, strlen(snapshot_name)); + len = strlen(snapshot_name); + pq_sendint(&buf, len, 4); /* col3 len */ + pq_sendbytes(&buf, snapshot_name, len); } else pq_sendint(&buf, -1, 4); /* col3 len, NULL */ @@ -904,8 +903,9 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) /* plugin */ if (cmd->plugin != NULL) { - pq_sendint(&buf, strlen(cmd->plugin), 4); /* col4 len */ - pq_sendbytes(&buf, cmd->plugin, strlen(cmd->plugin)); + len = strlen(cmd->plugin); + pq_sendint(&buf, len, 4); /* col4 len */ + pq_sendbytes(&buf, cmd->plugin, len); } else pq_sendint(&buf, -1, 4); /* col4 len, NULL */ -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
pgsql-hackers by date: