mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
From: "D'Arcy J.M. Cain" <darcy@druid.net>
Subject: [HACKERS] backend/optimizer/geqo/geqo_erx.c I sent these changes in with a bunch of others. Some were folded in but others, like these, were not. I am not sure why so I am resending this to the developers list by itself for discussion. The readon why I suggest these changes is that the compiler can't tell that minimum_count is initialized before it is used. The tests that I add in here will cause an immediate error if it doesn't. As the comments below suggest, if it is 100% guaranteed that the variable will always be initialized then how this is so should be commented here. I don't know how much strain the actual test puts on the performance but if it isn't too much then maybe leave it in for absolute safety anyway. There are also a few returns just to stop warnings.
This commit is contained in:
parent
a668b7ac2d
commit
f50b103ce1
@ -3,7 +3,7 @@
|
|||||||
* geqo_erx.c--
|
* geqo_erx.c--
|
||||||
* edge recombination crossover [ER]
|
* edge recombination crossover [ER]
|
||||||
*
|
*
|
||||||
* $Id: geqo_erx.c,v 1.1 1997/02/19 12:56:55 scrappy Exp $
|
* $Id: geqo_erx.c,v 1.2 1997/06/06 00:37:23 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -278,7 +278,7 @@ gimme_gene (Edge edge, Edge *edge_table)
|
|||||||
int i;
|
int i;
|
||||||
Gene friend;
|
Gene friend;
|
||||||
int minimum_edges;
|
int minimum_edges;
|
||||||
int minimum_count;
|
int minimum_count = -1;
|
||||||
int rand_decision;
|
int rand_decision;
|
||||||
|
|
||||||
/* no point has edges to more than 4 other points
|
/* no point has edges to more than 4 other points
|
||||||
@ -304,10 +304,19 @@ gimme_gene (Edge edge, Edge *edge_table)
|
|||||||
if there is more than one cadidate with the minimum number
|
if there is more than one cadidate with the minimum number
|
||||||
of unused edges keep count of this number (minimum_count); */
|
of unused edges keep count of this number (minimum_count); */
|
||||||
|
|
||||||
|
/* The test for minimum_count can probably be removed at some
|
||||||
|
point but comments should probably indicate exactly why it
|
||||||
|
is guaranteed that the test will always succeed the first
|
||||||
|
time around. If it can fail then the code is in error */
|
||||||
|
|
||||||
|
|
||||||
if (edge_table[(int) friend].unused_edges < minimum_edges) {
|
if (edge_table[(int) friend].unused_edges < minimum_edges) {
|
||||||
minimum_edges = edge_table[(int) friend].unused_edges;
|
minimum_edges = edge_table[(int) friend].unused_edges;
|
||||||
minimum_count = 1;
|
minimum_count = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if (minimum_count == -1)
|
||||||
|
elog(WARN, "gimme_gene: Internal error - minimum_count not set");
|
||||||
else
|
else
|
||||||
if (edge_table[(int) friend].unused_edges == minimum_edges)
|
if (edge_table[(int) friend].unused_edges == minimum_edges)
|
||||||
minimum_count++;
|
minimum_count++;
|
||||||
@ -332,6 +341,7 @@ gimme_gene (Edge edge, Edge *edge_table)
|
|||||||
|
|
||||||
/* ... should never be reached */
|
/* ... should never be reached */
|
||||||
elog(WARN,"gimme_gene: neither shared nor minimum number nor random edge found");
|
elog(WARN,"gimme_gene: neither shared nor minimum number nor random edge found");
|
||||||
|
return 0; /* to keep the compiler quiet */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* edge_failure--
|
/* edge_failure--
|
||||||
@ -420,5 +430,6 @@ edge_failure (Gene *gene, int index, Edge *edge_table, int num_gene)
|
|||||||
|
|
||||||
/* ... should never be reached */
|
/* ... should never be reached */
|
||||||
elog(WARN,"edge_failure: no edge detected");
|
elog(WARN,"edge_failure: no edge detected");
|
||||||
|
return 0; /* to keep the compiler quiet */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user