Skip to content

Commit

Permalink
pcp: Optimize for the case where we're composing names and we don't y…
Browse files Browse the repository at this point in the history
…et have a

set of names to deduplicate against.  In this case we can just bulk-insert all
the names into the deduplicating set and move the whole field value as-is.

(Internal change: 2257497)
  • Loading branch information
gitamohr authored and pixar-oss committed Dec 8, 2022
1 parent d990339 commit 10865e2
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions pxr/usd/pcp/composeSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,38 @@ PcpComposeSiteChildNames(SdfLayerRefPtrVector const &layers,
TF_REVERSE_FOR_ALL(layer, layers) {
VtValue namesVal = (*layer)->GetField(path, namesField);
if (namesVal.IsHolding<TfTokenVector>()) {
const TfTokenVector & names =
namesVal.UncheckedGet<TfTokenVector>();
// Append names in order. Skip names that are
// already in the nameSet.
TF_FOR_ALL(name, names) {
if (nameSet->insert(*name).second) {
nameOrder->push_back(*name);
TfTokenVector names = namesVal.UncheckedRemove<TfTokenVector>();

// Append names in order. Skip names that are already in the
// nameSet.

auto doOneByOne = [&]() {
for (TfToken &name: names) {
if (nameSet->insert(name).second) {
nameOrder->push_back(std::move(name));
}
}
};

// Commonly, nameSet is empty. In this case, insert everything
// upfront, then check the size. If it is the same size as names,
// they were unique, and we can just append them all.
if (nameSet->empty()) {
nameSet->insert(names.begin(), names.end());
if (nameSet->size() == names.size()) {
*nameOrder = std::move(names);
}
else {
// This case is really, really unlikely -- sdfdata semantics
// should disallow duplicates within a single names field.
// In this case we just pay the price and do them
// one-by-one.
nameSet->clear();
doOneByOne();
}
}
else {
doOneByOne();
}
}
if (orderField) {
Expand Down

0 comments on commit 10865e2

Please sign in to comment.