@@ -9,28 +9,34 @@ namespace scorepy
99
1010struct region_handle
1111{
12- region_handle () = default ;
12+ constexpr region_handle () = default;
1313 ~region_handle () = default ;
14+ constexpr bool operator ==(const region_handle& other)
15+ {
16+ return this ->value == other.value ;
17+ }
1418 SCOREP_User_RegionHandle value = SCOREP_USER_INVALID_REGION;
1519};
1620
21+ constexpr region_handle uninitalised_region_handle = region_handle();
22+
1723static std::unordered_map<std::string, region_handle> regions;
1824static std::unordered_map<std::string, region_handle> rewind_regions;
1925
2026void region_begin (const std::string& region_name, std::string module , std::string file_name,
2127 std::uint64_t line_number)
2228{
23- auto pair = regions.emplace (make_pair (region_name, region_handle ()));
24- bool inserted_new = pair.second ;
25- auto & handle = pair.first ->second ;
26- if (inserted_new)
29+ auto & region_handle = regions[region_name];
30+
31+ if (region_handle == uninitalised_region_handle)
2732 {
28- SCOREP_User_RegionInit (&handle .value , NULL , &SCOREP_User_LastFileHandle,
33+ SCOREP_User_RegionInit (®ion_handle .value , NULL , &SCOREP_User_LastFileHandle,
2934 region_name.c_str (), SCOREP_USER_REGION_TYPE_FUNCTION,
3035 file_name.c_str (), line_number);
31- SCOREP_User_RegionSetGroup (handle.value , std::string (module , 0 , module .find (' .' )).c_str ());
36+ SCOREP_User_RegionSetGroup (region_handle.value ,
37+ std::string (module , 0 , module .find (' .' )).c_str ());
3238 }
33- SCOREP_User_RegionEnter (handle .value );
39+ SCOREP_User_RegionEnter (region_handle .value );
3440}
3541
3642void region_end (const std::string& region_name)
0 commit comments