MyFaces Core
  1. MyFaces Core
  2. MYFACES-1864

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

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.5, 1.2.2
    • Fix Version/s: 1.2.3
    • Component/s: None
    • Labels:
      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.

        Activity

        Leonardo Uribe made changes -
        Fix Version/s 1.2.3 [ 12313144 ]
        Fix Version/s  1.1.6-SNAPSHOT [ 12312311 ]
        Fix Version/s 1.2.3-SNAPSHOT [ 12312933 ]
        Leonardo Uribe made changes -
        Field Original Value New Value
        Fix Version/s  1.1.6-SNAPSHOT [ 12312311 ]
        Fix Version/s 1.2.3-SNAPSHOT [ 12312933 ]
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Leonardo Uribe created issue -

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Leonardo Uribe
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development