Skip to content

Commit

Permalink
Remove Redundant bitwise operations (#13094)
Browse files Browse the repository at this point in the history
Motivation:

inverseMask is redundant since we will rightShift it with exact same amount

Modifications:

removed redundant operations

Result:

clean up
  • Loading branch information
jchrys committed Jan 4, 2023
1 parent f027fa2 commit fdfbb04
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions buffer/src/main/java/io/netty/buffer/SizeClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ public int size2SizeIdx(int size) {
int log2Delta = x < LOG2_SIZE_CLASS_GROUP + LOG2_QUANTUM + 1
? LOG2_QUANTUM : x - LOG2_SIZE_CLASS_GROUP - 1;

int deltaInverseMask = -1 << log2Delta;
int mod = (size - 1 & deltaInverseMask) >> log2Delta &
(1 << LOG2_SIZE_CLASS_GROUP) - 1;
int mod = size - 1 >> log2Delta & (1 << LOG2_SIZE_CLASS_GROUP) - 1;

return group + mod;
}
Expand Down Expand Up @@ -371,9 +369,7 @@ private int pages2pageIdxCompute(int pages, boolean floor) {
int log2Delta = x < LOG2_SIZE_CLASS_GROUP + pageShifts + 1?
pageShifts : x - LOG2_SIZE_CLASS_GROUP - 1;

int deltaInverseMask = -1 << log2Delta;
int mod = (pageSize - 1 & deltaInverseMask) >> log2Delta &
(1 << LOG2_SIZE_CLASS_GROUP) - 1;
int mod = pageSize - 1 >> log2Delta & (1 << LOG2_SIZE_CLASS_GROUP) - 1;

int pageIdx = group + mod;

Expand Down

0 comments on commit fdfbb04

Please sign in to comment.