(coll) foreach loop should use RandomAccess marker interface when possible rather than Iterable

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: core-libs

      The compiler may choose foreach loop implementation
      with respect to declared collection type.

      I proposed the following rule :
      if collection is a List that implements RandomAccess,
      use indexed loop rather than iterator loop
      else use Iterable interface.

      In order to convince you, this paragraph is extracted from
      RandomAccess documentation :

      A List implementation should implement this interface if, for typical
      instances of the class, this loop:

             for (int i=0, n=list.size(); i < n; i++)
                 list.get(i);


      runs faster than this loop:

             for (Iterator i=list.iterator(); i.hasNext(); )
                 i.next();

            Assignee:
            Unassigned
            Reporter:
            Jerry Driscoll (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: