summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2018-05-02 07:10:59 +0000
committerHeikki Linnakangas2018-05-02 11:22:47 +0000
commite5df35713a32ba708d96ec3fe862eb047b059769 (patch)
tree59fe60c7a852790ac5969474663c2da06c159fa5
parent31772f7af8cd890c9ee57a68e3f68378e7c9af68 (diff)
Little tweaks to make gcc compile this the faster way.sort-balanced-merge3
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.
-rw-r--r--src/backend/utils/sort/logtape.c13
1 files 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;
}