From e5df35713a32ba708d96ec3fe862eb047b059769 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 2 May 2018 10:10:59 +0300 Subject: [PATCH] Little tweaks to make gcc compile this the faster way. On master, gcc compiles this into a call to memcpy(), but on the branch, it compiled it into a "rep movsq". Turns out that memcpy() is faster. Move things around a little bit, so that we get the faster memcpy() version. --- src/backend/utils/sort/logtape.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c index 891a663d31..789dc2dec1 100644 --- a/src/backend/utils/sort/logtape.c +++ b/src/backend/utils/sort/logtape.c @@ -625,7 +625,10 @@ LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size) Assert(lt->buffer_size == BLCKSZ); while (size > 0) { - if (lt->pos >= TapeBlockPayloadSize) + int bufleft; + + bufleft = TapeBlockPayloadSize - lt->pos; + if (bufleft == 0) { /* Buffer full, dump it out */ long nextBlockNumber; @@ -646,18 +649,16 @@ LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size) lt->curBlockNumber = nextBlockNumber; lt->pos = 0; lt->nbytes = 0; + bufleft = TapeBlockPayloadSize; } - nthistime = TapeBlockPayloadSize - lt->pos; - if (nthistime > size) - nthistime = size; + nthistime = Min(bufleft, size); Assert(nthistime > 0); memcpy(lt->buffer + lt->pos, ptr, nthistime); lt->pos += nthistime; - if (lt->nbytes < lt->pos) - lt->nbytes = lt->pos; + lt->nbytes = lt->pos; ptr = (void *) ((char *) ptr + nthistime); size -= nthistime; } -- 2.39.5