Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #8055]remove unnecessary math.abs() method #8056

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Willhow-Gao
Copy link
Contributor

@Willhow-Gao Willhow-Gao commented Apr 23, 2024

remove unnecessary math.abs() method in TopicPublishInfo#selectOneMessageQueue

Fixes #8055

remove unnecessary math.abs() method in TopicPublishInfo#selectOneMessageQueue

How Did You Test This Change?

In the ThreadLocalIndexTest class, there are already some test that the return value of the incrementAndGet method must be a positive number.

@@ -83,7 +83,7 @@ private MessageQueue selectOneMessageQueue(List<MessageQueue> messageQueueList,

if (filter != null && filter.length != 0) {
for (int i = 0; i < messageQueueList.size(); i++) {
int index = Math.abs(sendQueue.incrementAndGet() % messageQueueList.size());
int index = sendQueue.incrementAndGet() % messageQueueList.size();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是个 thread local int,用完会再从 0 开始,不能去掉吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解的是即使是0,做取模操作后的值也会是非负的,不需要再math.abs取绝对值吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是一个线程local int,用完会再从0开始,不能去掉吧
在同一个类里,也看到了去掉math.abs的用法,应该是确定可以去掉吧,不然下面的方法就会出bug了

image

@Willhow-Gao
Copy link
Contributor Author

@lizhimins Please cr again. thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Remove unnecessary absolute value calculations
3 participants