Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize provenance constructors using move semantics #12907

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DataFormats/Provenance/interface/Parentage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ namespace edm {
Parentage();

explicit Parentage(std::vector<BranchID> const& parents);
explicit Parentage(std::vector<BranchID>&& parents);

Parentage(Parentage const&) = default;
Parentage(Parentage&&) = default;

Parentage& operator=(Parentage const&) = default;
Parentage& operator=(Parentage&&) = default;

~Parentage() {}

ParentageID id() const;
Expand Down
1 change: 1 addition & 0 deletions DataFormats/Provenance/interface/ParentageRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace edm
/// value_type object, and 'false' if the
/// value_type object was already present.
bool insertMapped(value_type const& v);
bool insertMapped(value_type&& v);

///Not thread safe
void clear();
Expand Down
3 changes: 3 additions & 0 deletions DataFormats/Provenance/interface/ProductProvenance.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace edm {
ProductProvenance(BranchID const& bid,
std::vector<BranchID> const& parents);

ProductProvenance(BranchID const& bid,
std::vector<BranchID>&& parents);

~ProductProvenance() {}

ProductProvenance makeProductProvenance() const;
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/Provenance/src/Parentage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace edm {
parents_(parents) {
}

Parentage::Parentage(std::vector<BranchID>&& parents) :
parents_(std::move(parents)) {
}

ParentageID
Parentage::id() const {
std::ostringstream oss;
Expand Down
7 changes: 6 additions & 1 deletion DataFormats/Provenance/src/ParentageRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ namespace edm {
ParentageRegistry::insertMapped(value_type const& v) {
return m_map.insert(std::make_pair(v.id(),v)).second;
}


bool
ParentageRegistry::insertMapped(value_type&& v) {
return m_map.emplace(v.id(),std::move(v)).second;
}

void
ParentageRegistry::clear() {
m_map.clear();
Expand Down
10 changes: 10 additions & 0 deletions DataFormats/Provenance/src/ProductProvenance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ namespace edm {
ParentageRegistry::instance()->insertMapped(p);
}

ProductProvenance::ProductProvenance(BranchID const& bid,
std::vector<BranchID>&& parents) :
branchID_(bid),
parentageID_() {
Parentage p;
p.setParents(std::move(parents));
parentageID_ = p.id();
ParentageRegistry::instance()->insertMapped(std::move(p));
}

ProductProvenance
ProductProvenance::makeProductProvenance() const {
return *this;
Expand Down
6 changes: 3 additions & 3 deletions FWCore/Framework/src/Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ namespace edm {
while(pit != pie) {
// set provenance
if(!sameAsPrevious) {
ProductProvenance prov(pit->second->branchID(), gotBranchIDVector);
ProductProvenance prov(pit->second->branchID(), std::move(gotBranchIDVector));
*previousParentageId = prov.parentageID();
ep.put(*pit->second, std::move(pit->first), prov);
ep.put(*pit->second, std::move(pit->first), prov);
sameAsPrevious = true;
} else {
ProductProvenance prov(pit->second->branchID(), *previousParentageId);
ep.put(*pit->second, std::move(pit->first), prov);
ep.put(*pit->second, std::move(pit->first), prov);
}
++pit;
}
Expand Down