mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-26 02:50:26 +00:00
Fix: faster item swapping
This commit is contained in:
parent
c1cc1ed852
commit
540a68a456
12
src/list.c
12
src/list.c
@ -55,7 +55,6 @@ struct node *list_node_at(const struct list *l, unsigned index) {
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int list_swap_item(struct node *n1, struct node *n2) {
|
int list_swap_item(struct node *n1, struct node *n2) {
|
||||||
if (n1 == n2)
|
if (n1 == n2)
|
||||||
return 1;
|
return 1;
|
||||||
@ -64,19 +63,14 @@ int list_swap_item(struct node *n1, struct node *n2) {
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int value = n2->value;
|
int value = n2->value;
|
||||||
char *data = strdup(n2->data);
|
char *data = n2->data;
|
||||||
|
|
||||||
n2->value = n1->value;
|
n2->value = n1->value;
|
||||||
n2->data = realloc(n2->data, strlen(n1->data) + 1);
|
n2->data = n1->data;
|
||||||
if (n2->data)
|
|
||||||
strcpy(n2->data, n1->data);
|
|
||||||
|
|
||||||
n1->value = value;
|
n1->value = value;
|
||||||
n1->data = realloc(n1->data, strlen(data) + 1);
|
n1->data = data;
|
||||||
if (n1->data)
|
|
||||||
strcpy(n1->data, data);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user