Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2987

Slow leftShift GDK methods

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6
    • 1.7.4, 1.8-beta-1
    • groovy-jdk
    • None

    Description

      The DGM/PDGM methods

      • StringBuffer leftShift(String, Object)
      • StringBuffer leftShift(StringBuffer, Object)
      • StringBuilder leftShift(StringBuilder, Object)

      are (up to at minimum ten times) slower than they should be. Possible faster implementations are

          public static StringBuffer leftShift(String self, Object value) {
          	final CharSequence chseq;
          	if (value instanceof CharSequence)
          		chseq = (CharSequence)value;
          	else
          		chseq = String.valueOf(value);
          	final int capacity = 2 * (self.length() + chseq.length());
              return new StringBuffer(capacity).append(self).append(chseq);
          }
      
          public static StringBuffer leftShift(StringBuffer self, Object value) {
          	if (value instanceof CharSequence)
          		return self.append((CharSequence)value);
          	else
          		return self.append(value);
          }
      
          public static StringBuilder leftShift(StringBuilder self, Object value) {
          	if (value instanceof CharSequence)
          		return self.append((CharSequence)value);
          	else
          		return self.append(value);
          }
      

      Attachments

        1. AppendPerformance.java
          1 kB
          Alexander Veit
        2. improvedLeftShift.java
          0.8 kB
          Alexander Veit

        Activity

          People

            guillaume Guillaume Sauthier
            veita Alexander Veit
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: