void add(RefQueueEntry t) throws IOException { // Common case is many iterations over the same RefQueueEntry // for the bottom of the stack (scanning all refs). Its almost // always less than the top of the queue. Avoid the queue's // O(log N) insertion and removal costs for this common case. if (!t.rc.next()) { t.rc.close(); } else if (head == null) { RefQueueEntry p = queue.peek(); if (p == null || RefQueueEntry.compare(t, p) < 0) { head = t; } else { head = queue.poll(); queue.add(t); } } else if (RefQueueEntry.compare(t, head) > 0) { queue.add(t); } else { queue.add(head); head = t; } }
private void skipShadowedRefs(String name) throws IOException { for (;;) { RefQueueEntry t = head != null ? head : queue.peek(); if (t != null && name.equals(t.name())) { add(poll()); } else { break; } } }
static int compare(RefQueueEntry a, RefQueueEntry b) { int cmp = a.name().compareTo(b.name()); if (cmp == 0) { // higher updateIndex shadows lower updateIndex. cmp = Long.signum(b.updateIndex() - a.updateIndex()); } if (cmp == 0) { // higher index shadows lower index, so higher index first. cmp = b.stackIdx - a.stackIdx; } return cmp; }
void add(RefQueueEntry t) throws IOException { // Common case is many iterations over the same RefQueueEntry // for the bottom of the stack (scanning all refs). Its almost // always less than the top of the queue. Avoid the queue's // O(log N) insertion and removal costs for this common case. if (!t.rc.next()) { t.rc.close(); } else if (head == null) { RefQueueEntry p = queue.peek(); if (p == null || RefQueueEntry.compare(t, p) < 0) { head = t; } else { head = queue.poll(); queue.add(t); } } else if (RefQueueEntry.compare(t, head) > 0) { queue.add(t); } else { queue.add(head); head = t; } }
/** {@inheritDoc} */ @Override public RefCursor seekRef(String name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRef(name), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor allRefs() throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].allRefs(), i)); } return m; }
private void skipShadowedRefs(String name) throws IOException { for (;;) { RefQueueEntry t = head != null ? head : queue.peek(); if (t != null && name.equals(t.name())) { add(poll()); } else { break; } } }
static int compare(RefQueueEntry a, RefQueueEntry b) { int cmp = a.name().compareTo(b.name()); if (cmp == 0) { // higher updateIndex shadows lower updateIndex. cmp = Long.signum(b.updateIndex() - a.updateIndex()); } if (cmp == 0) { // higher index shadows lower index, so higher index first. cmp = b.stackIdx - a.stackIdx; } return cmp; }
/** {@inheritDoc} */ @Override public RefCursor byObjectId(AnyObjectId name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].byObjectId(name), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor seekRefsWithPrefix(String prefix) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRefsWithPrefix(prefix), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor byObjectId(AnyObjectId name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].byObjectId(name), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor allRefs() throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].allRefs(), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor seekRefsWithPrefix(String prefix) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRefsWithPrefix(prefix), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor seekRef(String name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRef(name), i)); } return m; }