Joost - 2008-04-23


I'm currently automating the insertion of assertions for a complete dialog: basically I'm looking iteratively for all components in a dialog, and for certain types (textfield, combo, checkbox, ...) I'm adding a couple of tests automatically. It is already working fine, except for the fact that the process is slowing down after a few dialogs. For a first dialog, it is very fast, say 50 tests in a couple of seconds. For the next dialog it is still ok. For a 3rd dialog I have to wait maybe one minute, and the time is further increasing exponentially.

I have tried to find where the time goes to:

- One problem was the automatic highlighting of the last inserted test in the List. This step is not necessary since many other tests will be inserted afterwards. I could exclude it by commenting the following lines in method "addStep(Step step)" of ScriptEditor:
        scriptTable.setRowSelectionInterval(row, row);
        scriptTable.setCursorLocation(row + 1);
The same piece of code could be used after inserting all the tests.

- The other problem that I cannot solve is somewhere in the stack of method "getComponentReference(Component comp)" of ScriptEditor. This function has to be called for each component for which an assertion will be added. When digging into it I found out that most of the time goes to one method "matchExisting(final Component comp, Collection existing)" of ComponentReference, and more specifically in the following while loop:
        while (iter.hasNext()) {
            ComponentReference ref = (ComponentReference);
            if (comp == ref.getCachedLookup(ref.resolver.getHierarchy())
                || comp == ref.resolveComponent(comp, empty)) {
                matches.put(ref, Boolean.TRUE);
It looks to me that some maps are rebuilt every time for each component for which the reference has to be found, and this takes more and more time because some maps get bigger and bigger when more and more dialogs are in use.

I'm afraid that I know too little of the code to find a more efficient way to get references for all the components in the dialog. Could there be some procedure taking advantage of the fact that all components are in the same hierarchy under the selected dialog, and that they do not change during the insertion of the many tests?

Any help would be highly appreciated!