velorek1 / c-edit

A text editor in C with drop down menus from scratch. No ncurses.
MIT License
250 stars 18 forks source link

Optimize create_screen #10

Closed Maato closed 2 months ago

Maato commented 2 months ago

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).

velorek1 commented 2 months ago

Wow! nicely spot :) It does significantly increase editor's speed. I will merge it right away. Thanks for taking the time to check it.