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

Maybe can remove some useless code in encodeBatch() #783

Merged
merged 1 commit into from
Jul 21, 2022

Conversation

ixzk
Copy link
Contributor

@ixzk ixzk commented Mar 5, 2022

I streamlined the code of the encodeBatch() method and removed the else branch. The reasons are as follows:
The first line of encodeBatch() judges the case where len == 1. According to the judgment condition of if, else should take effect when len < 1 (ie len == 0). But the case of len == 0 is judged by checkMsg() before using the encodeBatch() method. Personally think that encodeBatch can be simplified.
Of course, the original author may need to keep the else branch from the perspective of code specifications or language features.

我精简了encodeBatch()方法的代码,删除了else分支。原因如下:
encodeBatch()第一行判断了 len == 1的情况。根据if的判断条件,else应该是len < 1时生效(即len == 0)。 但在使用encodeBatch()方法之前通过checkMsg()判断了len == 0的情况。 个人认为可以精简encodeBatch。
当然,原作者可能从代码规范或者语言特性方面考虑,需要保留else分支。

@ShannonDing ShannonDing added the codestyle code style issues label Jul 21, 2022
@ShannonDing ShannonDing added this to the 2.1.1 milestone Jul 21, 2022
Copy link
Member

@ShannonDing ShannonDing left a comment

Choose a reason for hiding this comment

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

LGTM

@ShannonDing ShannonDing merged commit 7f60ab9 into apache:master Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codestyle code style issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants