Example #1
0
  private void push(Candidate toInsert) {
    if (toInsert.has(SEEN)) {
      // We have already added a Candidate for this commit to the queue,
      // this can happen if the commit is a merge base for two or more
      // parallel branches that were merged together.
      //
      // It is likely the candidate was not yet processed. The queue
      // sorts descending by commit time and usually descendant commits
      // have higher timestamps than the ancestors.
      //
      // Find the existing candidate and merge the new candidate's
      // region list into it.
      for (Candidate p = queue; p != null; p = p.queueNext) {
        if (p.canMergeRegions(toInsert)) {
          p.mergeRegions(toInsert);
          return;
        }
      }
    }
    toInsert.add(SEEN);

    // Insert into the queue using descending commit time, so
    // the most recent commit will pop next.
    int time = toInsert.getTime();
    Candidate n = queue;
    if (n == null || time >= n.getTime()) {
      toInsert.queueNext = n;
      queue = toInsert;
      return;
    }

    for (Candidate p = n; ; p = n) {
      n = p.queueNext;
      if (n == null || time >= n.getTime()) {
        toInsert.queueNext = n;
        p.queueNext = toInsert;
        return;
      }
    }
  }