More: Don't use DataHelper.readLong() for 1-byte reads, for efficiency

This commit is contained in:
zzz
2015-11-08 20:43:42 +00:00
parent 1aed266f70
commit 1451dc6ece
12 changed files with 14 additions and 14 deletions

View File

@ -68,7 +68,7 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl {
curIndex += Hash.HASH_LENGTH;
//_key = new Hash(keyData);
int num = (int)DataHelper.fromLong(data, curIndex, 1);
int num = data[curIndex] & 0xff;
curIndex++;
_peerHashes.clear();

View File

@ -209,7 +209,7 @@ public class DeliveryInstructions extends DataStructureImpl {
public int readBytes(byte data[], int offset) throws DataFormatException {
int cur = offset;
long flags = DataHelper.fromLong(data, cur, 1);
int flags = data[cur] & 0xff;
cur++;
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Read flags: " + flags + " mode: " + flagMode(flags));

View File

@ -85,7 +85,7 @@ public abstract class FastI2NPMessageImpl extends I2NPMessageImpl {
throw new I2NPMessageException("Payload is too short " + maxLen);
int cur = offset;
if (type < 0) {
type = (int)DataHelper.fromLong(data, cur, 1);
type = data[cur] & 0xff;
cur++;
}
_uniqueId = DataHelper.fromLong(data, cur, 4);

View File

@ -109,7 +109,7 @@ public class I2NPMessageHandler {
public int readMessage(byte data[], int offset, int maxLen) throws I2NPMessageException {
int cur = offset;
// we will assume that maxLen is >= 1 here. It's checked to be >= 16 in readBytes()
int type = (int)DataHelper.fromLong(data, cur, 1);
int type = data[cur] & 0xff;
cur++;
_lastReadBegin = System.currentTimeMillis();
I2NPMessage msg = I2NPMessageImpl.createMessage(_context, type);

View File

@ -197,7 +197,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
throw new I2NPMessageException("Payload is too short " + maxLen);
int cur = offset;
if (type < 0) {
type = (int)DataHelper.fromLong(data, cur, 1);
type = data[cur] & 0xff;
cur++;
}
_uniqueId = DataHelper.fromLong(data, cur, 4);
@ -413,7 +413,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
*/
public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset,
int len, I2NPMessageHandler handler) throws I2NPMessageException {
int type = (int)DataHelper.fromLong(buffer, offset, 1);
int type = buffer[offset] & 0xff;
offset++;
I2NPMessage msg = createMessage(ctx, type);
if (msg == null)

View File

@ -29,7 +29,7 @@ public class VariableTunnelBuildMessage extends TunnelBuildMessage {
@Override
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException {
// message type will be checked in super()
int r = (int)DataHelper.fromLong(data, offset, 1);
int r = data[offset] & 0xff;
if (r <= 0 || r > MAX_RECORD_COUNT)
throw new I2NPMessageException("Bad record count " + r);
RECORD_COUNT = r;

View File

@ -31,7 +31,7 @@ public class VariableTunnelBuildReplyMessage extends TunnelBuildReplyMessage {
@Override
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException {
// message type will be checked in super()
int r = (int)DataHelper.fromLong(data, offset, 1);
int r = data[offset] & 0xff;
if (r <= 0 || r > MAX_RECORD_COUNT)
throw new I2NPMessageException("Bad record count " + r);
RECORD_COUNT = r;

View File

@ -75,7 +75,7 @@ public class GarlicMessageParser {
private CloveSet readCloveSet(byte data[]) throws DataFormatException {
int offset = 0;
int numCloves = (int)DataHelper.fromLong(data, offset, 1);
int numCloves = data[offset] & 0xff;
offset++;
if (_log.shouldLog(Log.DEBUG))
_log.debug("# cloves to read: " + numCloves);

View File

@ -120,7 +120,7 @@ public class BuildReplyHandler {
return -1;
} else {
SimpleByteCache.release(h);
int rv = (int)DataHelper.fromLong(data, TunnelBuildReplyMessage.RECORD_SIZE - 1, 1);
int rv = data[TunnelBuildReplyMessage.RECORD_SIZE - 1] & 0xff;
if (log.shouldLog(Log.DEBUG))
log.debug(reply.getUniqueId() + ": Verified: " + rv + " for record " + recordNum + "/" + hop);
return rv;

View File

@ -340,7 +340,7 @@ class FragmentHandler {
offset += 4;
}
if (extended) {
int extendedSize = (int)DataHelper.fromLong(preprocessed, offset, 1);
int extendedSize = preprocessed[offset] & 0xff;
offset++;
offset += extendedSize; // we don't interpret these yet, but skip them for now
}