Looking to the source code of java.nio.DirectByteBuffer class, I have found this:
if ((length << 0) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) ....
What is the purpose to shift length by zero bits? May this be some perfomance optimization or something else?
Bit shifting is used when the operand is being used as a series of bits rather than as a whole. In other words, the operand is treated as individual bits that stand for something and not as a value. Bit shifting is often used in programming and has at least one variation in each programming language.
<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .
@Jani A left shift corresponds by a division by 2. A right shift corresponds to multiplication my 2. This is often handy to keep in mind when doing bit shifting.
The left shift means that shift each of the bits is in binary representation toward the left. For example, when we say left shift 5 or 101 by one position. We will shift each of the bits by one position towards the left. So after shifting the number 5 towards the left by one position, the number obtained is 10 or 1010.
I think I've solved it.
In the class JavaDocs:
// -- This file was mechanically generated: Do not edit! -- //
So it is not hand coded. It was script-generated and the script writer did not add an optimisation for the case when the amount to bit shift by is zero.
Doing i << 0
is a no-op. It evaluates to the same as i
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With