Skip to content

Commit 29b0173

Browse files
committed
Minor performance optimization of response out of sequence check
1 parent 939d4b2 commit 29b0173

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ public DefaultBHttpClientConnection(
113113
DefaultContentLengthStrategy.INSTANCE;
114114
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
115115
DefaultContentLengthStrategy.INSTANCE;
116-
this.responseOutOfOrderStrategy = responseOutOfOrderStrategy != null ? responseOutOfOrderStrategy :
117-
NoResponseOutOfOrderStrategy.INSTANCE;
116+
this.responseOutOfOrderStrategy = responseOutOfOrderStrategy;
118117
this.consistent = true;
119118
}
120119

@@ -220,21 +219,27 @@ void checkForEarlyResponse(final long totalBytesSent, final int nextWriteSize) t
220219

221220
@Override
222221
public void write(final byte[] b) throws IOException {
223-
checkForEarlyResponse(totalBytes, b.length);
222+
if (responseOutOfOrderStrategy != null) {
223+
checkForEarlyResponse(totalBytes, b.length);
224+
}
224225
totalBytes += b.length;
225226
socketOutputStream.write(b);
226227
}
227228

228229
@Override
229230
public void write(final byte[] b, final int off, final int len) throws IOException {
230-
checkForEarlyResponse(totalBytes, len);
231+
if (responseOutOfOrderStrategy != null) {
232+
checkForEarlyResponse(totalBytes, len);
233+
}
231234
totalBytes += len;
232235
socketOutputStream.write(b, off, len);
233236
}
234237

235238
@Override
236239
public void write(final int b) throws IOException {
237-
checkForEarlyResponse(totalBytes, 1);
240+
if (responseOutOfOrderStrategy != null) {
241+
checkForEarlyResponse(totalBytes, 1);
242+
}
238243
totalBytes++;
239244
socketOutputStream.write(b);
240245
}

0 commit comments

Comments
 (0)