Commit 90f60f8e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make expire_sources run in linear time.

It's not like it's run that often, but I've got OCD.
parent bb2114ca
...@@ -201,7 +201,7 @@ update_source(struct source *src, ...@@ -201,7 +201,7 @@ update_source(struct source *src,
void void
expire_sources() expire_sources()
{ {
int i = 0; int i = 0, j = 0;
while(i < source_slots) { while(i < source_slots) {
struct source *src = sources[i]; struct source *src = sources[i];
...@@ -211,14 +211,18 @@ expire_sources() ...@@ -211,14 +211,18 @@ expire_sources()
if(src->route_count == 0 && src->time < now.tv_sec - SOURCE_GC_TIME) { if(src->route_count == 0 && src->time < now.tv_sec - SOURCE_GC_TIME) {
free(src); free(src);
memmove(sources + i, sources + i + 1, sources[i] = NULL;
(source_slots - i - 1) * sizeof(struct source*)); i++;
sources[source_slots - 1] = NULL;
source_slots--;
} else { } else {
if(j < i) {
sources[j] = sources[i];
sources[i] = NULL;
}
i++; i++;
j++;
} }
} }
source_slots = j;
} }
void void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment