#include "swap.h" | |
#include <stdlib.h> | |
#include <string.h> | |
void swap_loop(char* restrict a, char* restrict b, size_t len) { | |
while (len--) { | |
char tmp = *a; | |
*a++ = *b; | |
*b++ = tmp; | |
}; | |
} | |
void swap_malloc(char* restrict a, char* restrict b, size_t len) { | |
char *temp = malloc(len); | |
memmove(temp,a,len); | |
memmove(a,b,len); | |
memmove(b,temp,len); | |
free(temp); | |
} | |
void swap_alloca(char* restrict a, char* restrict b, size_t len) { | |
char temp[len]; | |
memmove(temp,a,len); | |
memmove(a,b,len); | |
memmove(b,temp,len); | |
} |