Closed GoogleCodeExporter closed 8 years ago
One way to address this would be to get the enum for the tag and to switch on
the enum.
Original comment by westm...@gmail.com
on 28 Feb 2015 at 3:30
Yes. There are some places already does it. But, I'm not sure which way is
faster (serialize? or deserialize?): 1) a byte to a byte [actual byte value in
the frame - ATypeTag.X.serialize()] 2) getting enum from a byte
[EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(byte value) to an enum].
Original comment by wangs...@gmail.com
on 28 Feb 2015 at 3:36
There is not need for deserialization.
To get from a byte to the enum value, we only need to look it up in
ATypeTag.VALUE_TYPE_MAPPING.
So the only 2 additional operations (compared to a simple byte comparison) that
we would do are
a) a cast from byte to an int (as the array index is an int) and
b) the range check when accessing the array.
However, I am not sure how many instructions those really are after the code is
JIT-compiled.
But I also think that the code is easier to read with a switch than with nested
ifs.
Original comment by westm...@gmail.com
on 28 Feb 2015 at 4:50
Till, I agree with you. Please check whether I understood your concept
correctly. The following code is what you expect?
ATypeTag argOutTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
switch (argOutTag) {
case INT64:
start = (int) LongPointable.getLong(argOut.getByteArray(), 1) - 1;
case INT32:
start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
}
-- Original
private final static byte SER_INT64_TYPE_TAG = ATypeTag.INT64.serialize();
private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
if (argOut.getByteArray()[0] == SER_INT64_TYPE_TAG) {
start = (int) LongPointable.getLong(argOut.getByteArray(), 1) - 1;
} else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
}
Original comment by wangs...@gmail.com
on 28 Feb 2015 at 5:15
Yes, that's what I thought (with the addition of "break"s in the switch cases).
Original comment by westm...@gmail.com
on 28 Feb 2015 at 6:04
Sure. I will add a break. Let's do it.
Original comment by wangs...@gmail.com
on 28 Feb 2015 at 7:10
Original comment by wangs...@gmail.com
on 6 Mar 2015 at 4:43
Original issue reported on code.google.com by
wangs...@gmail.com
on 28 Feb 2015 at 1:55