Skip to content

Commit

Permalink
use memcpy() instead of memmove() if data doesn't overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Guzzo committed Apr 13, 2014
1 parent ed353ca commit e6ba756
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/iomux.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,19 +883,19 @@ iomux_run(iomux_t *iomux, struct timeval *tv_default)
continue;

if (len) {
memmove(iomux->connections[i]->outbuf + iomux->connections[i]->outlen, data, len);
memcpy(iomux->connections[i]->outbuf + iomux->connections[i]->outlen, data, len);
iomux->connections[i]->outlen += len;
memcpy(&iomux->events[n], &iomux->connections[i]->event, 2 * sizeof(struct kevent));
n += 2;
} else {
memmove(&iomux->events[n], &iomux->connections[i]->event, sizeof(struct kevent));
memcpy(&iomux->events[n], &iomux->connections[i]->event, sizeof(struct kevent));
n++;
}
} else if (iomux->connections[i]->outlen) {
memmove(&iomux->events[n], &iomux->connections[i]->event, 2 * sizeof(struct kevent));
memcpy(&iomux->events[n], &iomux->connections[i]->event, 2 * sizeof(struct kevent));
n += 2;
} else {
memmove(&iomux->events[n], &iomux->connections[i]->event, sizeof(struct kevent));
memcpy(&iomux->events[n], &iomux->connections[i]->event, sizeof(struct kevent));
n++;
}
}
Expand Down Expand Up @@ -986,7 +986,7 @@ iomux_run(iomux_t *iomux, struct timeval *tv_default)
continue;

if (len) {
memmove(iomux->connections[i]->outbuf + iomux->connections[i]->outlen, data, len);
memcpy(iomux->connections[i]->outbuf + iomux->connections[i]->outlen, data, len);
iomux->connections[i]->outlen += len;
}
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ iomux_run(iomux_t *iomux, struct timeval *tv_default)
continue;

if (len) {
memmove(iomux->connections[fd]->outbuf + iomux->connections[fd]->outlen, data, len);
memcpy(iomux->connections[fd]->outbuf + iomux->connections[fd]->outlen, data, len);
iomux->connections[fd]->outlen += len;
}
}
Expand Down

2 comments on commit e6ba756

@dgryski
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark please :P. I'm of the camp that you should just always use memmove and let libc have the three asm instructions to determine if the blocks overlap and which implementation to dispatch to. Having a single code path is also simpler.

@xant
Copy link
Owner

@xant xant commented on e6ba756 Apr 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well they don't overlap there... memmove was used in the previous implementation and I just left it there.
For what it's doing sounds more natural to use memcpy() instead of memmove() ... performances are exactly the same from what I've seen
(AKA: it's irrelevant)

Please sign in to comment.