blob: 657ae9d33e476a0fbe226681c5dc1b911fae2ca3 [file] [log] [blame]
Matthias Andreas Benkard08586462020-06-28 22:42:43 +02001#include "swap.h"
2
3#include <stdlib.h>
4#include <string.h>
5
6void swap_loop(char* restrict a, char* restrict b, size_t len) {
7 while (len--) {
8 char tmp = *a;
9 *a++ = *b;
10 *b++ = tmp;
11 };
12}
13
14void swap_malloc(char* restrict a, char* restrict b, size_t len) {
15 char *temp = malloc(len);
16 memmove(temp,a,len);
17 memmove(a,b,len);
18 memmove(b,temp,len);
19 free(temp);
20}
21
22void swap_alloca(char* restrict a, char* restrict b, size_t len) {
23 char temp[len];
24 memmove(temp,a,len);
25 memmove(a,b,len);
26 memmove(b,temp,len);
27}