Author: pmouawad
Date: Tue Sep 20 18:01:23 2016
New Revision: 1761608

URL: http://svn.apache.org/viewvc?rev=1761608&view=rev
Log:
tiny memory allocation improvements
Contributed by  Benoit Wiart (b.wiart at ubik-ingenierie.com).
this closes #229 on github

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/reporters/Summariser.java
    
jmeter/trunk/src/core/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java
    jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java
    jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
    jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/reporters/Summariser.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/reporters/Summariser.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/reporters/Summariser.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/reporters/Summariser.java Tue Sep 
20 18:01:23 2016
@@ -237,11 +237,11 @@ public class Summariser extends Abstract
     private static String format(String name, SummariserRunningSample 
summariserRunningSample, String type) {
         DecimalFormat dfDouble = new DecimalFormat("#0.0"); // $NON-NLS-1$
         StringBuilder tmp = new StringBuilder(20); // for intermediate use
-        StringBuilder sb = new StringBuilder(100); // output line buffer
+        StringBuilder sb = new StringBuilder(140); // output line buffer
         sb.append(name);
-        sb.append(" ");
+        sb.append(' ');
         sb.append(type);
-        sb.append(" ");
+        sb.append(' ');
         sb.append(longToSb(tmp, summariserRunningSample.getNumSamples(), 6));
         sb.append(" in ");
         long elapsed = summariserRunningSample.getElapsed();
@@ -263,7 +263,7 @@ public class Summariser extends Abstract
         sb.append(longToSb(tmp, summariserRunningSample.getErrorCount(), 5));
         sb.append(" (");
         sb.append(summariserRunningSample.getErrorPercentageString());
-        sb.append(")");
+        sb.append(')');
         if ("+".equals(type)) {
             ThreadCounts tc = JMeterContextService.getThreadCounts();
             sb.append(" Active: ");

Modified: 
jmeter/trunk/src/core/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/core/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java 
(original)
+++ 
jmeter/trunk/src/core/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java 
Tue Sep 20 18:01:23 2016
@@ -91,7 +91,7 @@ public class HttpSSLProtocolSocketFactor
         StringBuilder sb = new StringBuilder();
         for (int i=0;i<strings.length;i++){
             if (i>0) {
-                sb.append(" ");
+                sb.append(' ');
             }
             sb.append(strings[i]);
         }

Modified: 
jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java 
(original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java Tue 
Sep 20 18:01:23 2016
@@ -116,15 +116,15 @@ public class LogFunction extends Abstrac
         StringBuilder sb = new StringBuilder(80);
         sb.append("Log: ");
         sb.append(tn);
-        if (c.length()>0){
-            sb.append(" ");
+        if (c.length()>0) {
+            sb.append(' ');
             sb.append(c);
         } else {
             sb.append(DEFAULT_SEPARATOR);
         }
         sb.append(s);
         if (t != null) {
-            sb.append(" ");
+            sb.append(' ');
             ps.print(sb.toString());
             t.printStackTrace(ps);
         } else {
@@ -148,7 +148,7 @@ public class LogFunction extends Abstrac
                 StringBuilder sb = new StringBuilder(40);
                 sb.append(tn);
                 if (c.length()>0){
-                    sb.append(" ");
+                    sb.append(' ');
                     sb.append(c);
                 } else {
                     sb.append(DEFAULT_SEPARATOR);

Modified: 
jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java 
(original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java 
Tue Sep 20 18:01:23 2016
@@ -286,11 +286,11 @@ public class StringFromFile extends Abst
         sb.append("setParameters(");//$NON-NLS-1$
         for (int i = 0; i < values.length; i++) {
             if (i > 0) {
-                sb.append(",");
+                sb.append(',');
             }
             sb.append(((CompoundVariable) values[i]).getRawParameters());
         }
-        sb.append(")");//$NON-NLS-1$
+        sb.append(')');//$NON-NLS-1$
         log.info(sb.toString());
 
         // N.B. setParameters is called before the test proper is started,

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java 
(original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Tue Sep 
20 18:01:23 2016
@@ -168,9 +168,8 @@ public final class JOrphanUtils {
     }
 
 
-    private static final String SPACES = "                                 ";
-
-    private static final int SPACES_LEN = SPACES.length();
+    private static final char[] SPACES_CHARS = "                               
  ".toCharArray();
+    private static final int SPACES_LEN = SPACES_CHARS.length;
 
     /**
      * Right aligns some text in a StringBuilder N.B. modifies the input buffer
@@ -189,7 +188,7 @@ public final class JOrphanUtils {
         if (pfx > SPACES_LEN) {
             pfx = SPACES_LEN;
         }
-        in.insert(0, SPACES.substring(0, pfx));
+        in.insert(0, SPACES_CHARS, 0, pfx);
         return in;
     }
 
@@ -210,7 +209,7 @@ public final class JOrphanUtils {
         if (sfx > SPACES_LEN) {
             sfx = SPACES_LEN;
         }
-        in.append(SPACES.substring(0, sfx));
+        in.append(SPACES_CHARS, 0, sfx);
         return in;
     }
 
@@ -427,7 +426,7 @@ public final class JOrphanUtils {
         for (byte b : ba) {
             int j = b & 0xff;
             if (j < 16) {
-                sb.append("0"); // $NON-NLS-1$ add zero padding
+                sb.append('0'); // $NON-NLS-1$ add zero padding
             }
             sb.append(Integer.toHexString(j));
         }
@@ -449,7 +448,7 @@ public final class JOrphanUtils {
             }
             int j = ba[i] & 0xff;
             if (j < 16) {
-                sb.append("0"); // $NON-NLS-1$ add zero padding
+                sb.append('0'); // $NON-NLS-1$ add zero padding
             }
             sb.append(Integer.toHexString(j));
         }

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java
 Tue Sep 20 18:01:23 2016
@@ -33,7 +33,7 @@ import org.apache.jorphan.util.JOrphanUt
 public class Cookie extends AbstractTestElement implements Serializable {
     private static final long serialVersionUID = 240L;
 
-    private static final String TAB = "\t";
+    private static final char TAB = '\t';
 
     private static final String VALUE = "Cookie.value"; //$NON-NLS-1$
 

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
 Tue Sep 20 18:01:23 2016
@@ -164,7 +164,7 @@ public class CssParser implements LinkEx
                 StringBuilder builder = new StringBuilder();
                 for (Iterator<URL> iterator = urlCollection.iterator(); 
iterator.hasNext();) {
                     URL urlString = iterator.next();
-                    builder.append(urlString).append(",");
+                    builder.append(urlString).append(',');
                 }
                 LOG.debug("Parsed:"+baseUrl+", got:"+builder.toString());
             }

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java
 Tue Sep 20 18:01:23 2016
@@ -359,18 +359,18 @@ public final class HtmlParsingUtils {
 
     private static String printNode(Node node) {
         StringBuilder buf = new StringBuilder();
-        buf.append("<"); // $NON-NLS-1$
+        buf.append('<'); // $NON-NLS-1$
         buf.append(node.getNodeName());
         NamedNodeMap atts = node.getAttributes();
         for (int x = 0; x < atts.getLength(); x++) {
-            buf.append(" "); // $NON-NLS-1$
+            buf.append(' '); // $NON-NLS-1$
             buf.append(atts.item(x).getNodeName());
             buf.append("=\""); // $NON-NLS-1$
             buf.append(atts.item(x).getNodeValue());
             buf.append("\""); // $NON-NLS-1$
         }
 
-        buf.append(">"); // $NON-NLS-1$
+        buf.append('>'); // $NON-NLS-1$
 
         return buf.toString();
     }

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 Tue Sep 20 18:01:23 2016
@@ -715,9 +715,9 @@ public class HTTPHC4Impl extends HTTPHCA
             if (hasProxy) {
                 sb.append(" via ");
                 sb.append(proxyUser);
-                sb.append("@");
+                sb.append('@');
                 sb.append(proxyHost);
-                sb.append(":");
+                sb.append(':');
                 sb.append(proxyPort);
             }
             return sb.toString();
@@ -977,13 +977,13 @@ public class HTTPHC4Impl extends HTTPHCA
     private void writeResponseHeader(StringBuilder headerBuffer, Header 
responseHeader) {
         if(responseHeader instanceof BufferedHeader) {
             CharArrayBuffer buffer = 
((BufferedHeader)responseHeader).getBuffer();
-            headerBuffer.append(buffer.buffer(), 0, 
buffer.length()).append("\n"); // $NON-NLS-1$;
+            headerBuffer.append(buffer.buffer(), 0, 
buffer.length()).append('\n'); // $NON-NLS-1$;
         }
         else {
             headerBuffer.append(responseHeader.getName())
             .append(": ") // $NON-NLS-1$
             .append(responseHeader.getValue())
-            .append("\n"); // $NON-NLS-1$
+            .append('\n'); // $NON-NLS-1$
         }
     }
 

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
 Tue Sep 20 18:01:23 2016
@@ -147,12 +147,12 @@ public class HTTPSampleResult extends Sa
         if (u != null) {
             sb.append(' ');
             sb.append(u.toString());
-            sb.append("\n");
+            sb.append('\n');
             // Include request body if it is a post or put or patch
             if (!METHODS_WITHOUT_BODY.contains(method)) {
-                sb.append("\n"+method+" data:\n");
+                sb.append("\n").append(method).append(" data:\n");
                 sb.append(queryString);
-                sb.append("\n");
+                sb.append('\n');
             }
             if (cookies.length()>0){
                 sb.append("\nCookie Data:\n");
@@ -160,7 +160,7 @@ public class HTTPSampleResult extends Sa
             } else {
                 sb.append("\n[no cookies]");
             }
-            sb.append("\n");
+            sb.append('\n');
         }
         final String sampData = super.getSamplerData();
         if (sampData != null){

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
 Tue Sep 20 18:01:23 2016
@@ -952,7 +952,7 @@ public abstract class HTTPSamplerBase ex
         } else {
             // HTTP URLs must be absolute, allow file to be relative
             if (!path.startsWith("/")) { // $NON-NLS-1$
-                pathAndQuery.append("/"); // $NON-NLS-1$
+                pathAndQuery.append('/'); // $NON-NLS-1$
             }
         }
         pathAndQuery.append(path);

Modified: jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java 
(original)
+++ jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java Tue Sep 
20 18:01:23 2016
@@ -344,4 +344,16 @@ public class TestJorphanUtils {
         assertTrue(JOrphanUtils.isBlank("    "));
         assertFalse(JOrphanUtils.isBlank(" zdazd dzd "));
     }
+    
+    @Test
+    public void testRightAlign() {
+        StringBuilder in = new StringBuilder("AZE");
+        assertEquals("   AZE", JOrphanUtils.rightAlign(in, 6).toString());
+        in = new StringBuilder("AZERTY");
+        assertEquals("AZERTY", JOrphanUtils.rightAlign(in, 6).toString());
+        in = new StringBuilder("baulpismuth");
+        assertEquals("baulpismuth", JOrphanUtils.rightAlign(in, 6).toString());
+        in = new StringBuilder("A");
+        assertEquals("       A", JOrphanUtils.rightAlign(in, 8).toString());
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1761608&r1=1761607&r2=1761608&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue Sep 20 18:01:23 2016
@@ -159,6 +159,7 @@ Summary
     <li><bug>60085</bug>Remove cache for prepared statements, as it didn't 
work with the current jdbc pool implementation and current jdbc drivers should 
support caching of prepared statements themselves.</li>
     <li><bug>60137</bug>In Distributed testing when using StrippedXXXX modes 
strip response also on error</li>
     <li><bug>60106</bug>Settings defaults : Switch 
"jmeter.save.saveservice.connect_time" to true (after 3.0)</li>
+    <li><pr>229</pr> tiny memory allocation improvements. Contributed by 
Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>


Reply via email to