use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class FSRecords method listRoots.
@NotNull
static int[] listRoots() {
try {
r.lock();
try {
if (ourStoreRootsSeparately) {
TIntArrayList result = new TIntArrayList();
try {
try (LineNumberReader stream = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(DbConnection.myRootsFile))))) {
String str;
while ((str = stream.readLine()) != null) {
int index = str.indexOf(' ');
int id = Integer.parseInt(str.substring(0, index));
result.add(id);
}
}
} catch (FileNotFoundException ignored) {
}
return result.toNativeArray();
}
final DataInputStream input = readAttribute(ROOT_RECORD_ID, ourChildrenAttr);
if (input == null)
return ArrayUtil.EMPTY_INT_ARRAY;
try {
final int count = DataInputOutputUtil.readINT(input);
int[] result = ArrayUtil.newIntArray(count);
int prevId = 0;
for (int i = 0; i < count; i++) {
// Name
DataInputOutputUtil.readINT(input);
// Id
prevId = result[i] = DataInputOutputUtil.readINT(input) + prevId;
}
return result;
} finally {
input.close();
}
} finally {
r.unlock();
}
} catch (Throwable e) {
DbConnection.handleError(e);
return ArrayUtil.EMPTY_INT_ARRAY;
}
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class LowLevelSearchUtilTest method testProcessTextOccurrencesNeverScansBeyondStartEndOffsetIfNeverAskedTo.
public void testProcessTextOccurrencesNeverScansBeyondStartEndOffsetIfNeverAskedTo() {
StringSearcher searcher = new StringSearcher("xxx", true, true);
TIntArrayList found = new TIntArrayList(new int[] { -1 });
CharSequence text = StringUtil.repeat("xxx z ", 1000000);
PlatformTestUtil.startPerformanceTest("processTextOccurrences", 100, () -> {
for (int i = 0; i < 10000; i++) {
found.remove(0);
int startOffset = text.length() / 2 + i % 20;
int endOffset = startOffset + 8;
boolean success = LowLevelSearchUtil.processTextOccurrences(text, startOffset, endOffset, searcher, null, offset -> {
found.add(offset);
return true;
});
assertTrue(success);
assertEquals(startOffset + "," + endOffset, 1, found.size());
}
}).cpuBound().assertTiming();
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class SortedListModelTest method testRemoveViaIterator.
public void testRemoveViaIterator() {
myModel.setAll(new String[] { "1", "2", "3", "4" });
Iterator iterator = myModel.iterator();
final TIntArrayList removed = new TIntArrayList();
myModel.addListDataListener(new ListDataListener() {
@Override
public void contentsChanged(ListDataEvent e) {
throw new RuntimeException();
}
@Override
public void intervalAdded(ListDataEvent e) {
throw new RuntimeException();
}
@Override
public void intervalRemoved(ListDataEvent e) {
assertEquals(e.getIndex0(), e.getIndex1());
removed.add(e.getIndex0());
}
});
iterator.next();
iterator.remove();
assertEquals(1, removed.size());
assertEquals(0, removed.get(0));
while (iterator.hasNext()) iterator.next();
assertFalse(iterator.hasNext());
iterator.remove();
assertEquals(2, removed.size());
assertEquals(2, removed.get(1));
CHECK.compareAll(new String[] { "2", "3" }, myModel.getItems());
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class PatternCompiler method checkErrorElements.
/**
* False: there are no error elements before offset, except patternEndOffset
* Null: there are only error elements located exactly after template variables or at the end of the pattern
* True: otherwise
*/
@Nullable
private static Boolean checkErrorElements(PsiElement element, final int offset, final int patternEndOffset, final int[] varEndOffsets, final boolean strict) {
final TIntArrayList errorOffsets = new TIntArrayList();
final boolean[] containsErrorTail = { false };
final TIntHashSet varEndOffsetsSet = new TIntHashSet(varEndOffsets);
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitErrorElement(PsiErrorElement element) {
super.visitErrorElement(element);
final int startOffset = element.getTextRange().getStartOffset();
if ((strict || !varEndOffsetsSet.contains(startOffset)) && startOffset != patternEndOffset) {
errorOffsets.add(startOffset);
}
if (startOffset == offset) {
containsErrorTail[0] = true;
}
}
});
for (int i = 0; i < errorOffsets.size(); i++) {
final int errorOffset = errorOffsets.get(i);
if (errorOffset <= offset) {
return true;
}
}
return containsErrorTail[0] ? null : false;
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class TableSpeedSearch method findAllFilteredRows.
@NotNull
private TIntArrayList findAllFilteredRows(String s) {
TIntArrayList rows = new TIntArrayList();
String _s = s.trim();
for (int row = 0; row < myComponent.getRowCount(); row++) {
for (int col = 0; col < myComponent.getColumnCount(); col++) {
int index = row * myComponent.getColumnCount() + col;
if (isMatchingElement(index, _s)) {
rows.add(row);
break;
}
}
}
return rows;
}
Aggregations