diff --git a/alg/gdalwarpoperation.cpp b/alg/gdalwarpoperation.cpp index 1448de37f95b..d84d2c08b943 100644 --- a/alg/gdalwarpoperation.cpp +++ b/alg/gdalwarpoperation.cpp @@ -832,22 +832,6 @@ void GDALDestroyWarpOperation(GDALWarpOperationH hOperation) /* CollectChunkList() */ /************************************************************************/ -static int OrderWarpChunk(const void *_a, const void *_b) -{ - const GDALWarpChunk *a = static_cast(_a); - const GDALWarpChunk *b = static_cast(_b); - if (a->dy < b->dy) - return -1; - else if (a->dy > b->dy) - return 1; - else if (a->dx < b->dx) - return -1; - else if (a->dx > b->dx) - return 1; - else - return 0; -} - void GDALWarpOperation::CollectChunkList(int nDstXOff, int nDstYOff, int nDstXSize, int nDstYSize) @@ -859,10 +843,18 @@ void GDALWarpOperation::CollectChunkList(int nDstXOff, int nDstYOff, CollectChunkListInternal(nDstXOff, nDstYOff, nDstXSize, nDstYSize); // Sort chunks from top to bottom, and for equal y, from left to right. - // TODO(schwehr): Use std::sort. - if (pasChunkList) - qsort(pasChunkList, nChunkListCount, sizeof(GDALWarpChunk), - OrderWarpChunk); + if (nChunkListCount > 1) + { + std::sort(pasChunkList, pasChunkList + nChunkListCount, + [](const GDALWarpChunk &a, const GDALWarpChunk &b) + { + if (a.dy < b.dy) + return true; + if (a.dy > b.dy) + return false; + return a.dx < b.dx; + }); + } /* -------------------------------------------------------------------- */ /* Find the global source window. */ diff --git a/ogr/ogrfeaturequery.cpp b/ogr/ogrfeaturequery.cpp index 4cc77749d7f8..371672d89551 100644 --- a/ogr/ogrfeaturequery.cpp +++ b/ogr/ogrfeaturequery.cpp @@ -33,7 +33,6 @@ #include "ogr_swq.h" #include -#include #include #include "cpl_conv.h" @@ -407,18 +406,6 @@ int OGRFeatureQuery::CanUseIndex(const swq_expr_node *psExpr, OGRLayer *poLayer) /* multi-part queries with ranges. */ /************************************************************************/ -static int CompareGIntBig(const void *pa, const void *pb) -{ - const GIntBig a = *(reinterpret_cast(pa)); - const GIntBig b = *(reinterpret_cast(pb)); - if (a < b) - return -1; - else if (a > b) - return 1; - else - return 0; -} - GIntBig *OGRFeatureQuery::EvaluateAgainstIndices(OGRLayer *poLayer, OGRErr *peErr) @@ -668,8 +655,7 @@ GIntBig *OGRFeatureQuery::EvaluateAgainstIndices(const swq_expr_node *psExpr, if (nFIDCount > 1) { // The returned FIDs are expected to be in sorted order. - qsort(panFIDs, static_cast(nFIDCount), sizeof(GIntBig), - CompareGIntBig); + std::sort(panFIDs, panFIDs + nFIDCount); } return panFIDs; } @@ -712,9 +698,7 @@ GIntBig *OGRFeatureQuery::EvaluateAgainstIndices(const swq_expr_node *psExpr, if (nFIDCount > 1) { // The returned FIDs are expected to be sorted. - // TODO(schwehr): Use std::sort. - qsort(panFIDs, static_cast(nFIDCount), sizeof(GIntBig), - CompareGIntBig); + std::sort(panFIDs, panFIDs + nFIDCount); } return panFIDs; } diff --git a/ogr/ogrsf_frmts/gml/gmlhandler.cpp b/ogr/ogrsf_frmts/gml/gmlhandler.cpp index 82b16111576a..6cdd85f99fc4 100644 --- a/ogr/ogrsf_frmts/gml/gmlhandler.cpp +++ b/ogr/ogrsf_frmts/gml/gmlhandler.cpp @@ -31,6 +31,7 @@ #include "gmlreader.h" #include "gmlreaderp.h" +#include #include #include #include @@ -486,23 +487,6 @@ struct _GeometryNamesStruct const char *pszName; }; -/************************************************************************/ -/* GMLHandlerSortGeometryElements() */ -/************************************************************************/ - -static int GMLHandlerSortGeometryElements(const void *pAIn, const void *pBIn) -{ - const GeometryNamesStruct *pA = - static_cast(pAIn); - const GeometryNamesStruct *pB = - static_cast(pBIn); - CPLAssert(pA->nHash != pB->nHash); - if (pA->nHash < pB->nHash) - return -1; - else - return 1; -} - /************************************************************************/ /* GMLHandler() */ /************************************************************************/ @@ -520,8 +504,9 @@ GMLHandler::GMLHandler(GMLReader *poReader) pasGeometryNames[i].nHash = CPLHashSetHashStr(pasGeometryNames[i].pszName); } - qsort(pasGeometryNames, GML_GEOMETRY_TYPE_COUNT, - sizeof(GeometryNamesStruct), GMLHandlerSortGeometryElements); + std::sort(pasGeometryNames, pasGeometryNames + GML_GEOMETRY_TYPE_COUNT, + [](const GeometryNamesStruct &a, const GeometryNamesStruct &b) + { return a.nHash < b.nHash; }); stateStack[0] = STATE_TOP; } diff --git a/port/cplstringlist.cpp b/port/cplstringlist.cpp index 8e92d3af7f75..b3957c24f0af 100644 --- a/port/cplstringlist.cpp +++ b/port/cplstringlist.cpp @@ -653,6 +653,7 @@ char **CPLStringList::StealList() return papszRetList; } +/* Case insensitive comparison function */ static int CPLCompareKeyValueString(const char *pszKVa, const char *pszKVb) { const char *pszItera = pszKVa; @@ -685,19 +686,6 @@ static int CPLCompareKeyValueString(const char *pszKVa, const char *pszKVb) } } -/************************************************************************/ -/* llCompareStr() */ -/* */ -/* Note this is case insensitive! This is because we normally */ -/* treat key value keywords as case insensitive. */ -/************************************************************************/ -static int llCompareStr(const void *a, const void *b) -{ - return CPLCompareKeyValueString( - *static_cast(const_cast(a)), - *static_cast(const_cast(b))); -} - /************************************************************************/ /* Sort() */ /************************************************************************/ @@ -721,8 +709,12 @@ CPLStringList &CPLStringList::Sort() if (!MakeOurOwnCopy()) return *this; - if (nCount) - qsort(papszList, nCount, sizeof(char *), llCompareStr); + if (nCount > 1) + { + std::sort(papszList, papszList + nCount, + [](const char *a, const char *b) + { return CPLCompareKeyValueString(a, b) < 0; }); + } bIsSorted = true; return *this;