Skip to content

Commit

Permalink
Optimize object clone operation
Browse files Browse the repository at this point in the history
There's no point in checking uniqueness when cloning items.
(PrismContainer already had this optimization implemented.)
  • Loading branch information
mederly committed Jul 30, 2019
1 parent 48ec6c7 commit 3ed334a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Expand Up @@ -237,16 +237,23 @@ public void addValues(Collection<PrismPropertyValue<T>> pValuesToAdd) {
}

public void addValue(PrismPropertyValue<T> pValueToAdd) {
addValue(pValueToAdd, true);
}

public void addValue(PrismPropertyValue<T> pValueToAdd, boolean checkUniqueness) {
checkMutability();
((PrismPropertyValueImpl<T>) pValueToAdd).checkValue();
Iterator<PrismPropertyValue<T>> iterator = getValues().iterator();
while (iterator.hasNext()) {
PrismPropertyValue<T> pValue = iterator.next();
if (pValue.equals(pValueToAdd, EquivalenceStrategy.REAL_VALUE)) {
LOGGER.warn("Adding value to property "+ getElementName()+" that already exists (overwriting), value: "+pValueToAdd);
iterator.remove();
}
}
if (checkUniqueness) {
Iterator<PrismPropertyValue<T>> iterator = getValues().iterator();
while (iterator.hasNext()) {
PrismPropertyValue<T> pValue = iterator.next();
if (pValue.equals(pValueToAdd, EquivalenceStrategy.REAL_VALUE)) {
LOGGER.warn("Adding value to property " + getElementName() + " that already exists (overwriting), value: "
+ pValueToAdd);
iterator.remove();
}
}
}
pValueToAdd.setParent(this);
pValueToAdd.recompute();
getValues().add(pValueToAdd);
Expand Down Expand Up @@ -392,7 +399,7 @@ public PrismProperty<T> cloneComplex(CloneStrategy strategy) {
protected void copyValues(CloneStrategy strategy, PrismPropertyImpl<T> clone) {
super.copyValues(strategy, clone);
for (PrismPropertyValue<T> value : getValues()) {
clone.addValue(value.cloneComplex(strategy));
clone.addValue(value.cloneComplex(strategy), false);
}
}

Expand Down
Expand Up @@ -239,7 +239,7 @@ protected void copyValues(CloneStrategy strategy, PrismReferenceImpl clone) {
super.copyValues(strategy, clone);
for (PrismReferenceValue value : getValues()) {
try {
clone.add(value.cloneComplex(strategy));
clone.add(value.cloneComplex(strategy), false);
} catch (SchemaException e) {
throw new IllegalStateException("Unexpected SchemaException while copying values: " + e.getMessage(), e);
}
Expand Down

0 comments on commit 3ed334a

Please sign in to comment.