Skip to content

Commit

Permalink
[Lint] OCI: modernize SRS cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 9, 2024
1 parent afdb927 commit 9a5db40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
8 changes: 5 additions & 3 deletions ogr/ogrsf_frmts/oci/ogr_oci.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "oci.h"
#include "cpl_error.h"

#include <map>

/* -------------------------------------------------------------------- */
/* Low level Oracle spatial declarations. */
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -564,9 +566,9 @@ class OGROCIDataSource final : public OGRDataSource

// We maintain a list of known SRID to reduce the number of trips to
// the database to get SRSes.
int nKnownSRID;
int *panSRID;
OGRSpatialReference **papoSRS;
std::map<int,
std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser>>
m_oSRSCache{};

public:
OGROCIDataSource();
Expand Down
39 changes: 10 additions & 29 deletions ogr/ogrsf_frmts/oci/ogrocidatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ OGROCIDataSource::OGROCIDataSource()
bDSUpdate = FALSE;
bNoLogging = FALSE;
poSession = nullptr;
papoSRS = nullptr;
panSRID = nullptr;
nKnownSRID = 0;
}

/************************************************************************/
Expand All @@ -81,13 +78,6 @@ OGROCIDataSource::~OGROCIDataSource()

CPLFree(papoLayers);

for (i = 0; i < nKnownSRID; i++)
{
papoSRS[i]->Release();
}
CPLFree(papoSRS);
CPLFree(panSRID);

if (poSession != nullptr)
delete poSession;
}
Expand Down Expand Up @@ -801,12 +791,10 @@ OGRSpatialReference *OGROCIDataSource::FetchSRS(int nId)
/* -------------------------------------------------------------------- */
/* First, we look through our SRID cache, is it there? */
/* -------------------------------------------------------------------- */
int i;

for (i = 0; i < nKnownSRID; i++)
auto oIter = m_oSRSCache.find(nId);
if (oIter != m_oSRSCache.end())
{
if (panSRID[i] == nId)
return papoSRS[i];
return oIter->second.get();
}

/* -------------------------------------------------------------------- */
Expand All @@ -830,11 +818,11 @@ OGRSpatialReference *OGROCIDataSource::FetchSRS(int nId)
/* -------------------------------------------------------------------- */
/* Turn into a spatial reference. */
/* -------------------------------------------------------------------- */
OGRSpatialReference *poSRS = new OGRSpatialReference();
std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> poSRS(
new OGRSpatialReference());
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if (poSRS->importFromWkt(papszResult[0]) != OGRERR_NONE)
{
delete poSRS;
return nullptr;
}

Expand All @@ -853,10 +841,10 @@ OGRSpatialReference *OGROCIDataSource::FetchSRS(int nId)
const char *const apszOptions[] = {
"IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES", nullptr};
if (oSRS_EPSG.importFromEPSG(nId) == OGRERR_NONE &&
oSRS_EPSG.IsSame(poSRS, apszOptions))
oSRS_EPSG.IsSame(poSRS.get(), apszOptions))
{
*poSRS = oSRS_EPSG;
return poSRS;
return poSRS.release();
}
}

Expand All @@ -865,7 +853,7 @@ OGRSpatialReference *OGROCIDataSource::FetchSRS(int nId)
/* authority. */
/* -------------------------------------------------------------------- */
int bGotEPSGMapping = FALSE;
for (i = 0; anEPSGOracleMapping[i] != 0; i += 2)
for (int i = 0; anEPSGOracleMapping[i] != 0; i += 2)
{
if (anEPSGOracleMapping[i] == nId)
{
Expand All @@ -890,15 +878,8 @@ OGRSpatialReference *OGROCIDataSource::FetchSRS(int nId)
/* -------------------------------------------------------------------- */
/* Add to the cache. */
/* -------------------------------------------------------------------- */
panSRID = (int *)CPLRealloc(panSRID, sizeof(int) * (nKnownSRID + 1));
papoSRS = (OGRSpatialReference **)CPLRealloc(papoSRS, sizeof(void *) *
(nKnownSRID + 1));
panSRID[nKnownSRID] = nId;
papoSRS[nKnownSRID] = poSRS;

nKnownSRID++;

return poSRS;
oIter = m_oSRSCache.emplace(nId, std::move(poSRS)).first;
return oIter->second.get();
}

/************************************************************************/
Expand Down

0 comments on commit 9a5db40

Please sign in to comment.