RFR: 8356891: Some code simplifications for basic BigIntegers' bit operations [v8]

fabioromano1 duke at openjdk.org
Mon May 19 15:21:58 UTC 2025


On Mon, 19 May 2025 15:03:51 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/BigInteger.java line 5034:
>> 
>>> 5032:      */
>>> 5033:     private byte[] magSerializedForm() {
>>> 5034:         byte[] result = new byte[(magBitLength() + 7) >>> 3];
>> 
>> I think there's a risk of overflow, so consider
>> Suggestion:
>> 
>>         byte[] result = new byte[(magBitLength() - 1 >>> 3) + 1];
>
> Ah no, there's a unsigned shift `>>>`.
> Disregard

Indeed, I had thought about this possibility too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2095957646


More information about the core-libs-dev mailing list