I noticed it took more time than I would expect for c-edit to start up. Looking into it with valgrind --tool=callgrind pointed me to the addend function called from create_screen.
Repeatedly calling addend unnecessarily traverses the linked list a lot of times. Instead call addfront which does not traverse the list.
This changes the time complexity of create_screen from O(n^2) to O(n).
I noticed it took more time than I would expect for c-edit to start up. Looking into it with
valgrind --tool=callgrind
pointed me to theaddend
function called fromcreate_screen
.Repeatedly calling
addend
unnecessarily traverses the linked list a lot of times. Instead calladdfront
which does not traverse the list.This changes the time complexity of
create_screen
from O(n^2) to O(n).