[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patches



hi,
while looking through SOOT, I found some small improvements (correct me if i'm
    wrong!).
in soot.toolkits.scalar.ArraySparseSet.java:
    public void add(Object e)
    {
      /* Expand only if necessary! and removes one if too:) */
        // Add element
            if(!contains(e)) {
              // Expand array if necessary
              if(numElements == maxElements)
                doubleCapacity();
              elements[numElements++] = e;
            }
     }

    private void removeElementAt(int index)
    {
      /* NO!!! just copy the last element to the removed position!
        // Handle simple case
            if(index  == numElements - 1)
            {
                numElements--;
                return;
            }
············
        // Else, shift over elements
            System.arraycopy(elements, index + 1, elements, index, numElements -
(index + 1));
            numElements--;
       */
      elements[index] = elements[numElements--];
    }

    public boolean equals(Object otherFlow)
    {·······
        ArraySparseSet other = (ArraySparseSet) otherFlow;
·········
        if(other.numElements != this.numElements)
            return false;
·····
        int size = this.numElements;
·············
        // Make sure that thisFlow is contained in otherFlow··
            for(int i = 0; i < size; i++)
                if(!other.contains(this.elements[i]))
                    return false;

            /* both arrays have the same size, no element appears twice in one
             * array, all elements of ThisFlow are in otherFlow -> they are
             * equal!  we don't need to test again!
        // Make sure that otherFlow is contained in ThisFlow········
            for(int i = 0; i < size; i++)
                if(!this.contains(other.elements[i]))
                    return false;
             */
········
        return true;
    }

and a small change in soot.toolkits.scalar.BackwardFlowAnalysis.java, that
brought the flow-throughs from 190,000 to 80,000 (in my benchmark):

    protected void doAnalysis()
    {
        LinkedList changedUnits = new LinkedList();
        HashSet changedUnitsSet = new HashSet();

        // Set initial Flows and nodes to visit.
        {
            Iterator it = graph.iterator();

            while(it.hasNext())
            {
                Object s = it.next();

                /* although only a DFS could really give a good result, it is
                 * probably wiser to do begin at the bottom for
                 * Backwards-analysis*/
                changedUnits.addFirst(s);
                changedUnitsSet.add(s);

                unitToBeforeFlow.put(s, newInitialFlow());
                unitToAfterFlow.put(s, newInitialFlow());
            }
        }

mfg
 florian loitsch
ps: next time i'll send patch-files. promised.

-- 
People who think they know everything are very irritating to those of us who do.
- Anon.