You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/02/18 18:20:06 UTC

[httpcomponents-core] 06/10: Minor Improvements:

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 6d7debde616235d81906b00d30601fe464eb8046
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Wed Feb 10 08:07:23 2021 +0100

    Minor Improvements:
    
    * Unnecessary boxing
    * Unnecessary unboxing
    * inline variable
    * Change PosixParser to  DefaultParser
---
 .../hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java     | 4 +---
 .../hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java   | 4 +---
 .../main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java    | 4 ++--
 .../org/apache/hc/core5/http/support/AbstractRequestBuilder.java  | 2 +-
 .../src/main/java/org/apache/hc/core5/pool/StrictConnPool.java    | 4 ++--
 httpcore5/src/main/java/org/apache/hc/core5/util/Args.java        | 8 ++++----
 6 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
index 9e1cb7c..a1a7f4b 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http2.impl.nio;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -133,8 +132,7 @@ public class ClientHttpProtocolNegotiator extends ProtocolNegotiatorBase {
 
     private void writeOutPreface(final IOSession session) throws IOException {
         if (preface.hasRemaining()) {
-            final ByteChannel channel = session;
-            channel.write(preface);
+            session.write(preface);
         }
         if (!preface.hasRemaining()) {
             session.clearEvent(SelectionKey.OP_WRITE);
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
index 1a14b3c..a4f7df5 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http2.impl.nio;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -99,8 +98,7 @@ public class H2OnlyClientProtocolNegotiator extends ProtocolNegotiatorBase {
 
     private void writeOutPreface(final IOSession session) throws IOException  {
         if (preface.hasRemaining()) {
-            final ByteChannel channel = session;
-            channel.write(preface);
+            session.write(preface);
         }
         if (!preface.hasRemaining()) {
             session.clearEvent(SelectionKey.OP_WRITE);
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
index c3141b8..e968468 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
@@ -44,8 +44,8 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
 import org.apache.commons.cli.Options;
-import org.apache.commons.cli.PosixParser;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpConnection;
@@ -92,7 +92,7 @@ public class HttpBenchmark {
     public static void main(final String[] args) throws Exception {
 
         final Options options = CommandLineUtils.getOptions();
-        final CommandLineParser parser = new PosixParser();
+        final CommandLineParser parser = new DefaultParser();
         final CommandLine cmd = parser.parse(options, args);
 
         if (args.length == 0 || cmd.hasOption('h') || cmd.getArgs().length != 1) {
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/support/AbstractRequestBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/support/AbstractRequestBuilder.java
index e01e439..1aeb36e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/support/AbstractRequestBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/support/AbstractRequestBuilder.java
@@ -47,7 +47,7 @@ import java.util.List;
  */
 public abstract class AbstractRequestBuilder<T> extends AbstractMessageBuilder<T> {
 
-    private String method;
+    final private String method;
     private URI uri;
     private Charset charset;
     private List<NameValuePair> parameters;
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
index dfd5b36..a222bd8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
@@ -422,7 +422,7 @@ public class StrictConnPool<T, C extends ModalCloseable> implements ManagedConnP
     private int getMax(final T route) {
         final Integer v = this.maxPerRoute.get(route);
         if (v != null) {
-            return v.intValue();
+            return v;
         }
         return this.defaultMaxPerRoute;
     }
@@ -475,7 +475,7 @@ public class StrictConnPool<T, C extends ModalCloseable> implements ManagedConnP
         this.lock.lock();
         try {
             if (max > -1) {
-                this.maxPerRoute.put(route, Integer.valueOf(max));
+                this.maxPerRoute.put(route, max);
             } else {
                 this.maxPerRoute.remove(route);
             }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
index 5270a1e..25bc011 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
@@ -62,8 +62,8 @@ public class Args {
     public static int checkRange(final int value, final int lowInclusive, final int highInclusive,
                     final String message) {
         if (value < lowInclusive || value > highInclusive) {
-            throw illegalArgumentException("%s: %d is out of range [%d, %d]", message, Integer.valueOf(value),
-                            Integer.valueOf(lowInclusive), Integer.valueOf(highInclusive));
+            throw illegalArgumentException("%s: %d is out of range [%d, %d]", message, value,
+                    lowInclusive, highInclusive);
         }
         return value;
     }
@@ -71,8 +71,8 @@ public class Args {
     public static long checkRange(final long value, final long lowInclusive, final long highInclusive,
                     final String message) {
         if (value < lowInclusive || value > highInclusive) {
-            throw illegalArgumentException("%s: %d is out of range [%d, %d]", message, Long.valueOf(value),
-                            Long.valueOf(lowInclusive), Long.valueOf(highInclusive));
+            throw illegalArgumentException("%s: %d is out of range [%d, %d]", message, value,
+                    lowInclusive, highInclusive);
         }
         return value;
     }