Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-1864

Enhance UIComponentBase.getFacetsAndChildren(), creating _FacetsAndChildrenIterator only when it is necessary

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.5, 1.2.2
    • 1.2.3
    • None
    • None

    Description

      The actual implementation for UIComponentBase.getFacetsAndChildren() is this:

      public Iterator<UIComponent> getFacetsAndChildren()

      { return new _FacetsAndChildrenIterator<UIComponent>(_facetMap, _childrenList); }

      In most cases there is no children and there is not facets defined, and the creation of this object holds references to facetMap and childrenList iterators, causing possible memory leaks.

      The idea is use a similar strategy used in trinidad, avoiding the use of a list and using the compound iterator:

      public Iterator<UIComponent> getFacetsAndChildren()
      {
      // =-=AEW Is this supposed to be an immutable Iterator?
      if (_facets == null)

      { if (_children == null) return _EMPTY_UICOMPONENT_ITERATOR; return _children.iterator(); }

      else

      { if (_children == null) return _facets.values().iterator(); }

      ArrayList<UIComponent> childrenAndFacets = new ArrayList<UIComponent>();
      for(UIComponent facet : _facets.values())

      { childrenAndFacets.add(facet); }

      for(UIComponent child : _children)

      { childrenAndFacets.add(child); }

      if (childrenAndFacets.isEmpty())
      return _EMPTY_UICOMPONENT_ITERATOR;

      return childrenAndFacets.iterator();
      }

      also on _FacetsAndChildrenIterator use something like this:

      public boolean hasNext()
      {
      boolean hasNext = (_facetsIterator != null && _facetsIterator.hasNext()) ||
      (_childrenIterator != null && _childrenIterator.hasNext());
      if (!hasNext)

      { _facetsIterator = null; _childrenIterator = null; }

      return hasNext;
      }

      Before hasNext() returns false, set the references to the iterators to null, since this references no longer be used after this;

      Also create a class _EmptyIterator<E> to reuse this like trinidad does.

      Attachments

        Activity

          People

            lu4242 Leonardo Uribe
            lu4242 Leonardo Uribe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: