Skip to content

Commit

Permalink
add small optimization for reduce tracking copy with big linked graph…
Browse files Browse the repository at this point in the history
…, issue #7514
  • Loading branch information
tglman committed Aug 31, 2017
1 parent 16062b8 commit 202ca5e
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,8 @@ public boolean isSame(ODirtyManager other) {
public void merge(ODirtyManager toMerge) {
if (isSame(toMerge))
return;
final Set<ORecord> newRecords = toMerge.getNewRecords();
if (newRecords != null) {
if (this.newRecords == null)
this.newRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>(newRecords.size()));
this.newRecords.addAll(newRecords);
}
final Set<ORecord> updateRecords = toMerge.getUpdateRecords();
if (updateRecords != null) {
if (this.updateRecords == null)
this.updateRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>(updateRecords.size()));
this.updateRecords.addAll(updateRecords);
}
this.newRecords = mergeSet(this.newRecords, toMerge.getNewRecords());
this.updateRecords = mergeSet(this.updateRecords, toMerge.getUpdateRecords());
if (toMerge.getReferences() != null) {
if (references == null)
references = new IdentityHashMap<ODocument, List<OIdentifiable>>();
Expand All @@ -108,6 +98,32 @@ public void merge(ODirtyManager toMerge) {
toMerge.override(this);
}

/**
* Merge the two set try to use the optimum case
*
* @param target
* @param source
*
* @return
*/
private static Set<ORecord> mergeSet(Set<ORecord> target, Set<ORecord> source) {
if (source != null) {
if (target == null) {
return source;
} else {
if (target.size() > source.size()) {
target.addAll(source);
return target;
} else {
source.addAll(target);
return source;
}
}
} else {
return target;
}
}

public void track(ORecord pointing, OIdentifiable pointed) {
getReal().internalTrack(pointing, pointed);
}
Expand Down

0 comments on commit 202ca5e

Please sign in to comment.