From 1ca3d027dee0c693265a2d4519ee6c7ebef6fd1c Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Wed, 30 Dec 2015 17:44:48 +0100 Subject: Reduce amount of stat(2) calls Add 8-bit variable that is passed to imv_navigator_poll_changed(). Decrement it on each run of main loop. When it gets to 0, call stat(2). --- src/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 5e78017..6150558 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include +#include #include #include #include @@ -310,6 +311,9 @@ int main(int argc, char** argv) unsigned int last_time; unsigned int current_time; + /* keep file change polling rate under control */ + static uint8_t poll_countdown = UINT8_MAX; + /* do we need to redraw the window? */ int need_redraw = 1; @@ -434,7 +438,7 @@ int main(int argc, char** argv) } /* if the user has changed image, start loading the new one */ - if(imv_navigator_poll_changed(&nav)) { + if(imv_navigator_poll_changed(&nav, poll_countdown--)) { const char *current_path = imv_navigator_selection(&nav); if(!current_path) { fprintf(stderr, "No input files left. Exiting.\n"); @@ -476,7 +480,7 @@ int main(int argc, char** argv) } /* handle slideshow */ - if (g_options.delay) { + if(g_options.delay) { unsigned int dt = current_time - last_time; delay_mseconds_passed += dt; @@ -560,6 +564,9 @@ int main(int argc, char** argv) /* redraw complete, unset the flag */ need_redraw = 0; + /* reset poll countdown timer */ + poll_countdown = UINT8_MAX; + /* tell SDL to show the newly drawn frame */ SDL_RenderPresent(renderer); } -- cgit v1.2.3