1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Add lstEmpty(), strLstEmpty(), and varLstEmpty().

This seems more readable than lst*Size() == 0.

Hopefully this will also eliminate usage of lst*Size() > 0/lst*Size() != 0 variants for the inverse.
This commit is contained in:
David Steele 2021-01-29 14:27:56 -05:00
parent 5281e31422
commit 7d6c0319f0
32 changed files with 104 additions and 76 deletions

View File

@ -431,7 +431,7 @@ walSegmentFind(const Storage *storage, const String *archiveId, const String *wa
.nullOnMissing = true);
// If there are results
if (list != NULL && strLstSize(list) > 0)
if (list != NULL && !strLstEmpty(list))
{
// Error if there is more than one match
if (strLstSize(list) > 1)

View File

@ -198,7 +198,7 @@ archiveGetCheck(const StringList *archiveRequestList)
FUNCTION_LOG_END();
ASSERT(archiveRequestList != NULL);
ASSERT(strLstSize(archiveRequestList) > 0);
ASSERT(!strLstEmpty(archiveRequestList));
ArchiveGetCheckResult result = {.archiveFileMapList = lstNewP(sizeof(ArchiveFileMap))};
@ -368,7 +368,7 @@ cmdArchiveGet(void)
if (strLstSize(commandParam) != 2)
{
if (strLstSize(commandParam) == 0)
if (strLstEmpty(commandParam))
THROW(ParamRequiredError, "WAL segment to get required");
if (strLstSize(commandParam) == 1)
@ -439,7 +439,7 @@ cmdArchiveGet(void)
StringList *queue = storageListP(
storageSpool(), STORAGE_SPOOL_ARCHIVE_IN_STR, .expression = WAL_SEGMENT_REGEXP_STR, .errorOnMissing = true);
if (strLstSize(queue) > 0)
if (!strLstEmpty(queue))
{
// Get size of the WAL segment
uint64_t walSegmentSize = storageInfoP(storageLocal(), walDestination).size;
@ -524,7 +524,7 @@ cmdArchiveGet(void)
THROW_CODE(errorTypeCode(checkResult.errorType), strZ(checkResult.errorMessage));
// Get the archive file
if (lstSize(checkResult.archiveFileMapList) > 0)
if (!lstEmpty(checkResult.archiveFileMapList))
{
ASSERT(lstSize(checkResult.archiveFileMapList) == 1);
@ -563,7 +563,7 @@ static ProtocolParallelJob *archiveGetAsyncCallback(void *data, unsigned int cli
// Get a new job if there are any left
ArchiveGetCheckResult *checkResult = data;
if (lstSize(checkResult->archiveFileMapList) > 0)
if (!lstEmpty(checkResult->archiveFileMapList))
{
const ArchiveFileMap archiveFileMap = *((ArchiveFileMap *)lstGet(checkResult->archiveFileMapList, 0));
lstRemoveIdx(checkResult->archiveFileMapList, 0);
@ -612,7 +612,7 @@ cmdArchiveGetAsync(void)
archiveFileMissing = strLstGet(cfgCommandParam(), lstSize(checkResult.archiveFileMapList));
// Get archive files that were found
if (lstSize(checkResult.archiveFileMapList) > 0)
if (!lstEmpty(checkResult.archiveFileMapList))
{
// Create the parallel executor
ProtocolParallel *parallelExec = protocolParallelNew(

View File

@ -481,7 +481,7 @@ cmdArchivePushAsync(void)
jobData.walFileList = archivePushProcessList(jobData.walPath);
// The archive-push:async command should not have been called unless there are WAL files to process
if (strLstSize(jobData.walFileList) == 0)
if (strLstEmpty(jobData.walFileList))
THROW(AssertError, "no WAL files to process");
LOG_INFO_FMT(

View File

@ -101,7 +101,7 @@ backupLabelCreate(BackupType type, const String *backupLabelPrior, time_t timest
.expression = backupRegExpP(.full = true, .differential = true, .incremental = true)),
sortOrderDesc);
if (strLstSize(backupList) > 0)
if (!strLstEmpty(backupList))
backupLabelLatest = strLstGet(backupList, 0);
// Get the newest history
@ -109,7 +109,7 @@ backupLabelCreate(BackupType type, const String *backupLabelPrior, time_t timest
storageListP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/" BACKUP_PATH_HISTORY), .expression = STRDEF("^2[0-9]{3}$")),
sortOrderDesc);
if (strLstSize(historyYearList) > 0)
if (!strLstEmpty(historyYearList))
{
const StringList *historyList = strLstSort(
storageListP(
@ -121,7 +121,7 @@ backupLabelCreate(BackupType type, const String *backupLabelPrior, time_t timest
strZ(compressTypeStr(compressTypeGz)))),
sortOrderDesc);
if (strLstSize(historyList) > 0)
if (!strLstEmpty(historyList))
{
const String *historyLabelLatest = strLstGet(historyList, 0);
@ -683,7 +683,7 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
.expression = backupRegExpP(.full = true, .differential = true, .incremental = true)),
sortOrderDesc);
if (strLstSize(backupList) > 0)
if (!strLstEmpty(backupList))
{
const String *backupLabel = strLstGet(backupList, 0);
const String *manifestFile = strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel));
@ -1166,7 +1166,7 @@ backupJobResult(
{
// Format the page checksum errors
checksumPageErrorList = varVarLst(kvGet(checksumPageResult, VARSTRDEF("error")));
ASSERT(varLstSize(checksumPageErrorList) > 0);
ASSERT(!varLstEmpty(checksumPageErrorList));
String *error = strNew("");
unsigned int errorTotalMin = 0;
@ -1472,7 +1472,7 @@ static ProtocolParallelJob *backupJobCallback(void *data, unsigned int clientIdx
{
List *queue = *(List **)lstGet(jobData->queueList, (unsigned int)queueIdx + queueOffset);
if (lstSize(queue) > 0)
if (!lstEmpty(queue))
{
const ManifestFile *file = *(ManifestFile **)lstGet(queue, 0);
@ -1657,7 +1657,7 @@ backupProcess(BackupData *backupData, Manifest *manifest, const String *lsnStart
#ifdef DEBUG
// Ensure that all processing queues are empty
for (unsigned int queueIdx = 0; queueIdx < lstSize(jobData.queueList); queueIdx++)
ASSERT(lstSize(*(List **)lstGet(jobData.queueList, queueIdx)) == 0);
ASSERT(lstEmpty(*(List **)lstGet(jobData.queueList, queueIdx)));
#endif
// Remove files from the manifest that were removed during the backup. This must happen after processing to avoid

View File

@ -50,7 +50,7 @@ cmdOption(void)
// Add command parameters if they exist
const StringList *commandParamList = cfgCommandParam();
if (strLstSize(commandParamList) != 0)
if (!strLstEmpty(commandParamList))
{
strCatFmt(cmdOptionStr, " [");
@ -215,7 +215,7 @@ cmdEnd(int code, const String *errorMessage)
// Output statistics if there are any
const KeyValue *statKv = statToKv();
if (varLstSize(kvKeyList(statKv)) > 0)
if (!varLstEmpty(kvKeyList(statKv)))
LOG_DETAIL_FMT("statistics: %s", strZ(jsonFromKv(statKv)));
// Basic info on command end

View File

@ -435,7 +435,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
// Expire archives. If no backups were found or the number of backups found is not enough to satify archive retention
// then preserve current archive logs - too soon to expire them.
if (strLstSize(globalBackupRetentionList) > 0 && archiveRetention <= strLstSize(globalBackupRetentionList))
if (!strLstEmpty(globalBackupRetentionList) && archiveRetention <= strLstSize(globalBackupRetentionList))
{
// Attempt to load the archive info file
InfoArchive *infoArchive = infoArchiveLoadFile(
@ -522,7 +522,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
}
// If no backup to retain was found
if (strLstSize(localBackupRetentionList) == 0)
if (strLstEmpty(localBackupRetentionList))
{
// If this is not the current database, then delete the archive directory else do nothing since the
// current DB archive directory must not be deleted
@ -567,7 +567,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
// If no local backups were found as part of retention then set the backup archive retention to the newest
// backup so that the database is fully recoverable (can be recovered from the last backup through pitr)
if (strLstSize(localBackupArchiveRetentionList) == 0)
if (strLstEmpty(localBackupArchiveRetentionList))
{
strLstAdd(
localBackupArchiveRetentionList,

View File

@ -306,7 +306,7 @@ helpRender(void)
strCatFmt(result, " - '%s' command", commandName);
// If no additional params then this is command help
if (strLstSize(cfgCommandParam()) == 0)
if (strLstEmpty(cfgCommandParam()))
{
// Output command summary and description
strCatFmt(

View File

@ -273,7 +273,7 @@ archiveDbList(
StringList *walDir = strLstSort(
storageListP(storageRepo, archivePath, .expression = WAL_SEGMENT_DIR_REGEXP_STR), sortOrderAsc);
if (strLstSize(walDir) > 0)
if (!strLstEmpty(walDir))
{
// Not every WAL dir has WAL files so check each
for (unsigned int idx = 0; idx < strLstSize(walDir); idx++)
@ -284,7 +284,7 @@ archiveDbList(
.expression = WAL_SEGMENT_FILE_REGEXP_STR);
// If wal segments are found, get the oldest one as the archive start
if (strLstSize(list) > 0)
if (!strLstEmpty(list))
{
// Sort the list from oldest to newest to get the oldest starting WAL archived for this DB
list = strLstSort(list, sortOrderAsc);
@ -302,7 +302,7 @@ archiveDbList(
.expression = WAL_SEGMENT_FILE_REGEXP_STR);
// If wal segments are found, get the newest one as the archive stop
if (strLstSize(list) > 0)
if (!strLstEmpty(list))
{
// Sort the list from newest to oldest to get the newest ending WAL archived for this DB
list = strLstSort(list, sortOrderDesc);
@ -468,10 +468,10 @@ backupListAdd(
}
}
kvPut(varKv(backupInfo), BACKUP_KEY_LINK_VAR, (varLstSize(linkSection) > 0 ? varNewVarLst(linkSection) : NULL));
kvPut(varKv(backupInfo), BACKUP_KEY_LINK_VAR, (!varLstEmpty(linkSection) ? varNewVarLst(linkSection) : NULL));
kvPut(
varKv(backupInfo), BACKUP_KEY_TABLESPACE_VAR,
(varLstSize(tablespaceSection) > 0 ? varNewVarLst(tablespaceSection) : NULL));
(!varLstEmpty(tablespaceSection) ? varNewVarLst(tablespaceSection) : NULL));
// Get the list of files with an error in the page checksum
VariantList *checksumPageErrorList = varLstNew();
@ -486,7 +486,7 @@ backupListAdd(
kvPut(
varKv(backupInfo), BACKUP_KEY_CHECKSUM_PAGE_ERROR_VAR,
(varLstSize(checksumPageErrorList) > 0 ? varNewVarLst(checksumPageErrorList) : NULL));
(!varLstEmpty(checksumPageErrorList) ? varNewVarLst(checksumPageErrorList) : NULL));
manifestFree(manifest);
}
@ -806,7 +806,7 @@ formatTextBackup(const DbGroup *dbGroup, String *resultStr)
strCatZ(resultStr, " database list:");
if (varLstSize(dbSection) == 0)
if (varLstEmpty(dbSection))
strCatZ(resultStr, " none\n");
else
{
@ -1035,7 +1035,7 @@ formatTextDb(
formatTextBackup(dbGroupInfo, resultCurrent);
displayCurrent = true;
}
else if (dbGroupInfo->archiveMin != NULL || varLstSize(dbGroupInfo->backupList) > 0)
else if (dbGroupInfo->archiveMin != NULL || !varLstEmpty(dbGroupInfo->backupList))
{
strCatZ(resultStr, "\n db (prior)");
formatTextBackup(dbGroupInfo, resultStr);
@ -1185,7 +1185,7 @@ infoRender(void)
if (stanza != NULL)
{
// If a specific stanza was requested and it is not on this repo, then stanzaExists flag will be reset to false
if (strLstSize(stanzaNameList) == 0 || !strLstExists(stanzaNameList, stanza))
if (strLstEmpty(stanzaNameList) || !strLstExists(stanzaNameList, stanza))
stanzaExists = false;
// Narrow the list to only the requested stanza
@ -1246,14 +1246,14 @@ infoRender(void)
String *resultStr = strNew("");
// If the backup storage exists, then search for and process any stanzas
if (lstSize(stanzaRepoList) > 0)
if (!lstEmpty(stanzaRepoList))
infoList = stanzaInfoList(stanzaRepoList, backupLabel, repoIdxStart, repoIdxMax);
// Format text output
if (strEq(cfgOptionStr(cfgOptOutput), CFGOPTVAL_INFO_OUTPUT_TEXT_STR))
{
// Process any stanza directories
if (varLstSize(infoList) > 0)
if (!varLstEmpty(infoList))
{
for (unsigned int stanzaIdx = 0; stanzaIdx < varLstSize(infoList); stanzaIdx++)
{
@ -1344,7 +1344,7 @@ infoRender(void)
}
// Get the current database for this stanza
if (varLstSize(kvGetList(stanzaInfo, STANZA_KEY_DB_VAR)) > 0)
if (!varLstEmpty(kvGetList(stanzaInfo, STANZA_KEY_DB_VAR)))
{
InfoStanzaRepo *stanzaRepo = lstFind(stanzaRepoList, &stanzaName);

View File

@ -37,7 +37,7 @@ cmdStorageRemove(void)
{
bool recurse = cfgOptionBool(cfgOptRecurse);
if (!recurse && strLstSize(storageListP(storageRepo(), path)) > 0)
if (!recurse && !strLstEmpty(storageListP(storageRepo(), path)))
THROW(OptionInvalidError, CFGOPT_RECURSE " option must be used to delete non-empty path");
storagePathRemoveP(storageRepoWrite(), path, .recurse = recurse);

View File

@ -1207,7 +1207,7 @@ restoreSelectiveExpression(Manifest *manifest)
strLstSort(dbList, sortOrderAsc);
// If no databases were found then this backup is not a valid cluster
if (strLstSize(dbList) == 0)
if (strLstEmpty(dbList))
THROW(FormatError, "no databases found for selective restore\nHINT: is this a valid cluster?");
// Log databases found
@ -1981,7 +1981,7 @@ static ProtocolParallelJob *restoreJobCallback(void *data, unsigned int clientId
{
List *queue = *(List **)lstGet(jobData->queueList, (unsigned int)queueIdx);
if (lstSize(queue) > 0)
if (!lstEmpty(queue))
{
const ManifestFile *file = *(ManifestFile **)lstGet(queue, 0);

View File

@ -67,8 +67,8 @@ stanzaDelete(const Storage *storageRepoWriteStanza, const StringList *archiveLis
// empty StringList will be returned; in such a case, the directory will attempt to be deleted (this is OK).
if (archiveList != NULL || backupList != NULL)
{
bool archiveNotEmpty = (archiveList != NULL && strLstSize(archiveList) > 0) ? true : false;
bool backupNotEmpty = (backupList != NULL && strLstSize(backupList) > 0) ? true : false;
bool archiveNotEmpty = (archiveList != NULL && !strLstEmpty(archiveList)) ? true : false;
bool backupNotEmpty = (backupList != NULL && !strLstEmpty(backupList)) ? true : false;
// If something exists in either directory, then remove
if (archiveNotEmpty || backupNotEmpty)

View File

@ -544,7 +544,7 @@ verifyCreateArchiveIdRange(VerifyArchiveResult *archiveIdResult, StringList *wal
// If there is a WAL range for this archiveID, get the last one. If there is no timeline change then continue updating the last
// WAL range.
if (lstSize(archiveIdResult->walRangeList) != 0 &&
if (!lstEmpty(archiveIdResult->walRangeList) &&
strEq(
strSubN(((VerifyWalRange *)lstGetLast(archiveIdResult->walRangeList))->stop, 0, 8),
strSubN(strSubN(strLstGet(walFileList, walFileIdx), 0, WAL_SEGMENT_NAME_SIZE), 0, 8)))
@ -653,12 +653,12 @@ verifyArchive(void *data)
VerifyJobData *jobData = data;
// Process archive files, if any
while (strLstSize(jobData->archiveIdList) > 0)
while (!strLstEmpty(jobData->archiveIdList))
{
result = NULL;
// Add archiveId to the result list if the list is empty or the last processed is not equal to the current archiveId
if (lstSize(jobData->archiveIdResultList) == 0 ||
if (lstEmpty(jobData->archiveIdResultList) ||
!strEq(
((VerifyArchiveResult *)lstGetLast(jobData->archiveIdResultList))->archiveId, strLstGet(jobData->archiveIdList, 0)))
{
@ -691,7 +691,7 @@ verifyArchive(void *data)
}
// If there are WAL paths then get the file lists
if (strLstSize(jobData->walPathList) > 0)
if (!strLstEmpty(jobData->walPathList))
{
// Get the archive id info for the current (last) archive id being processed
VerifyArchiveResult *archiveResult = lstGetLast(jobData->archiveIdResultList);
@ -701,7 +701,7 @@ verifyArchive(void *data)
String *walPath = strLstGet(jobData->walPathList, 0);
// Get the WAL files for the first item in the WAL paths list and initialize WAL info and ranges
if (strLstSize(jobData->walFileList) == 0)
if (strLstEmpty(jobData->walFileList))
{
// Free the old WAL file list
strLstFree(jobData->walFileList);
@ -717,7 +717,7 @@ verifyArchive(void *data)
}
MEM_CONTEXT_END();
if (strLstSize(jobData->walFileList) > 0)
if (!strLstEmpty(jobData->walFileList))
{
if (archiveResult->pgWalInfo.size == 0)
{
@ -743,7 +743,7 @@ verifyArchive(void *data)
}
// If there are WAL files, then verify them
if (strLstSize(jobData->walFileList) > 0)
if (!strLstEmpty(jobData->walFileList))
{
do
{
@ -768,13 +768,13 @@ verifyArchive(void *data)
strLstRemoveIdx(jobData->walFileList, 0);
// If this is the last file to process for this timeline, then remove the path
if (strLstSize(jobData->walFileList) == 0)
if (strLstEmpty(jobData->walFileList))
strLstRemoveIdx(jobData->walPathList, 0);
// Return to process the job found
break;
}
while (strLstSize(jobData->walFileList) > 0);
while (!strLstEmpty(jobData->walFileList));
}
else
{
@ -789,10 +789,10 @@ verifyArchive(void *data)
if (result != NULL)
break;
}
while (strLstSize(jobData->walPathList) > 0);
while (!strLstEmpty(jobData->walPathList));
// If this is the last timeline to process for this archiveId, then remove the archiveId
if (strLstSize(jobData->walPathList) == 0)
if (strLstEmpty(jobData->walPathList))
strLstRemoveIdx(jobData->archiveIdList, 0);
// If a file was sent to be processed then break so can process it
@ -825,13 +825,13 @@ verifyBackup(void *data)
VerifyJobData *jobData = data;
// Process backup files, if any
while (strLstSize(jobData->backupList) > 0)
while (!strLstEmpty(jobData->backupList))
{
result = NULL;
// If result list is empty or the last processed is not equal to the backup being processed, then intialize the backup
// data and results
if (lstSize(jobData->backupResultList) == 0 ||
if (lstEmpty(jobData->backupResultList) ||
!strEq(((VerifyBackupResult *)lstGetLast(jobData->backupResultList))->backupLabel, strLstGet(jobData->backupList, 0)))
{
MEM_CONTEXT_BEGIN(lstMemContext(jobData->backupResultList))
@ -1058,7 +1058,7 @@ verifyJobCallback(void *data, unsigned int clientIdx)
result = protocolParallelJobMove(verifyArchive(data), memContextPrior());
// Set the backupProcessing flag if the archive processing is finished so backup processing can begin immediately after
jobData->backupProcessing = strLstSize(jobData->archiveIdList) == 0;
jobData->backupProcessing = strLstEmpty(jobData->archiveIdList);
}
if (jobData->backupProcessing)
@ -1150,7 +1150,7 @@ verifySetBackupCheckArchive(
{
// If there are backups, set the last backup as current if it is not in backup.info - if it is, then it is complete, else
// it will be checked later
if (strLstSize(backupList) > 0)
if (!strLstEmpty(backupList))
{
// Get the last backup as current if it is not in backup.info current list
String *backupLabel = strLstGet(backupList, strLstSize(backupList) - 1);
@ -1167,7 +1167,7 @@ verifySetBackupCheckArchive(
}
// If there are archive directories on disk, make sure they are in the database history list
if (strLstSize(archiveIdList) > 0)
if (!strLstEmpty(archiveIdList))
{
StringList *archiveIdHistoryList = strLstNew();
@ -1258,7 +1258,7 @@ verifyRender(List *archiveIdResultList, List *backupResultList)
String *result = strNew("Results:");
// Render archive results
if (lstSize(archiveIdResultList) == 0)
if (lstEmpty(archiveIdResultList))
strCatZ(result, "\n archiveId: none found");
else
{
@ -1311,7 +1311,7 @@ verifyRender(List *archiveIdResultList, List *backupResultList)
}
// Render backup results
if (lstSize(backupResultList) == 0)
if (lstEmpty(backupResultList))
strCatZ(result, "\n backup: none found");
else
{
@ -1468,15 +1468,15 @@ verifyProcess(unsigned int *errorTotal)
sortOrderAsc);
// Only begin processing if there are some archives or backups in the repo
if (strLstSize(jobData.archiveIdList) > 0 || strLstSize(jobData.backupList) > 0)
if (!strLstEmpty(jobData.archiveIdList) || !strLstEmpty(jobData.backupList))
{
// Warn if there are no archives or there are no backups in the repo so that the callback need not try to
// distinguish between having processed all of the list or if the list was missing in the first place
if (strLstSize(jobData.archiveIdList) == 0 || strLstSize(jobData.backupList) == 0)
LOG_WARN_FMT("no %s exist in the repo", strLstSize(jobData.archiveIdList) == 0 ? "archives" : "backups");
if (strLstEmpty(jobData.archiveIdList) || strLstEmpty(jobData.backupList))
LOG_WARN_FMT("no %s exist in the repo", strLstEmpty(jobData.archiveIdList) ? "archives" : "backups");
// If there are no archives to process, then set the processing flag to skip to processing the backups
if (strLstSize(jobData.archiveIdList) == 0)
if (strLstEmpty(jobData.archiveIdList))
jobData.backupProcessing = true;
// Set current backup if there is one and verify the archive history on disk is in the database history

View File

@ -78,7 +78,7 @@ httpClientOpen(HttpClient *this)
HttpSession *result = NULL;
// Check if there is a resuable session
if (lstSize(this->sessionReuseList) > 0)
if (!lstEmpty(this->sessionReuseList))
{
// Remove session from reusable list
result = *(HttpSession **)lstGet(this->sessionReuseList, 0);

View File

@ -268,7 +268,7 @@ httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param)
{
const StringList *keyList = httpQueryList(this);
if (strLstSize(keyList) > 0)
if (!strLstEmpty(keyList))
{
MEM_CONTEXT_PRIOR_BEGIN()
{

View File

@ -265,7 +265,7 @@ httpRequestError(const HttpRequest *this, HttpResponse *response)
// Output request headers
const StringList *requestHeaderList = httpHeaderList(this->header);
if (strLstSize(requestHeaderList) > 0)
if (!strLstEmpty(requestHeaderList))
{
strCatZ(error, "\n*** Request Headers ***:");
@ -283,7 +283,7 @@ httpRequestError(const HttpRequest *this, HttpResponse *response)
const HttpHeader *responseHeader = httpResponseHeader(response);
const StringList *responseHeaderList = httpHeaderList(responseHeader);
if (strLstSize(responseHeaderList) > 0)
if (!strLstEmpty(responseHeaderList))
{
strCatZ(error, "\n*** Response Headers ***:");

View File

@ -805,7 +805,7 @@ jsonFromKvInternal(const KeyValue *kv)
// If the array is empty, then do not add formatting, else process the array.
if (varVarLst(value) == NULL)
strCat(result, NULL_STR);
else if (varLstSize(varVarLst(value)) == 0)
else if (varLstEmpty(varVarLst(value)))
strCatZ(result, "[]");
else
{
@ -942,7 +942,7 @@ jsonFromVar(const Variant *var)
const VariantList *vl = varVarLst(var);
// If not an empty array
if (varLstSize(vl) > 0)
if (!varLstEmpty(vl))
{
strCatZ(jsonStr, "[");

View File

@ -104,6 +104,13 @@ List *lstRemoveLast(List *this);
// Return list size
unsigned int lstSize(const List *this);
// Is the list empty?
__attribute__((always_inline)) static inline bool
lstEmpty(const List *this)
{
return lstSize(this) == 0;
}
// List sort
List *lstSort(List *this, SortOrder sortOrder);

View File

@ -937,7 +937,7 @@ pckReadEnd(PackRead *this)
ASSERT(this != NULL);
// Read object end markers
while (lstSize(this->tagStack) > 0)
while (!lstEmpty(this->tagStack))
{
// Make sure we are at the end of the container
unsigned int id = UINT_MAX - 1;

View File

@ -680,7 +680,7 @@ strPathAbsolute(const String *this, const String *base)
StringList *baseList = strLstNewSplit(base, FSLASH_STR);
StringList *pathList = strLstNewSplit(this, FSLASH_STR);
while (strLstSize(pathList) > 0)
while (!strLstEmpty(pathList))
{
const String *pathPart = strLstGet(pathList, 0);

View File

@ -77,6 +77,13 @@ StringList *strLstRemoveIdx(StringList *this, unsigned int listIdx);
// List size
unsigned int strLstSize(const StringList *this);
// Is the list empty?
__attribute__((always_inline)) static inline bool
strLstEmpty(const StringList *this)
{
return strLstSize(this) == 0;
}
// List sort
StringList *strLstSort(StringList *this, SortOrder sortOrder);

View File

@ -38,6 +38,13 @@ VariantList *varLstMove(VariantList *this, MemContext *parentNew);
// List size
unsigned int varLstSize(const VariantList *this);
// Is the list empty?
__attribute__((always_inline)) static inline bool
varLstEmpty(const VariantList *this)
{
return varLstSize(this) == 0;
}
/***********************************************************************************************************************************
Destructor
***********************************************************************************************************************************/

View File

@ -853,7 +853,7 @@ cfgFileLoad( // NOTE: Pas
.nullOnMissing = !configIncludeRequired);
// If conf files are found, then add them to the config string
if (list != NULL && strLstSize(list) > 0)
if (list != NULL && !strLstEmpty(list))
{
// Sort the list for reproducibility only -- order does not matter
strLstSort(list, sortOrderAsc);

View File

@ -185,7 +185,7 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
this->info = infoNewLoad(read, infoPgLoadCallback, &loadData);
// History must include at least one item or the file is corrupt
CHECK(lstSize(this->history) > 0);
CHECK(!lstEmpty(this->history));
// If the current id was not found then the file is corrupt
CHECK(loadData.currentId > 0);

View File

@ -268,7 +268,7 @@ protocolParallelDone(ProtocolParallel *this)
ASSERT(this->state != protocolParallelJobStatePending);
// If there are no jobs left then we are done
if (this->state != protocolParallelJobStateDone && lstSize(this->jobList) == 0)
if (this->state != protocolParallelJobStateDone && lstEmpty(this->jobList))
this->state = protocolParallelJobStateDone;
FUNCTION_LOG_RETURN(BOOL, this->state == protocolParallelJobStateDone);

View File

@ -137,7 +137,7 @@ storageAzureAuth(
if (query != NULL)
{
StringList *queryKeyList = httpQueryList(query);
ASSERT(strLstSize(queryKeyList) > 0);
ASSERT(!strLstEmpty(queryKeyList));
for (unsigned int queryKeyIdx = 0; queryKeyIdx < strLstSize(queryKeyList); queryKeyIdx++)
{

View File

@ -652,7 +652,7 @@ void
hrnTestResultStringList(const StringList *actual, const void *expected, HarnessTestResultOperation operation)
{
// Return NULL if list is empty
if (strLstSize(actual) == 0)
if (strLstEmpty(actual))
{
hrnTestResultZ(NULL, expected, operation);
return;

View File

@ -625,7 +625,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("statistics exist");
TEST_RESULT_BOOL(varLstSize(kvKeyList(statToKv())) > 0, true, "check");
TEST_RESULT_BOOL(varLstEmpty(kvKeyList(statToKv())), false, "check");
}
FUNCTION_HARNESS_RESULT_VOID();

View File

@ -503,7 +503,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("stastistics exist");
TEST_RESULT_BOOL(varLstSize(kvKeyList(statToKv())) > 0, true, "check");
TEST_RESULT_BOOL(varLstEmpty(kvKeyList(statToKv())), false, "check");
}
FUNCTION_HARNESS_RESULT_VOID();

View File

@ -79,6 +79,8 @@ testRun(void)
{
list = lstNewP(sizeof(int));
TEST_RESULT_BOOL(lstEmpty(list), true, "list empty");
TEST_ERROR(lstGetLast(list), AssertError, "cannot get last from list with no values");
TEST_ERROR(lstRemoveLast(list), AssertError, "cannot remove last from list with no values");
@ -96,6 +98,7 @@ testRun(void)
// Check the size
TEST_RESULT_INT(lstSize(list), 9, "list size");
TEST_RESULT_BOOL(lstEmpty(list), false, "list not empty");
// Read them back and check values
for (unsigned int listIdx = 0; listIdx < lstSize(list); listIdx++)

View File

@ -336,10 +336,12 @@ testRun(void)
TEST_RESULT_BOOL(strLstExistsZ(list, NULL), false, "check null exists");
TEST_RESULT_VOID(strLstAddIfMissing(list, STRDEF("item1")), "add item 1 again");
TEST_RESULT_UINT(strLstSize(list), 1, "check size");
TEST_RESULT_BOOL(strLstEmpty(list), false, " not empty");
TEST_RESULT_BOOL(strLstRemove(list, STRDEF("item1")), true, "remove item 1");
TEST_RESULT_BOOL(strLstRemove(list, STRDEF("item1")), false, "remove item 1 fails");
TEST_RESULT_UINT(strLstSize(list), 0, " check size");
TEST_RESULT_BOOL(strLstEmpty(list), true, " empty");
}
// *****************************************************************************************************************************

View File

@ -328,12 +328,14 @@ testRun(void)
TEST_ASSIGN(listVar, varNewVarLst(varLstNew()), "new empty");
TEST_RESULT_INT(varLstSize(varVarLst(listVar)), 0, " empty size");
TEST_RESULT_BOOL(varLstEmpty(varVarLst(listVar)), true, " empty");
TEST_RESULT_PTR(varVarLst(NULL), NULL, "get null var list");
TEST_RESULT_PTR(varLstAdd(varVarLst(listVar), varNewBool(true)), varVarLst(listVar), " add bool");
TEST_RESULT_PTR(varLstAdd(varVarLst(listVar), varNewInt(55)), varVarLst(listVar), " add int");
TEST_RESULT_INT(varLstSize(varVarLst(listVar)), 2, " size with items");
TEST_RESULT_BOOL(varLstEmpty(varVarLst(listVar)), false, " not empty");
TEST_RESULT_BOOL(varBool(varLstGet(varVarLst(listVar), 0)), true, " get bool");
TEST_RESULT_INT(varInt(varLstGet(varVarLst(listVar), 1)), 55, " get int");

View File

@ -211,7 +211,7 @@ testRun(void)
TEST_LOG_FMT("remove completed in %ums", (unsigned int)(timeMSec() - timeBegin));
CHECK(lstSize(list) == 0);
CHECK(lstEmpty(list));
}
// *****************************************************************************************************************************