Skip to content

Commit

Permalink
Minor performance optimization of response out of sequence check
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Jun 2, 2024
1 parent 939d4b2 commit 29b0173
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public DefaultBHttpClientConnection(
DefaultContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
DefaultContentLengthStrategy.INSTANCE;
this.responseOutOfOrderStrategy = responseOutOfOrderStrategy != null ? responseOutOfOrderStrategy :
NoResponseOutOfOrderStrategy.INSTANCE;
this.responseOutOfOrderStrategy = responseOutOfOrderStrategy;
this.consistent = true;
}

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

@Override
public void write(final byte[] b) throws IOException {
checkForEarlyResponse(totalBytes, b.length);
if (responseOutOfOrderStrategy != null) {
checkForEarlyResponse(totalBytes, b.length);
}
totalBytes += b.length;
socketOutputStream.write(b);
}

@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
checkForEarlyResponse(totalBytes, len);
if (responseOutOfOrderStrategy != null) {
checkForEarlyResponse(totalBytes, len);
}
totalBytes += len;
socketOutputStream.write(b, off, len);
}

@Override
public void write(final int b) throws IOException {
checkForEarlyResponse(totalBytes, 1);
if (responseOutOfOrderStrategy != null) {
checkForEarlyResponse(totalBytes, 1);
}
totalBytes++;
socketOutputStream.write(b);
}
Expand Down

0 comments on commit 29b0173

Please sign in to comment.