commit 5d39da4638130a3168d79bb4f76f8d877e3c1674
parent 4e67c25846e9bbe88b960d236fcc2f798fae7b66
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date: Fri, 18 Sep 2020 15:39:33 +0200
simplified the likely to be taken path
Diffstat:
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -216,14 +216,34 @@ int main(int argc, char *argv[])
fprintf( stdout, "updates screen every %zu nano seconds (10^-9)\n", timer.tv_nsec );
- while( -1 != nanosleep( &timer, NULL ) )
+ //unlikely case
+ if( SDL_MUSTLOCK( screen ) )
{
- if( SDL_MUSTLOCK( screen ) && -1 == SDL_LockSurface( screen ) )
+ fprintf( stdout, "using locks\n" );
+ while( -1 != nanosleep( &timer, NULL ) )
{
- fprintf( stderr, "lock screen: %s.\n", SDL_GetError() );
- exit( EXIT_FAILURE );
+ if( -1 == SDL_LockSurface( screen ) )
+ {
+ fprintf( stderr, "lock screen: %s.\n", SDL_GetError() );
+ exit( EXIT_FAILURE );
+ }
+
+ uint8_t const* srcy = fbsim.mem;
+ uint8_t * dsty = screen->pixels;
+ for( ; srcy < endsrcy; srcy += srcw, dsty += scanline )
+ {
+ memcpy( dsty, srcy, srcw );
+ }
+
+ SDL_UnlockSurface( screen );
+ SDL_Flip( screen );
}
+ exit( EXIT_SUCCESS );
+ }
+ //most likely case
+ while( -1 != nanosleep( &timer, NULL ) )
+ {
uint8_t const* srcy = fbsim.mem;
uint8_t * dsty = screen->pixels;
for( ; srcy < endsrcy; srcy += srcw, dsty += scanline )
@@ -231,11 +251,6 @@ int main(int argc, char *argv[])
memcpy( dsty, srcy, srcw );
}
- if( SDL_MUSTLOCK( screen ) )
- {
- SDL_UnlockSurface( screen );
- }
-
SDL_Flip( screen );
}
exit( EXIT_SUCCESS );