blob: c646855dfcd4538699dc1fa408d269b8944ec839 [file] [log] [blame]
#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);
}