From 4905391c8202cb55e1420e10baa75c8d7fea3d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Sat, 10 Dec 2016 00:50:23 +0100 Subject: [PATCH] Add more optimizations. --- src/list.c | 4 ++-- src/main.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/list.c b/src/list.c index de163b3..8801b02 100644 --- a/src/list.c +++ b/src/list.c @@ -25,7 +25,7 @@ void deInitList(List *l) { } void addToList(List *l, mpz_t n) { - if(l->end == l->size) { + if(unlikely(l->end == l->size)) { l->size += BLOCK_SIZE; if(unlikely(l->size == 0)) { fprintf(stderr, @@ -33,7 +33,7 @@ void addToList(List *l, mpz_t n) { exit(1); } void *tmp = realloc(l->list, sizeof(mpz_t) * l->size); - if(!tmp) { + if(unlikely(!tmp)) { fprintf(stderr, "Failed to allocate more memory to list!\n"); exit(1); } diff --git a/src/main.c b/src/main.c index 42a3d67..79404e7 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include "list.h" +#include "optimizers.h" static bool run; void leave(); @@ -27,7 +28,7 @@ int main(void) { // Add 2, a known prime to this list mpz_set_ui(num, 2); addToList(&primes, num); - if(mpz_out_str(stdout, 10, num) == 0) { + if(unlikely(mpz_out_str(stdout, 10, num) == 0)) { fprintf(stderr, "Could not print to `stdout'!\n"); exit(1); } @@ -43,7 +44,7 @@ int main(void) { // `num' is a prime so we add it to the list and print it addToList(&primes, num); - if(mpz_out_str(stdout, 10, num) == 0) { + if(unlikely(mpz_out_str(stdout, 10, num) == 0)) { fprintf(stderr, "Could not print to `stdout'!\n"); exit(1); }