Skip to content

Commit

Permalink
Decrease indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed May 26, 2015
1 parent bf5ee04 commit 60b36d0
Showing 1 changed file with 65 additions and 72 deletions.
137 changes: 65 additions & 72 deletions extension/boolexpr/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,89 +22,84 @@ struct BoolExpr * _op_transform(struct BoolExpr *op, struct BoolExpr * (*fn)(str
static struct BoolExpr *
_commutative_binify(struct BoolExpr *op)
{
if (op->data.xs->length == 2) {
if (op->data.xs->length == 2)
return BoolExpr_IncRef(op);

size_t mid = op->data.xs->length / 2;
size_t n0 = mid;
size_t n1 = op->data.xs->length - mid;
struct BoolExpr **items0 = op->data.xs->items;
struct BoolExpr **items1 = op->data.xs->items + mid;
struct BoolExpr *xs[2];
struct BoolExpr *temp;
struct BoolExpr *y;

if (n0 == 1) {
xs[0] = BoolExpr_IncRef(items0[0]);
}
else {
size_t mid = op->data.xs->length / 2;
size_t n0 = mid;
size_t n1 = op->data.xs->length - mid;
struct BoolExpr **items0 = op->data.xs->items;
struct BoolExpr **items1 = op->data.xs->items + mid;
struct BoolExpr *xs[2];
struct BoolExpr *temp;
struct BoolExpr *y;

if (n0 == 1) {
xs[0] = BoolExpr_IncRef(items0[0]);
}
else {
CHECK_NULL(temp, _op_new(op->kind, n0, items0));
CHECK_NULL_1(xs[0], _commutative_binify(temp), temp);
BoolExpr_DecRef(temp);
}

CHECK_NULL_1(temp, _op_new(op->kind, n1, items1), xs[0]);
CHECK_NULL_2(xs[1], _commutative_binify(temp), xs[0], temp);
CHECK_NULL(temp, _op_new(op->kind, n0, items0));
CHECK_NULL_1(xs[0], _commutative_binify(temp), temp);
BoolExpr_DecRef(temp);
}

CHECK_NULL_2(y, _op_new(op->kind, 2, xs), xs[0], xs[1]);
BoolExpr_DecRef(xs[0]);
BoolExpr_DecRef(xs[1]);
CHECK_NULL_1(temp, _op_new(op->kind, n1, items1), xs[0]);
CHECK_NULL_2(xs[1], _commutative_binify(temp), xs[0], temp);
BoolExpr_DecRef(temp);

return y;
}
CHECK_NULL_2(y, _op_new(op->kind, 2, xs), xs[0], xs[1]);
BoolExpr_DecRef(xs[0]);
BoolExpr_DecRef(xs[1]);

return y;
}


static struct BoolExpr *
_eq_binify(struct BoolExpr *op)
{
if (op->data.xs->length == 2) {
if (op->data.xs->length == 2)
return BoolExpr_IncRef(op);
}
else {
size_t length;
struct BoolExpr **xs;
struct BoolExpr *temp;
struct BoolExpr *y;

length = (op->data.xs->length * (op->data.xs->length - 1)) >> 1;
xs = (struct BoolExpr **) malloc(length * sizeof(struct BoolExpr *));

for (size_t i = 0, index = 0; i < (op->data.xs->length - 1); ++i) {
for (size_t j = i+1; j < op->data.xs->length; ++j, ++index) {
xs[index] = EqualN(2, op->data.xs->items[i],
op->data.xs->items[j]);
if (xs[index] == NULL) {
/* LCOV_EXCL_START */
for (size_t k = 0; k < index; ++k)
BoolExpr_DecRef(xs[k]);
free(xs);
return NULL;
/* LCOV_EXCL_STOP */
}
}
}

temp = And(length, xs);
if (temp == NULL) {
/* LCOV_EXCL_START */
for (size_t i = 0; i < length; ++i)
BoolExpr_DecRef(xs[i]);
free(xs);
/* LCOV_EXCL_STOP */
size_t length;
struct BoolExpr **xs;
struct BoolExpr *temp;
struct BoolExpr *y;

length = (op->data.xs->length * (op->data.xs->length - 1)) >> 1;
xs = (struct BoolExpr **) malloc(length * sizeof(struct BoolExpr *));

for (size_t i = 0, index = 0; i < (op->data.xs->length - 1); ++i) {
for (size_t j = i+1; j < op->data.xs->length; ++j, ++index) {
xs[index] = EqualN(2, op->data.xs->items[i], op->data.xs->items[j]);
if (xs[index] == NULL) {
/* LCOV_EXCL_START */
for (size_t k = 0; k < index; ++k)
BoolExpr_DecRef(xs[k]);
free(xs);
return NULL;
/* LCOV_EXCL_STOP */
}
}
}

temp = And(length, xs);
if (temp == NULL) {
/* LCOV_EXCL_START */
for (size_t i = 0; i < length; ++i)
BoolExpr_DecRef(xs[i]);
free(xs);
/* LCOV_EXCL_STOP */
}

CHECK_NULL_1(y, _commutative_binify(temp), temp);
BoolExpr_DecRef(temp);
for (size_t i = 0; i < length; ++i)
BoolExpr_DecRef(xs[i]);
free(xs);

return y;
}
CHECK_NULL_1(y, _commutative_binify(temp), temp);
BoolExpr_DecRef(temp);

return y;
}


Expand Down Expand Up @@ -134,18 +129,16 @@ static struct BoolExpr * (*_op_binify[16])(struct BoolExpr *ex) = {
struct BoolExpr *
BoolExpr_ToBinary(struct BoolExpr *ex)
{
if (IS_ATOM(ex)) {
if (IS_ATOM(ex))
return BoolExpr_IncRef(ex);
}
else {
struct BoolExpr *temp;
struct BoolExpr *y;

CHECK_NULL(temp, _op_transform(ex, BoolExpr_ToBinary));
CHECK_NULL_1(y, _op_binify[temp->kind](temp), temp);
BoolExpr_DecRef(temp);
struct BoolExpr *temp;
struct BoolExpr *y;

return y;
}
CHECK_NULL(temp, _op_transform(ex, BoolExpr_ToBinary));
CHECK_NULL_1(y, _op_binify[temp->kind](temp), temp);
BoolExpr_DecRef(temp);

return y;
}

0 comments on commit 60b36d0

Please sign in to comment.