Skip to content

Commit e855de5

Browse files
authored
fix: the precedence of + is higher than >> (#16312)
Motivation: Code does not take operator precedence into account. Modification: Add parenthesis to force operator precedence to match the comments. Result: Array size increments works as intended.
1 parent 578588f commit e855de5

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueEventArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void reallocIfNeeded() {
9999
*/
100100
void realloc(boolean throwIfFail) {
101101
// Double the capacity while it is "sufficiently small", and otherwise increase by 50%.
102-
int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1;
102+
int newLength = capacity <= 65536 ? capacity << 1 : capacity + (capacity >> 1);
103103

104104
try {
105105
int newCapacity = calculateBufferCapacity(newLength);

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/NativeLongArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private long memoryOffset(int index) {
8888
private void reallocIfNeeded() {
8989
if (size == capacity) {
9090
// Double the capacity while it is "sufficiently small", and otherwise increase by 50%.
91-
int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1;
91+
int newLength = capacity <= 65536 ? capacity << 1 : capacity + (capacity >> 1);
9292
int newCapacity = calculateBufferCapacity(newLength);
9393
CleanableDirectBuffer buffer = Buffer.allocateDirectBufferWithNativeOrder(newCapacity);
9494
// Copy over the old content of the memory and reset the position as we always act on the buffer as if

0 commit comments

Comments
 (0)