Skip to content

Commit

Permalink
Avoid reset for objects searched in empty indices
Browse files Browse the repository at this point in the history
  • Loading branch information
drolbr committed Apr 6, 2021
1 parent 3482c09 commit f330443
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/overpass_api/data/meta_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ struct Meta_Collector

~Meta_Collector()
{
if (meta_db)
{
delete db_it;
delete meta_db;
}
delete last_index;
delete current_index;
delete range_it;
delete db_it;
delete meta_db;
}

private:
Expand All @@ -66,6 +66,7 @@ struct Meta_Collector
typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type > >
::Range_Iterator* range_it;
Index* current_index;
Index* last_index;
std::set< OSM_Element_Metadata_Skeleton< Id_Type > > current_objects;

void update_current_objects(const Index&);
Expand Down Expand Up @@ -106,7 +107,7 @@ template< typename Object >
Meta_Collector< Index, Id_Type >::Meta_Collector
(const std::map< Index, std::vector< Object > >& items,
Transaction& transaction, const File_Properties* meta_file_prop)
: meta_db(0), db_it(0), range_it(0), current_index(0)
: meta_db(0), db_it(0), range_it(0), current_index(0), last_index(0)
{
if (!meta_file_prop)
return;
Expand All @@ -123,7 +124,7 @@ template< typename Index, typename Id_Type >
Meta_Collector< Index, Id_Type >::Meta_Collector
(const std::set< std::pair< Index, Index > >& used_ranges_,
Transaction& transaction, const File_Properties* meta_file_prop)
: used_ranges(used_ranges_), meta_db(0), db_it(0), range_it(0), current_index(0)
: used_ranges(used_ranges_), meta_db(0), db_it(0), range_it(0), current_index(0), last_index(0)
{
if (!meta_file_prop)
return;
Expand All @@ -141,18 +142,20 @@ void Meta_Collector< Index, Id_Type >::reset()
if (!meta_db)
return;

if (db_it)
delete db_it;
if (range_it)
delete range_it;
if (current_index)
{
delete current_index;
current_index = 0;
}
delete db_it;
db_it = 0;
delete range_it;
range_it = 0;
delete current_index;
current_index = 0;
delete last_index;
last_index = 0;

if (used_ranges.empty())
{
if (!used_indices.empty())
last_index = new Index(*used_indices.begin());

db_it = new typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type > >
::Discrete_Iterator(meta_db->discrete_begin(used_indices.begin(), used_indices.end()));

Expand All @@ -166,6 +169,8 @@ void Meta_Collector< Index, Id_Type >::reset()
}
else
{
last_index = new Index(used_ranges.begin()->first);

range_it = new typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type > >
::Range_Iterator(meta_db->range_begin(
Default_Range_Iterator< Index >(used_ranges.begin()),
Expand All @@ -186,6 +191,8 @@ template< typename Index, typename Id_Type >
void Meta_Collector< Index, Id_Type >::update_current_objects(const Index& index)
{
current_objects.clear();
if (last_index)
*last_index = index;

if (db_it)
{
Expand Down Expand Up @@ -221,8 +228,8 @@ const OSM_Element_Metadata_Skeleton< Id_Type >* Meta_Collector< Index, Id_Type >
if (!meta_db)
return 0;

if (current_index && index < *current_index)
reset();
if (current_index && index < *last_index)
reset();
if (current_index && *current_index < index)
update_current_objects(index);

Expand All @@ -242,8 +249,8 @@ const OSM_Element_Metadata_Skeleton< Id_Type >* Meta_Collector< Index, Id_Type >
if (!meta_db)
return 0;

if (current_index && index < *current_index)
reset();
if (current_index && index < *last_index)
reset();
if (current_index && *current_index < index)
update_current_objects(index);

Expand Down

0 comments on commit f330443

Please sign in to comment.