Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-24689

Static code review sweep - Minor performance lint - MessageForums

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: RESOLVED
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.8.0
    • Fix Version/s: 2.8.2
    • Component/s: Messages Tool
    • Labels:
      None
    • Environment:
      Static code review
    • Previous Issue Keys:
      MSGCNTR-458

      Description

      Saw 1 possibly 2 minor performance bugs. Perhaps interesting for large numbers of messages.

      (1) - HierPvTMsgDataTableRender - Line 372

      for(int i=0; i<childNo; i++)

      { hideTr += "javascript:showHideDiv('_id_" + (hideDivNo+i) + "', '" + RESOURCE_PATH + "');"; }

      The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
      Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 1.5) explicitly.
      For example:
      // This is bad
      String s = "";
      for (int i = 0; i < field.length; ++i)

      { s = s + field[i]; }

      // This is better
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i < field.length; ++i)

      { buf.append(field[i]); }

      String s = buf.toString();

      (2) RendererUtil - line 210

      public static void writeAttributes(Map attributeMap, ResponseWriter writer) throws IOException
      {
      Iterator iter = attributeMap.keySet().iterator();
      while (iter.hasNext())

      { String key = (String) iter.next(); String value = (String) attributeMap.get(key); if (value == null) value = ""; writer.writeAttribute(key, value, key); }

      }

      Inefficient use of keySet iterator instead of entrySet iterator
      This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  maintenanceteam Core Team
                  Reporter:
                  arwhyte Anthony Whyte
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Git Source Code