mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 16:06:37 +01:00
Merge pull request #18 from taiyu-len/master
list_insert now works as it should
This commit is contained in:
commit
fe9037ace3
1 changed files with 13 additions and 11 deletions
24
sway/list.c
24
sway/list.c
|
@ -11,6 +11,13 @@ list_t *create_list(void) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void list_resize(list_t *list) {
|
||||||
|
if (list->length == list->capacity) {
|
||||||
|
list->capacity += 10;
|
||||||
|
list->items = realloc(list->items, sizeof(void*) * list->capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void list_free(list_t *list) {
|
void list_free(list_t *list) {
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -20,25 +27,20 @@ void list_free(list_t *list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_add(list_t *list, void *item) {
|
void list_add(list_t *list, void *item) {
|
||||||
if (list->length == list->capacity) {
|
list_resize(list);
|
||||||
list->capacity += 10;
|
|
||||||
list->items = realloc(list->items, sizeof(void*) * list->capacity);
|
|
||||||
}
|
|
||||||
list->items[list->length++] = item;
|
list->items[list->length++] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_insert(list_t *list, int index, void *item) {
|
void list_insert(list_t *list, int index, void *item) {
|
||||||
// TODO: Implement this properly
|
list_resize(list);
|
||||||
if (list->length == list->capacity) {
|
memmove(&list->items[index + 1], &list->items[index], sizeof(void*) * (list->length - index));
|
||||||
list->capacity += 10;
|
list->length++;
|
||||||
list->items = realloc(list->items, sizeof(void*) * list->capacity);
|
list->items[index] = item;
|
||||||
}
|
|
||||||
list->items[list->length++] = item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_del(list_t *list, int index) {
|
void list_del(list_t *list, int index) {
|
||||||
list->length--;
|
list->length--;
|
||||||
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->capacity - index - 1));
|
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_cat(list_t *list, list_t *source) {
|
void list_cat(list_t *list, list_t *source) {
|
||||||
|
|
Loading…
Reference in a new issue