-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
assert: remove code that is never reached #8132
Conversation
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string.
There appears to be some Ci infrastructure issues right now...will try again later, but the results look fine on the hosts that didn't have build issues. |
LGTM |
} else { | ||
return s; | ||
} | ||
return s.length < n ? s : s.slice(0, n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not directly s.slice(0, n)
? The String.prototype.slice
seems to cover the case s.length < endSlice
and returned what we expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. My guess is it was done this way as a micro-optimization for the common case. Seems like just calling s.slice(0,n)
as you suggest would be better.
LGTM |
LGTM |
2 similar comments
LGTM |
LGTM |
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. PR-URL: nodejs#8132 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Alexander Makarenko <estliberitas@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in 2e59cce |
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. PR-URL: #8132 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Alexander Makarenko <estliberitas@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. PR-URL: #8132 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Alexander Makarenko <estliberitas@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. PR-URL: #8132 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Alexander Makarenko <estliberitas@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. PR-URL: #8132 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Alexander Makarenko <estliberitas@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
assert
Description of change
The internal function
truncate()
is only called with the firstargument being the output of
util.inspect()
.util.inspect()
callsits own internal
formatValue()
which is guaranteed to return a string.Therefore, we can remove the check in
truncate()
that the firstargument is a string as well as code to handle the case where it is not
a string.