-
Notifications
You must be signed in to change notification settings - Fork 252
ut-match algorithm improvements. #1333
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
base: master
Are you sure you want to change the base?
Conversation
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.
This one looks fine
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.
This one looks bad.
Separating conditions by moving them to the nested "if()" does not improve readability.
IMO, it's more readable in this specific case, because it aligns the similar conditions. It also makes the other commits smaller. (In fact, it made me finally fully understand it, which I hadn't understood from the previous implementation.) |
"Smaller commits" should not be a reason for "worse code". } else if ( (match < UT_MATCH_BY_LINE)
&& (LOGIN_PROCESS == ut->ut_type) /* Be more picky when matching by 'ut_line' only */
&& is_my_tty(ut->ut_line))
{
match = UT_MATCH_BY_LINE;
ut_copy = *ut;
}vs } else if ( LOGIN_PROCESS == ut->ut_type /* Be more picky when matching by 'ut_line' only */
&& is_my_tty(ut->ut_line)) {
if (match < UT_MATCH_BY_LINE)
{
match = UT_MATCH_BY_LINE;
ut_copy = *ut;
}
}Simpler, shorter, better and more efficient. |
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.
Nested if() should be avoided.
I disagree. I like much better the latter (but I'd fix the braces). Both
|
|
Besides inconsistent styles, questionable readability improvements in some places, the code is fine. |
9f55b18 to
791e81b
Compare
Signed-off-by: Alejandro Colomar <[email protected]>
This function already returned NULL on some errors. It didn't make any sense to exit(3) on allocation failure. Instead, just return NULL. Signed-off-by: Alejandro Colomar <[email protected]>
Cc: "Evgeny Grin (Karlson2k)" <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
This aligns similar code, enhancing readability of the algorithm. Signed-off-by: Alejandro Colomar <[email protected]>
This tells in a more readable way what kind of match we have. I'll use this enum for simplifying other stuff in the following commit. Signed-off-by: Alejandro Colomar <[email protected]>
As Evgeny reported, malloc(3) is overkill here. He suggested using other methods, which are less than ideal, but it's true that it's overkill, and with the stack we can get something readable and more efficient. Reported-by: Evgeny Grin (Karlson2k) <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
This removes the reuse of 'ut', with which I wasn't entirely happy. It also reduces the scope between setutxent()/endutxent(). Signed-off-by: Alejandro Colomar <[email protected]>
I've optimized the algorithm in several ways (both performance and readability):
Reported-by: @Karlson2k
Queued after #1296 .
Revisions:
v2
v2b
v2c
v2d
v3