Skip to content

Commit

Permalink
[bug] byteBuffer calculate new capacity bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCooker17 committed Sep 14, 2023
1 parent 0daf6c4 commit b2bf29f
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,13 @@ private void ensureCapacity(int need) {
* @return new capacity
*/
private int calculateNewCapacity(int capacity, int minCapacity) {
int newCapacity;
int newCapacity = 0;
if (capacity == 0) {
newCapacity = DEFAULT_BUF_SIZE;
while (newCapacity < minCapacity) {
newCapacity = newCapacity << 1;
}
} else {
newCapacity = capacity << 1;

}
while (newCapacity < minCapacity) {
newCapacity = newCapacity << 1;
}
return newCapacity;
}
Expand Down

0 comments on commit b2bf29f

Please sign in to comment.