Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2018-03-08 12:03:38 +0000
committerMykola Nikishov2018-03-12 11:27:44 +0000
commit1c099de68d1bb68ccfb27054281b28bd97912e5d (patch)
treedce0020f3623c811b6d4d8fee0e699b6358012c4
parenta2dbd434889870ceecde595bee0143c898c5eb41 (diff)
downloadrt.equinox.p2-1c099de68d1bb68ccfb27054281b28bd97912e5d.tar.gz
rt.equinox.p2-1c099de68d1bb68ccfb27054281b28bd97912e5d.tar.xz
rt.equinox.p2-1c099de68d1bb68ccfb27054281b28bd97912e5d.zip
Bug 532118 - Eliminate exception when checking if buffer is full in MessageDigestProcessingStep
There is common wisdom behind the claim that throwing exception may hurt performance but I have no real numbers to say it will have real impact in this case. However, in this case it is easy to avoid exception by explicitly checking if the buffer is full before putting new data into it. Change-Id: Ifbd178aff4f943c31772aa357ee8369efcee558f Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/MessageDigestProcessingStep.java10
1 files changed, 4 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/MessageDigestProcessingStep.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/MessageDigestProcessingStep.java
index 3fef57d03..2a8a16bf7 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/MessageDigestProcessingStep.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/MessageDigestProcessingStep.java
@@ -11,7 +11,6 @@
package org.eclipse.equinox.internal.p2.artifact.processors.checksum;
import java.io.IOException;
-import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumHelper;
@@ -31,13 +30,12 @@ public abstract class MessageDigestProcessingStep extends ProcessingStep {
public void write(int b) throws IOException {
getDestination().write(b);
- // TODO exceptions are expensive
- try {
- buffer.put((byte) b);
- } catch (BufferOverflowException e) {
+ boolean isBufferFull = buffer.remaining() == 0;
+ if (isBufferFull) {
processBufferredBytes();
- buffer.put((byte) b);
}
+
+ buffer.put((byte) b);
}
private void processBufferredBytes() {

Back to the top