mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
limit try/catch and simplify leak fix
This commit is contained in:
parent
5eb0b4c961
commit
683c47beb6
@ -480,29 +480,21 @@ QString QgsStacParser::getString( const nlohmann::json &data )
|
||||
|
||||
QgsStacItemCollection *QgsStacParser::itemCollection()
|
||||
{
|
||||
std::vector< std::unique_ptr<QgsStacItem> > items;
|
||||
QVector< QgsStacLink > links;
|
||||
int numberMatched = -1;
|
||||
try
|
||||
{
|
||||
QVector< QgsStacLink > links = parseLinks( mData.at( "links" ) );
|
||||
links = parseLinks( mData.at( "links" ) );
|
||||
|
||||
std::vector< std::unique_ptr<QgsStacItem> > items;
|
||||
items.reserve( mData.at( "features" ).size() );
|
||||
for ( auto &item : mData.at( "features" ) )
|
||||
{
|
||||
std::unique_ptr<QgsStacItem> i( parseItem( item ) );
|
||||
if ( i )
|
||||
items.emplace_back( i.release() );
|
||||
items.emplace_back( parseItem( item ) );
|
||||
}
|
||||
|
||||
const int numberMatched = mData.contains( "numberMatched" ) ? mData["numberMatched"].get<int>() : -1;
|
||||
|
||||
QVector< QgsStacItem *> rawItems;
|
||||
rawItems.reserve( static_cast<int>( items.size() ) );
|
||||
for ( std::unique_ptr<QgsStacItem> &i : items )
|
||||
{
|
||||
rawItems.append( i.release() );
|
||||
}
|
||||
|
||||
return new QgsStacItemCollection( rawItems, links, numberMatched );
|
||||
if ( mData.contains( "numberMatched" ) )
|
||||
numberMatched = mData["numberMatched"].get<int>();
|
||||
}
|
||||
catch ( nlohmann::json::exception &ex )
|
||||
{
|
||||
@ -510,33 +502,36 @@ QgsStacItemCollection *QgsStacParser::itemCollection()
|
||||
QgsDebugError( QStringLiteral( "Error parsing ItemCollection: %1" ).arg( ex.what() ) );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QVector< QgsStacItem *> rawItems;
|
||||
rawItems.reserve( static_cast<int>( items.size() ) );
|
||||
for ( std::unique_ptr<QgsStacItem> &i : items )
|
||||
{
|
||||
if ( i )
|
||||
rawItems.append( i.release() );
|
||||
}
|
||||
|
||||
return new QgsStacItemCollection( rawItems, links, numberMatched );
|
||||
}
|
||||
|
||||
QgsStacCollections *QgsStacParser::collections()
|
||||
{
|
||||
std::vector< std::unique_ptr<QgsStacCollection> > cols;
|
||||
QVector< QgsStacLink > links;
|
||||
int numberMatched = -1;
|
||||
|
||||
try
|
||||
{
|
||||
QVector< QgsStacLink > links = parseLinks( mData.at( "links" ) );
|
||||
links = parseLinks( mData.at( "links" ) );
|
||||
|
||||
std::vector< std::unique_ptr<QgsStacCollection> > cols;
|
||||
cols.reserve( mData.at( "collections" ).size() );
|
||||
for ( auto &col : mData.at( "collections" ) )
|
||||
{
|
||||
std::unique_ptr<QgsStacCollection> c( parseCollection( col ) );
|
||||
if ( c )
|
||||
cols.emplace_back( c.release() );
|
||||
cols.emplace_back( parseCollection( col ) );
|
||||
}
|
||||
|
||||
const int numberMatched = mData.contains( "numberMatched" ) ? mData["numberMatched"].get<int>() : -1;
|
||||
|
||||
QVector< QgsStacCollection * > rawCols;
|
||||
rawCols.reserve( static_cast<int>( cols.size() ) );
|
||||
for ( std::unique_ptr<QgsStacCollection> &c : cols )
|
||||
{
|
||||
rawCols.append( c.release() );
|
||||
}
|
||||
|
||||
return new QgsStacCollections( rawCols, links, numberMatched );
|
||||
if ( mData.contains( "numberMatched" ) )
|
||||
numberMatched = mData["numberMatched"].get<int>();
|
||||
}
|
||||
catch ( nlohmann::json::exception &ex )
|
||||
{
|
||||
@ -544,4 +539,14 @@ QgsStacCollections *QgsStacParser::collections()
|
||||
QgsDebugError( QStringLiteral( "Error parsing ItemCollection: %1" ).arg( ex.what() ) );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QVector< QgsStacCollection * > rawCols;
|
||||
rawCols.reserve( static_cast<int>( cols.size() ) );
|
||||
for ( std::unique_ptr<QgsStacCollection> &c : cols )
|
||||
{
|
||||
if ( c )
|
||||
rawCols.append( c.release() );
|
||||
}
|
||||
|
||||
return new QgsStacCollections( rawCols, links, numberMatched );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user