Add more optimizations.

This commit is contained in:
Nicolás A. Ortega 2016-12-10 00:50:23 +01:00
parent d757f3a79f
commit 4905391c82
No known key found for this signature in database
GPG Key ID: 614272579C2070D1
2 changed files with 5 additions and 4 deletions

View File

@ -25,7 +25,7 @@ void deInitList(List *l) {
} }
void addToList(List *l, mpz_t n) { void addToList(List *l, mpz_t n) {
if(l->end == l->size) { if(unlikely(l->end == l->size)) {
l->size += BLOCK_SIZE; l->size += BLOCK_SIZE;
if(unlikely(l->size == 0)) { if(unlikely(l->size == 0)) {
fprintf(stderr, fprintf(stderr,
@ -33,7 +33,7 @@ void addToList(List *l, mpz_t n) {
exit(1); exit(1);
} }
void *tmp = realloc(l->list, sizeof(mpz_t) * l->size); 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"); fprintf(stderr, "Failed to allocate more memory to list!\n");
exit(1); exit(1);
} }

View File

@ -5,6 +5,7 @@
#include <gmp.h> #include <gmp.h>
#include "list.h" #include "list.h"
#include "optimizers.h"
static bool run; static bool run;
void leave(); void leave();
@ -27,7 +28,7 @@ int main(void) {
// Add 2, a known prime to this list // Add 2, a known prime to this list
mpz_set_ui(num, 2); mpz_set_ui(num, 2);
addToList(&primes, num); 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"); fprintf(stderr, "Could not print to `stdout'!\n");
exit(1); exit(1);
} }
@ -43,7 +44,7 @@ int main(void) {
// `num' is a prime so we add it to the list and print it // `num' is a prime so we add it to the list and print it
addToList(&primes, num); 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"); fprintf(stderr, "Could not print to `stdout'!\n");
exit(1); exit(1);
} }