Search in sources :

Example 21 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class ControlFlowAnalyzer method getEmptyIntArray.

@NotNull
private TIntArrayList getEmptyIntArray() {
    if (intArrayPool.isEmpty()) {
        return new TIntArrayList(1);
    }
    TIntArrayList list = intArrayPool.pop();
    list.clear();
    return list;
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with TIntArrayList

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;
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with TIntArrayList

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();
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) StringSearcher(com.intellij.util.text.StringSearcher)

Example 24 with TIntArrayList

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());
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) Iterator(java.util.Iterator) ListDataListener(javax.swing.event.ListDataListener) TIntArrayList(gnu.trove.TIntArrayList)

Example 25 with TIntArrayList

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;
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) TIntHashSet(gnu.trove.TIntHashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TIntArrayList (gnu.trove.TIntArrayList)104 NotNull (org.jetbrains.annotations.NotNull)34 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Nullable (org.jetbrains.annotations.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)3 StringSearcher (com.intellij.util.text.StringSearcher)3 TIntHashSet (gnu.trove.TIntHashSet)3 TIntProcedure (gnu.trove.TIntProcedure)3 IOException (java.io.IOException)3 IDevice (com.android.ddmlib.IDevice)2 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 ElementToWorkOn (com.intellij.refactoring.introduceField.ElementToWorkOn)2 IntroduceParameterProcessor (com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2