jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1754658 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/ src/protocol/http/org/apache/jmeter/protocol/http/sampler/ xdocs/
Date Sun, 31 Jul 2016 12:33:48 GMT
Author: pmouawad
Date: Sun Jul 31 12:33:47 2016
New Revision: 1754658

URL: http://svn.apache.org/viewvc?rev=1754658&view=rev
Log:
re-use pattern when possible
Contributed by Benoit Wiart (b.wiart at ubik-ingenierie.com)

This closes #216 on github.

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.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/HttpWebdav.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java?rev=1754658&r1=1754657&r2=1754658&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java Sun Jul 31 12:33:47
2016
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.samplers.SampleResult;
@@ -41,6 +42,8 @@ import org.apache.jmeter.util.JMeterUtil
 public class TimeFunction extends AbstractFunction {
 
     private static final String KEY = "__time"; // $NON-NLS-1$
+    
+    private static final Pattern DIVISOR_PATTERN = Pattern.compile("/\\d+");
 
     private static final List<String> desc = new LinkedList<>();
 
@@ -85,8 +88,7 @@ public class TimeFunction extends Abstra
             if (fmt == null) {
                 fmt = format;// Not found
             }
-            // TODO: avoid regexp parsing in loop
-            if (fmt.matches("/\\d+")) { // divisor is a positive number
+            if (DIVISOR_PATTERN.matcher(fmt).matches()) { // divisor is a positive number
                 long div = Long.parseLong(fmt.substring(1)); // should never case NFE
                 datetime = Long.toString((System.currentTimeMillis() / div));
             } else {

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=1754658&r1=1754657&r2=1754658&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
Sun Jul 31 12:33:47 2016
@@ -35,6 +35,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
 
 import javax.security.auth.Subject;
 
@@ -147,6 +148,8 @@ public class HTTPHC4Impl extends HTTPHCA
     private static final int TIME_TO_LIVE = JMeterUtils.getPropDefault("httpclient4.time_to_live",
2000);
 
     private static final String CONTEXT_METRICS = "jmeter_metrics"; // TODO hack for metrics
related to HTTPCLIENT-1081, to be removed later
+    
+    private static final Pattern PORT_PATTERN = Pattern.compile("^\\d+$");
 
     private static final ConnectionKeepAliveStrategy IDLE_STRATEGY = new DefaultConnectionKeepAliveStrategy(){
         @Override
@@ -1058,7 +1061,7 @@ public class HTTPHC4Impl extends HTTPHCA
         String[] hostParts = hostHeaderValue.split(":");
         if (hostParts.length > 1) {
             String portString = hostParts[hostParts.length - 1];
-            if (portString.matches("^\\d+$")) {
+            if (PORT_PATTERN.matcher(portString).matches()) {
                 return Integer.parseInt(portString);
             }
         }

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java?rev=1754658&r1=1754657&r2=1754658&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
Sun Jul 31 12:33:47 2016
@@ -19,6 +19,7 @@
 package org.apache.jmeter.protocol.http.sampler;
 
 import java.net.URI;
+import java.util.regex.Pattern;
 
 import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
 
@@ -28,7 +29,10 @@ import org.apache.http.client.methods.Ht
  * @since 2.12
  */
 public final class HttpWebdav extends HttpEntityEnclosingRequestBase {
-
+    // A HTTP method can be a token as specified in
+    // https://tools.ietf.org/html/rfc7230#section-3.2.6
+    private static final Pattern WEBDAV_METHOD_PATTERN = Pattern.compile("^(?i)[\\da-z!#$%&'*+\\-.^_`|~]+$");
+    
     private final String davMethod;
 
     /**
@@ -56,8 +60,6 @@ public final class HttpWebdav extends Ht
      * @return <code>true</code> if method is a Webdav one
      */
     public static boolean isWebdavMethod(String method) {
-        // A HTTP method can be a token as specified in
-        // https://tools.ietf.org/html/rfc7230#section-3.2.6
-        return method != null && method.matches("^(?i)[\\da-z!#$%&'*+\\-.^_`|~]+$");
+        return method != null && WEBDAV_METHOD_PATTERN.matcher(method).matches();
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1754658&r1=1754657&r2=1754658&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Jul 31 12:33:47 2016
@@ -127,6 +127,7 @@ Summary
     <li><pr>215</pr>Reduce duplicated code by using the newly added method
<code>GuiUtils#cancelEditing</code>.
     Contributed by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
     <li><pr>218</pr>Misc cleanup. Contributed by Benoit Wiart (b.wiart
at ubik-ingenierie.com)</li>
+    <li><pr>216</pr>Re-use pattern when possible. Contributed by Benoit
Wiart (b.wiart at ubik-ingenierie.com)</li>
 </ul>
  
  <!-- =================== Bug fixes =================== -->



Mime
View raw message