From: Thadeu Lima de Souza Cascardo Date: Wed, 8 Jul 2015 09:48:11 +0000 (+0000) Subject: Pré-calcula o total de rendimentos. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fdeclara.git;a=commitdiff_plain;h=fc0855a07a8ff1e75a9b3441d4be25e451b903d2 Pré-calcula o total de rendimentos. Ao invés de calcular duas vezes, tanto para declaração simples quanto completa, calcula o total de rendimentos uma única vez. --- diff --git a/calcula.c b/calcula.c index a6bac0e..a8accc3 100644 --- a/calcula.c +++ b/calcula.c @@ -23,7 +23,7 @@ #include #include -static long long total_rendimento(struct declaracao *dec) +static void total_rendimento(struct declaracao *dec) { long long tr = 0; struct rendimento *rendimento; @@ -31,7 +31,7 @@ static long long total_rendimento(struct declaracao *dec) for (i = 0; rendimento = list_get(dec->rendimento, i); i++) { tr += rendimento->rendimento; } - return tr; + dec->totalrendimento = tr; } static long long total_deducao(struct declaracao *dec) @@ -86,7 +86,7 @@ static long long imposto_simples(struct declaracao *dec) struct taxtable *tt; long long tr, td; tt = table2015; - tr = total_rendimento(dec); + tr = dec->totalrendimento; dec->totalrendimento = tr; if (tr / 5 < simples2015) td = tr / 5; @@ -104,9 +104,8 @@ static long long imposto_completa(struct declaracao *dec) return -EINVAL; } tt = table2015; - tr = total_rendimento(dec); + tr = dec->totalrendimento; td = total_deducao(dec); - dec->totalrendimento = tr; tr -= td; return imposto(tt, tr); } @@ -117,6 +116,7 @@ int calcula(struct declaracao *dec) if (dec->ano != 2015) { return -EINVAL; } + total_rendimento(dec); i_simples = imposto_simples(dec); i_completa = imposto_completa(dec); total_pago(dec);