Maybe can remove some useless code in encodeBatch() #783
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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分支。