Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/IntVector.java @ 329:694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 13 Oct 2011 03:30:50 +0200 |
parents | a674b8590362 |
children | 15b406c7cd9d |
comparison
equal
deleted
inserted
replaced
328:a674b8590362 | 329:694ebabb5cb3 |
---|---|
55 } | 55 } |
56 | 56 |
57 public int size() { | 57 public int size() { |
58 return count; | 58 return count; |
59 } | 59 } |
60 | |
61 public void clear() { | |
62 count = 0; | |
63 } | |
64 | |
65 public void trimToSize() { | |
66 data = toArray(true); | |
67 } | |
68 | |
60 | 69 |
61 public int[] toArray() { | 70 public int[] toArray() { |
62 int[] rv = new int[count]; | 71 int[] rv = new int[count]; |
63 System.arraycopy(data, 0, rv, 0, count); | 72 System.arraycopy(data, 0, rv, 0, count); |
64 return rv; | 73 return rv; |
75 return toArray(); | 84 return toArray(); |
76 } | 85 } |
77 | 86 |
78 private void grow() { | 87 private void grow() { |
79 if (increment == 0) { | 88 if (increment == 0) { |
80 // throw specific exception right away | 89 throw new UnsupportedOperationException("This vector is not allowed to expand"); |
81 return; | |
82 } | 90 } |
83 int newCapacity = increment < 0 ? data.length << 1 : data.length + increment; | 91 int newCapacity = increment < 0 ? data.length << 1 : data.length + increment; |
84 assert newCapacity > 0 && newCapacity != data.length : newCapacity; | 92 assert newCapacity > 0 && newCapacity != data.length : newCapacity; |
85 int[] newData = new int[newCapacity]; | 93 int[] newData = new int[newCapacity]; |
86 System.arraycopy(data, 0, newData, 0, count); | 94 System.arraycopy(data, 0, newData, 0, count); |