From 5f32cfb7d244106e77d9ec5e09161af1433ad5e9 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 16 Apr 2015 01:40:22 +0200 Subject: Prevent inserting the same Node multiple times into the nodesWithoutId vector using a set. Keep the vector in order to generate the ids in a deterministic order. --- src/transformations/uniqueid/UniqueIdTransformation.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/transformations/uniqueid/UniqueIdTransformation.cpp') diff --git a/src/transformations/uniqueid/UniqueIdTransformation.cpp b/src/transformations/uniqueid/UniqueIdTransformation.cpp index 028c1ef..6065e9d 100644 --- a/src/transformations/uniqueid/UniqueIdTransformation.cpp +++ b/src/transformations/uniqueid/UniqueIdTransformation.cpp @@ -42,6 +42,11 @@ private: */ ManagedVector nodesWithoutId; + /** + * Set preventing multi-insertion into the nodesWithoutId vector. + */ + std::unordered_set nodesWithoutIdSet; + /** * Traverse the document tree -- find all elements with primitive content. */ @@ -80,7 +85,10 @@ void UniqueIdTransformationImpl::processVariant(const Variant &var) } else if (var.isObject()) { Rooted obj = var.asObject(); if (!obj->hasDataKey("id") && obj->isa(&RttiTypes::Node)) { - nodesWithoutId.push_back(obj.cast()); + if (nodesWithoutIdSet.count(obj.get()) == 0) { + nodesWithoutId.push_back(obj.cast()); + nodesWithoutIdSet.insert(obj.get()); + } } } } -- cgit v1.2.3