Search in sources :

Example 16 with TIntProcedure

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

the class VfsAwareMapIndexStorage method saveHashedIds.

private void saveHashedIds(@NotNull TIntHashSet hashMaskSet, int largestId, @NotNull GlobalSearchScope scope) {
    File newFileWithCaches = getSavedProjectFileValueIds(largestId, scope);
    assert newFileWithCaches != null;
    DataOutputStream stream = null;
    boolean savedSuccessfully = false;
    try {
        stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFileWithCaches)));
        DataInputOutputUtil.writeINT(stream, hashMaskSet.size());
        final DataOutputStream finalStream = stream;
        savedSuccessfully = hashMaskSet.forEach(new TIntProcedure() {

            @Override
            public boolean execute(int value) {
                try {
                    DataInputOutputUtil.writeINT(finalStream, value);
                    return true;
                } catch (IOException ex) {
                    return false;
                }
            }
        });
    } catch (IOException ignored) {
    } finally {
        if (stream != null) {
            try {
                stream.close();
                if (savedSuccessfully)
                    myLastScannedId = largestId;
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) DataOutputStream(com.intellij.util.io.DataOutputStream)

Example 17 with TIntProcedure

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

the class ChangeBufferingList method getRandomAccessContainer.

private RandomAccessIntContainer getRandomAccessContainer() {
    int[] currentChanges = changes;
    if (currentChanges == null)
        return randomAccessContainer;
    synchronized (currentChanges) {
        currentChanges = changes;
        if (currentChanges == null)
            return randomAccessContainer;
        boolean copyChanges = true;
        RandomAccessIntContainer idSet;
        if (randomAccessContainer == null) {
            int someElementsNumberEstimation = length;
            if (someElementsNumberEstimation < MAX_FILES) {
                if (!hasRemovals) {
                    if (mayHaveDupes) {
                        removingDupesAndSort();
                    }
                    idSet = new SortedIdSet(currentChanges, length);
                    copyChanges = false;
                } else {
                    idSet = new SortedIdSet(Math.max(someElementsNumberEstimation, 3));
                }
            } else if (!hasRemovals) {
                idSet = new IdBitSet(changes, length, 0);
                copyChanges = false;
            } else {
                idSet = new IdBitSet(calcMinMax(changes, length), 0);
            }
        } else if (checkSet != null) {
            idSet = (RandomAccessIntContainer) randomAccessContainer.clone();
        } else {
            idSet = randomAccessContainer;
        }
        assert idSet != null;
        if (copyChanges) {
            for (int i = 0, len = length; i < len; ++i) {
                int id = currentChanges[i];
                if (id > 0) {
                    idSet.add(id);
                } else {
                    idSet.remove(-id);
                }
            }
        }
        if (checkSet != null) {
            DebugAssertions.assertTrue(checkSet.size() == idSet.size());
            final RandomAccessIntContainer finalIdSet = idSet;
            checkSet.forEach(new TIntProcedure() {

                @Override
                public boolean execute(int value) {
                    DebugAssertions.assertTrue(finalIdSet.contains(value));
                    return true;
                }
            });
        }
        length = 0;
        hasRemovals = false;
        mayHaveDupes = false;
        randomAccessContainer = idSet;
        changes = null;
        return randomAccessContainer;
    }
}
Also used : TIntProcedure(gnu.trove.TIntProcedure)

Example 18 with TIntProcedure

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

the class ChangeTrackingValueContainer method getMergedData.

// need 'synchronized' to ensure atomic initialization of merged data
// because several threads that acquired read lock may simultaneously execute the method
private ValueContainerImpl<Value> getMergedData() {
    ValueContainerImpl<Value> merged = myMerged;
    if (merged != null) {
        return merged;
    }
    synchronized (myInitializer.getLock()) {
        merged = myMerged;
        if (merged != null) {
            return merged;
        }
        FileId2ValueMapping<Value> fileId2ValueMapping = null;
        final ValueContainer<Value> fromDisk = myInitializer.compute();
        final ValueContainerImpl<Value> newMerged;
        if (fromDisk instanceof ValueContainerImpl) {
            newMerged = ((ValueContainerImpl<Value>) fromDisk).copy();
        } else {
            newMerged = ((ChangeTrackingValueContainer<Value>) fromDisk).getMergedData().copy();
        }
        if ((myAdded != null || myInvalidated != null) && (newMerged.size() > ValueContainerImpl.NUMBER_OF_VALUES_THRESHOLD || (myAdded != null && myAdded.size() > ValueContainerImpl.NUMBER_OF_VALUES_THRESHOLD))) {
            // Calculate file ids that have Value mapped to avoid O(NumberOfValuesInMerged) during removal
            fileId2ValueMapping = new FileId2ValueMapping<Value>(newMerged);
        }
        final FileId2ValueMapping<Value> finalFileId2ValueMapping = fileId2ValueMapping;
        if (myInvalidated != null) {
            myInvalidated.forEach(new TIntProcedure() {

                @Override
                public boolean execute(int inputId) {
                    if (finalFileId2ValueMapping != null)
                        finalFileId2ValueMapping.removeFileId(inputId);
                    else
                        newMerged.removeAssociatedValue(inputId);
                    return true;
                }
            });
        }
        if (myAdded != null) {
            if (fileId2ValueMapping != null) {
                // there is no sense for value per file validation because we have fileId -> value mapping and we are enforcing it here
                fileId2ValueMapping.disableOneValuePerFileValidation();
            }
            myAdded.forEach(new ValueContainer.ContainerAction<Value>() {

                @Override
                public boolean perform(final int inputId, final Value value) {
                    // enforcing "one-value-per-file for particular key" invariant
                    if (finalFileId2ValueMapping != null)
                        finalFileId2ValueMapping.removeFileId(inputId);
                    else
                        newMerged.removeAssociatedValue(inputId);
                    newMerged.addValue(inputId, value);
                    if (finalFileId2ValueMapping != null)
                        finalFileId2ValueMapping.associateFileIdToValue(inputId, value);
                    return true;
                }
            });
        }
        setNeedsCompacting(((UpdatableValueContainer) fromDisk).needsCompacting());
        myMerged = newMerged;
        return newMerged;
    }
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) ValueContainer(com.intellij.util.indexing.ValueContainer)

Example 19 with TIntProcedure

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

the class ByteArrayList method toString.

// stringification
/**
     * Returns a String representation of the list, front to back.
     *
     * @return a {@code String} value
     */
public String toString() {
    final StringBuffer buf = new StringBuffer("{");
    forEach(new TIntProcedure() {

        @Override
        public boolean execute(int val) {
            buf.append(val);
            buf.append(", ");
            return true;
        }
    });
    buf.append("}");
    return buf.toString();
}
Also used : TIntProcedure(gnu.trove.TIntProcedure)

Example 20 with TIntProcedure

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

the class SourceLineCounterUtil method collectSrcLinesForUntouchedFiles.

public static void collectSrcLinesForUntouchedFiles(final List<Integer> uncoveredLines, byte[] content, final boolean excludeLines) {
    final ClassReader reader = new ClassReader(content);
    final SourceLineCounter collector = new SourceLineCounter(null, excludeLines, null);
    reader.accept(collector, 0);
    final TIntObjectHashMap lines = collector.getSourceLines();
    lines.forEachKey(new TIntProcedure() {

        public boolean execute(int line) {
            line--;
            uncoveredLines.add(line);
            return true;
        }
    });
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) SourceLineCounter(com.intellij.rt.coverage.instrumentation.SourceLineCounter)

Aggregations

TIntProcedure (gnu.trove.TIntProcedure)24 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 TIntArrayList (gnu.trove.TIntArrayList)5 NotNull (org.jetbrains.annotations.NotNull)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)2 MethodJavaDocHelper (com.intellij.refactoring.util.javadoc.MethodJavaDocHelper)2 DFSTBuilder (com.intellij.util.graph.DFSTBuilder)2 TIntHashSet (gnu.trove.TIntHashSet)2 ArrayList (java.util.ArrayList)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)2 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)2 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)2 ConditionalGotoInstruction (com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction)1 GotoInstruction (com.intellij.codeInspection.dataFlow.instructions.GotoInstruction)1