core/src/main/java/com/orientechnologies/orient/core/record/impl/ODirtyManager.java
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;
    }
  }
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;
    }
  }
Merge the two set try to use the optimum case

@param target
@param source

@return