Skip to content

Commit

Permalink
Lobby Info: simplified player list sorting code by @Ja-MiT
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 20, 2017
1 parent c6d4dff commit 29e7e57
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/game_initialization/lobby_info.cpp
Expand Up @@ -398,15 +398,7 @@ void lobby_info::sort_users(bool by_name, bool by_relation)
(u1->relation == u2->relation && translation::icompare(u1->name, u2->name) < 0);
}

if(by_name) {
return translation::icompare(u1->name, u2->name) < 0;
}

if(by_relation) {
return u1->relation < u2->relation;
}

return true;
return (by_name && translation::icompare(u1->name, u2->name) < 0) || (by_relation && u1->relation < u2->relation);
});
}

Expand Down

2 comments on commit 29e7e57

@jyrkive
Copy link
Member

Choose a reason for hiding this comment

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

This isn't any more simple IMO...

@Ja-MiT
Copy link
Contributor

@Ja-MiT Ja-MiT commented on 29e7e57 Oct 21, 2017

Choose a reason for hiding this comment

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

To be more accurate, I had presented this approach as a simplification to cfed64d, which has since been converted to the pair of if statements. Also, I presented this approach as part of an example of why trying to cram complex logic into a single return statement is often not a good idea. (While it is a single line of source code, it should produce the same executable code, at least with a decent optimizing compiler. At the same time, the single line is harder for humans to read.)

If I were to try to simplify the current code, I would instead favor the snippet I presented earlier in the discussion of PR 2099.

Please sign in to comment.