annotate src/org/tmatesoft/hg/internal/IntVector.java @ 713:661e77dc88ba tip

Mac support: respect Mac alternatives of command-line arguments for common unix tools
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 03 Aug 2014 18:09:00 +0200
parents 58a6900f845d
children
rev   line source
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
19 import java.util.Arrays;
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
20
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 /**
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 288
diff changeset
22 * Vector of primitive values
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 288
diff changeset
23 *
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 * @author Artem Tikhomirov
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 * @author TMate Software Ltd.
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 */
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
27 public class IntVector implements Cloneable {
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 private int[] data;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 private final int increment;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 private int count;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 public IntVector() {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 this(16, -1);
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 // increment == -1: grow by power of two.
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 // increment == 0: no resize (Exception will be thrown on attempt to add past capacity)
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public IntVector(int initialCapacity, int increment) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 data = new int[initialCapacity];
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 this.increment = increment;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 public void add(int v) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 if (count == data.length) {
551
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
47 grow(0);
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 data[count++] = v;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
551
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
52 public void add(int... values) {
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
53 if (count + values.length > data.length) {
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
54 grow(count + values.length);
551
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
55 }
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
56 for (int v : values) {
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
57 data[count++] = v;
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
58 }
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
59 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
60
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
61 public void addAll(IntVector other) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
62 final int otherLen = other.count;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
63 if (count + otherLen > data.length) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
64 grow(count + otherLen);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
65 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
66 for (int i = 0; i < otherLen; i++) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
67 data[count++] = other.data[i];
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
68 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
69 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
70
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 public int get(int i) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 if (i < 0 || i >= count) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 throw new IndexOutOfBoundsException(String.format("Index: %d, size: %d", i, count));
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return data[i];
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
78 public void set(int i, int v) {
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
79 if (i < 0 || i >= count) {
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
80 throw new IndexOutOfBoundsException(String.format("Index: %d, size: %d", i, count));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
81 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
82 data[i] = v;
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
83 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
84
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 public int size() {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 return count;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 }
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
88
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
89 public boolean isEmpty() {
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
90 return count == 0;
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
91 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
92
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
93 public void clear() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
94 count = 0;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
95 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
96
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
97 public void trimTo(int newSize) {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
98 if (newSize < 0 || newSize > count) {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
99 throw new IllegalArgumentException(String.format("Can't trim vector of size %d to %d", count, newSize));
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
100 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
101 count = newSize;
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
102 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
103
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
104 public void trimToSize() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
105 data = toArray(true);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
106 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
107
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 public int[] toArray() {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 int[] rv = new int[count];
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 System.arraycopy(data, 0, rv, 0, count);
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 return rv;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
114
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
115 public void reverse() {
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
116 for (int a = 0, b = count-1; a < b; a++, b--) {
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
117 int t = data[b];
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
118 data[b] = data[a];
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
119 data[a] = t;
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
120 }
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
121 }
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
122
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
123 /**
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
124 *
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
125 * @param ascending <code>true</code> to sort in ascending order, <code>false</code> for descending
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
126 */
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
127 public void sort(boolean ascending) {
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
128 Arrays.sort(data, 0, count);
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
129 if (!ascending) {
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
130 reverse();
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
131 }
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
132 }
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
133
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
134
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
135 @Override
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
136 public String toString() {
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
137 return String.format("%s[%d]", IntVector.class.getSimpleName(), size());
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
138 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
139
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
140 @Override
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
141 public IntVector clone() {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
142 try {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
143 return (IntVector) super.clone();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
144 } catch (CloneNotSupportedException ex) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
145 throw new Error(ex);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
146 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
147 }
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 /**
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 * Use only when this instance won't be used any longer
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 */
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 int[] toArray(boolean internalIfSizeMatchCapacity) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 if (count == data.length) {
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 return data;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 return toArray();
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158
551
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
159 private void grow(int newCapacityHint) {
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 if (increment == 0) {
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 328
diff changeset
161 throw new UnsupportedOperationException("This vector is not allowed to expand");
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 }
574
88afffd39899 Improve memory consumption of HgManifest#getFileRevision(): avoid extra byte[] instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
163 int newCapacity = increment < 0 ? data.length << 1 : (data.length + increment);
551
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
164 if (newCapacityHint > 0 && newCapacity < newCapacityHint) {
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
165 newCapacity = newCapacityHint;
4ea0351ca878 Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
166 }
288
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 assert newCapacity > 0 && newCapacity != data.length : newCapacity;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 int[] newData = new int[newCapacity];
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 System.arraycopy(data, 0, newData, 0, count);
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 data = newData;
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 }
b11f6a08f748 Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 }