Skip to content

Commit 0eb09e9

Browse files
committed
Merge pull request CGAL#1611 from MaelRL/Mesh_3-fix_medit_io_redundant_find_calls-GF
Avoid some unnecessary set/map's find() calls in Mesh_3's medit output
2 parents 79741e4 + 8a29124 commit 0eb09e9

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

Mesh_3/include/CGAL/IO/File_medit.h

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ class Rebind_cell_pmap
7878
++cell_it)
7979
{
8080
// Add subdomain index in internal map if needed
81-
if ( subdomain_map_.end() ==
82-
subdomain_map_.find(r_c3t3_.subdomain_index(cell_it)) )
83-
{
84-
subdomain_map_.insert(std::make_pair(r_c3t3_.subdomain_index(cell_it),
85-
index_counter));
81+
std::pair<typename Subdomain_map::iterator, bool> is_insert_successful =
82+
subdomain_map_.insert(std::make_pair(r_c3t3_.subdomain_index(cell_it),
83+
index_counter));
84+
85+
if(is_insert_successful.second)
8686
++index_counter;
87-
}
8887
}
89-
88+
9089
// Rebind indices in alphanumeric order
9190
index_counter = first_index + 1;
9291
for ( typename Subdomain_map::iterator mit = subdomain_map_.begin() ;
@@ -181,11 +180,8 @@ class No_rebind_cell_pmap
181180
cell_it != r_c3t3_.cells_in_complex_end();
182181
++cell_it)
183182
{
184-
// Add subdomain index in set if new
185-
if ( subdomain_set.end() == subdomain_set.find(subdomain_index(cell_it)) )
186-
{
187-
subdomain_set.insert(subdomain_index(cell_it));
188-
}
183+
// Add subdomain index in set
184+
subdomain_set.insert(subdomain_index(cell_it));
189185
}
190186

191187
return subdomain_set.size();
@@ -231,14 +227,11 @@ class Rebind_facet_pmap
231227
++facet_it)
232228
{
233229
// Add surface index in internal map if needed
234-
if ( surface_map_.end() ==
235-
surface_map_.find(c3t3.surface_patch_index((*facet_it).first,
236-
(*facet_it).second)) )
237-
{
238-
surface_map_.insert(std::make_pair(r_c3t3_.surface_patch_index(*facet_it),
239-
index_counter));
230+
std::pair<typename Surface_map::iterator, bool> is_insert_successful =
231+
surface_map_.insert(std::make_pair(r_c3t3_.surface_patch_index(*facet_it),
232+
index_counter));
233+
if(is_insert_successful.second)
240234
++index_counter;
241-
}
242235
}
243236

244237
// Find cell_pmap_ unused indices
@@ -249,12 +242,8 @@ class Rebind_facet_pmap
249242
cell_it != r_c3t3_.cells_in_complex_end();
250243
++cell_it)
251244
{
252-
// Add subdomain index in set if new
253-
if ( cell_label_set.end()
254-
== cell_label_set.find(get(cell_pmap_,cell_it)) )
255-
{
256-
cell_label_set.insert(get(cell_pmap_,cell_it));
257-
}
245+
// Add subdomain index in set
246+
cell_label_set.insert(get(cell_pmap_, cell_it));
258247
}
259248

260249
// Rebind indices

0 commit comments

Comments
 (0)