Clean up some code using "(expr) ? true : false"
All the code paths simplified here were already using a boolean or used an expression that led to zero or one, making the extra bits unnecessary. Author: Justin Pryzby Reviewed-by: Tom Lane, Michael Paquier, Peter Smith Discussion: https://postgr.es/m/20210428182936.GE27406@telsasoft.com
This commit is contained in:
parent
d6c916f020
commit
fd0625c7a9
@ -41,7 +41,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
|
||||
break; /* db[j] is not in da */
|
||||
}
|
||||
|
||||
return (n == nb) ? true : false;
|
||||
return (n == nb);
|
||||
}
|
||||
|
||||
/* arguments are assumed sorted */
|
||||
|
@ -137,7 +137,7 @@ ltree_same(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(result);
|
||||
|
||||
if (LTG_ISONENODE(a))
|
||||
*result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
|
||||
*result = ISEQ(LTG_NODE(a), LTG_NODE(b));
|
||||
else
|
||||
{
|
||||
int32 i;
|
||||
|
@ -615,7 +615,7 @@ static int sepgsql_mode = SEPGSQL_MODE_INTERNAL;
|
||||
bool
|
||||
sepgsql_is_enabled(void)
|
||||
{
|
||||
return (sepgsql_mode != SEPGSQL_MODE_DISABLED ? true : false);
|
||||
return (sepgsql_mode != SEPGSQL_MODE_DISABLED);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -241,7 +241,7 @@ dataIsMoveRight(GinBtree btree, Page page)
|
||||
if (GinPageIsDeleted(page))
|
||||
return true;
|
||||
|
||||
return (ginCompareItemPointers(&btree->itemptr, iptr) > 0) ? true : false;
|
||||
return (ginCompareItemPointers(&btree->itemptr, iptr) > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -100,7 +100,7 @@ initGinState(GinState *state, Relation index)
|
||||
MemSet(state, 0, sizeof(GinState));
|
||||
|
||||
state->index = index;
|
||||
state->oneCol = (origTupdesc->natts == 1) ? true : false;
|
||||
state->oneCol = (origTupdesc->natts == 1);
|
||||
state->origTupdesc = origTupdesc;
|
||||
|
||||
for (i = 0; i < origTupdesc->natts; i++)
|
||||
|
@ -303,9 +303,9 @@ supportSecondarySplit(Relation r, GISTSTATE *giststate, int attno,
|
||||
penalty2 = gistpenalty(giststate, attno, entry1, false, &entrySR, false);
|
||||
|
||||
if (penalty1 < penalty2)
|
||||
leaveOnLeft = (sv->spl_ldatum_exists) ? true : false;
|
||||
leaveOnLeft = sv->spl_ldatum_exists;
|
||||
else
|
||||
leaveOnLeft = (sv->spl_rdatum_exists) ? true : false;
|
||||
leaveOnLeft = sv->spl_rdatum_exists;
|
||||
}
|
||||
|
||||
if (leaveOnLeft == false)
|
||||
|
@ -816,7 +816,7 @@ hashbucketcleanup(Relation rel, Bucket cur_bucket, Buffer bucket_buf,
|
||||
XLogRecPtr recptr;
|
||||
|
||||
xlrec.clear_dead_marking = clear_dead_marking;
|
||||
xlrec.is_primary_bucket_page = (buf == bucket_buf) ? true : false;
|
||||
xlrec.is_primary_bucket_page = (buf == bucket_buf);
|
||||
|
||||
XLogBeginInsert();
|
||||
XLogRegisterData((char *) &xlrec, SizeOfHashDelete);
|
||||
|
@ -176,7 +176,7 @@ restart_insert:
|
||||
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
|
||||
|
||||
/* chain to a new overflow page */
|
||||
buf = _hash_addovflpage(rel, metabuf, buf, (buf == bucket_buf) ? true : false);
|
||||
buf = _hash_addovflpage(rel, metabuf, buf, (buf == bucket_buf));
|
||||
page = BufferGetPage(buf);
|
||||
|
||||
/* should fit now, given test above */
|
||||
|
@ -953,7 +953,7 @@ readpage:
|
||||
xl_hash_move_page_contents xlrec;
|
||||
|
||||
xlrec.ntups = nitups;
|
||||
xlrec.is_prim_bucket_same_wrt = (wbuf == bucket_buf) ? true : false;
|
||||
xlrec.is_prim_bucket_same_wrt = (wbuf == bucket_buf);
|
||||
|
||||
XLogBeginInsert();
|
||||
XLogRegisterData((char *) &xlrec, SizeOfHashMovePageContents);
|
||||
|
@ -1195,7 +1195,7 @@ _hash_splitbucket(Relation rel,
|
||||
all_tups_size = 0;
|
||||
|
||||
/* chain to a new overflow page */
|
||||
nbuf = _hash_addovflpage(rel, metabuf, nbuf, (nbuf == bucket_nbuf) ? true : false);
|
||||
nbuf = _hash_addovflpage(rel, metabuf, nbuf, (nbuf == bucket_nbuf));
|
||||
npage = BufferGetPage(nbuf);
|
||||
nopaque = (HashPageOpaque) PageGetSpecialPointer(npage);
|
||||
}
|
||||
|
@ -1475,7 +1475,7 @@ HeapTupleIsSurelyDead(HeapTuple htup, GlobalVisState *vistest)
|
||||
* all relevant hint bits were just set moments ago).
|
||||
*/
|
||||
if (!HeapTupleHeaderXminCommitted(tuple))
|
||||
return HeapTupleHeaderXminInvalid(tuple) ? true : false;
|
||||
return HeapTupleHeaderXminInvalid(tuple);
|
||||
|
||||
/*
|
||||
* If the inserting transaction committed, but any deleting transaction
|
||||
|
@ -1037,7 +1037,7 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
|
||||
if (attnum[i] <= 0 || attnum[i] > numberOfAttributes)
|
||||
break;
|
||||
v[attnum[i] - 1] = Values[i];
|
||||
n[attnum[i] - 1] = (Nulls && Nulls[i] == 'n') ? true : false;
|
||||
n[attnum[i] - 1] = (Nulls && Nulls[i] == 'n');
|
||||
}
|
||||
|
||||
if (i == natts) /* no errors in *attnum */
|
||||
|
@ -198,7 +198,7 @@ file_exists(const char *name)
|
||||
AssertArg(name != NULL);
|
||||
|
||||
if (stat(name, &st) == 0)
|
||||
return S_ISDIR(st.st_mode) ? false : true;
|
||||
return !S_ISDIR(st.st_mode);
|
||||
else if (!(errno == ENOENT || errno == ENOTDIR))
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
|
@ -936,7 +936,7 @@ create_seqscan_path(PlannerInfo *root, RelOptInfo *rel,
|
||||
pathnode->pathtarget = rel->reltarget;
|
||||
pathnode->param_info = get_baserel_parampathinfo(root, rel,
|
||||
required_outer);
|
||||
pathnode->parallel_aware = parallel_workers > 0 ? true : false;
|
||||
pathnode->parallel_aware = (parallel_workers > 0);
|
||||
pathnode->parallel_safe = rel->consider_parallel;
|
||||
pathnode->parallel_workers = parallel_workers;
|
||||
pathnode->pathkeys = NIL; /* seqscan has unordered result */
|
||||
@ -1057,7 +1057,7 @@ create_bitmap_heap_path(PlannerInfo *root,
|
||||
pathnode->path.pathtarget = rel->reltarget;
|
||||
pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
|
||||
required_outer);
|
||||
pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
|
||||
pathnode->path.parallel_aware = (parallel_degree > 0);
|
||||
pathnode->path.parallel_safe = rel->consider_parallel;
|
||||
pathnode->path.parallel_workers = parallel_degree;
|
||||
pathnode->path.pathkeys = NIL; /* always unordered */
|
||||
|
@ -1772,7 +1772,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
||||
for (i = 0; i < mcvlist->nitems; i++)
|
||||
{
|
||||
int j;
|
||||
bool match = (expr->useOr ? false : true);
|
||||
bool match = !expr->useOr;
|
||||
MCVItem *item = &mcvlist->items[i];
|
||||
|
||||
/*
|
||||
|
@ -336,7 +336,7 @@ BufFileOpenFileSet(FileSet *fileset, const char *name, int mode,
|
||||
|
||||
file = makeBufFileCommon(nfiles);
|
||||
file->files = files;
|
||||
file->readOnly = (mode == O_RDONLY) ? true : false;
|
||||
file->readOnly = (mode == O_RDONLY);
|
||||
file->fileset = fileset;
|
||||
file->name = pstrdup(name);
|
||||
|
||||
|
@ -288,7 +288,7 @@ LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
|
||||
}
|
||||
}
|
||||
|
||||
ld->dictState.isend = (curVal->type == 0) ? true : false;
|
||||
ld->dictState.isend = (curVal->type == 0);
|
||||
ld->dictState.getnext = false;
|
||||
|
||||
res = (TSLexeme *) DatumGetPointer(FunctionCall4(&(dict->lexize),
|
||||
|
@ -184,7 +184,7 @@ boolrecv(PG_FUNCTION_ARGS)
|
||||
int ext;
|
||||
|
||||
ext = pq_getmsgbyte(buf);
|
||||
PG_RETURN_BOOL((ext != 0) ? true : false);
|
||||
PG_RETURN_BOOL(ext != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -8005,14 +8005,14 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
|
||||
* appears simple since . has top precedence, unless parent is
|
||||
* T_FieldSelect itself!
|
||||
*/
|
||||
return (IsA(parentNode, FieldSelect) ? false : true);
|
||||
return !IsA(parentNode, FieldSelect);
|
||||
|
||||
case T_FieldStore:
|
||||
|
||||
/*
|
||||
* treat like FieldSelect (probably doesn't matter)
|
||||
*/
|
||||
return (IsA(parentNode, FieldStore) ? false : true);
|
||||
return !IsA(parentNode, FieldStore);
|
||||
|
||||
case T_CoerceToDomain:
|
||||
/* maybe simple, check args */
|
||||
|
@ -109,7 +109,7 @@ gtsquery_same(PG_FUNCTION_ARGS)
|
||||
TSQuerySign b = PG_GETARG_TSQUERYSIGN(1);
|
||||
bool *result = (bool *) PG_GETARG_POINTER(2);
|
||||
|
||||
*result = (a == b) ? true : false;
|
||||
*result = (a == b);
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ QTNEq(QTNode *a, QTNode *b)
|
||||
if (!(sign == a->sign && sign == b->sign))
|
||||
return false;
|
||||
|
||||
return (QTNodeCompare(a, b) == 0) ? true : false;
|
||||
return (QTNodeCompare(a, b) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -458,7 +458,7 @@ file_exists(const char *name)
|
||||
AssertArg(name != NULL);
|
||||
|
||||
if (stat(name, &st) == 0)
|
||||
return S_ISDIR(st.st_mode) ? false : true;
|
||||
return !S_ISDIR(st.st_mode);
|
||||
else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user