Skip to content

Commit 6597cde

Browse files
committed
fixup! [RF] Improve hash-assisted find in RooAbsCollection.
1 parent 3bb0821 commit 6597cde

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

roofit/roofitcore/inc/RooAbsCollection.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ ROOT::RRangeCast<T, true, Range_t> dynamic_range_cast(Range_t &&coll)
5454

5555
class RooCmdArg;
5656

57+
namespace RooFit {
58+
namespace Detail {
59+
struct HashAssistedFind;
60+
}
61+
}
62+
5763
class RooAbsCollection : public TObject, public RooPrintable {
5864
public:
5965
using Storage_t = std::vector<RooAbsArg*>;
@@ -381,7 +387,7 @@ class RooAbsCollection : public TObject, public RooPrintable {
381387
private:
382388
std::unique_ptr<LegacyIterator_t> makeLegacyIterator (bool forward = true) const;
383389

384-
struct HashAssistedFind;
390+
using HashAssistedFind = RooFit::Detail::HashAssistedFind;
385391
mutable std::unique_ptr<HashAssistedFind> _hashAssistedFind; //!
386392
std::size_t _sizeThresholdForMapSearch; //!
387393

roofit/roofitcore/src/RooAbsCollection.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ char* operator+( streampos&, char* );
6262

6363
ClassImp(RooAbsCollection);
6464

65+
namespace RooFit {
66+
namespace Detail {
67+
6568
/**
6669
* Helper for hash-map-assisted finding of elements by name.
6770
* Create this helper if finding of elements by name is needed.
@@ -71,7 +74,7 @@ ClassImp(RooAbsCollection);
7174
* gets renamed, this counter will be increased, and the name to
7275
* object map becomes invalid. In this case, it has to be recreated.
7376
*/
74-
struct RooAbsCollection::HashAssistedFind {
77+
struct HashAssistedFind {
7578

7679
/// Inititalise empty hash map for fast finding by name.
7780
template<typename It_t>
@@ -114,7 +117,8 @@ struct RooAbsCollection::HashAssistedFind {
114117
std::size_t rooNameRegCounterWhereMapWasValid = 0;
115118
};
116119

117-
120+
}
121+
}
118122

119123

120124
////////////////////////////////////////////////////////////////////////////////
@@ -1561,8 +1565,8 @@ void RooAbsCollection::insert(RooAbsArg* item) {
15611565
////////////////////////////////////////////////////////////////////////////////
15621566
/// \param[in] flag Switch hash map on or off.
15631567
void RooAbsCollection::useHashMapForFind(bool flag) const {
1568+
if (flag && !_hashAssistedFind) _hashAssistedFind = std::make_unique<HashAssistedFind>(_list.begin(), _list.end());
15641569
if (!flag) _hashAssistedFind = nullptr;
1565-
else _hashAssistedFind = std::make_unique<HashAssistedFind>(_list.begin(), _list.end());
15661570
}
15671571

15681572

0 commit comments

Comments
 (0)