Skip to content

Hash ops cleanups - #9764

Merged
keszybz merged 2 commits into
systemd:masterfrom
yuwata:hash_ops-cleanups
Aug 2, 2018
Merged

keszybz merged 2 commits into
systemd:masterfrom
yuwata:hash_ops-cleanups

Conversation

@yuwata

@yuwata yuwata commented Jul 31, 2018

Copy link
Copy Markdown
Member

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The second commit looks good. But I don't particularly like the first. It makes the code longer. I'd rather prefer to accept

   if (x != y)
        return y - x;

as an idiom, and use it in all comparison functions.

(One particular advantage of the shorter version is that there's less place for typos and copy-paste errors.)

@yuwata
yuwata force-pushed the hash_ops-cleanups branch from c9d4b18 to 2357724 Compare August 2, 2018 08:07
@yuwata

yuwata commented Aug 2, 2018

Copy link
Copy Markdown
Member Author

@keszybz OK. The most part of the first commit has been dropped. Only exception is the compare function for NetworkConfigSection. The element is unsigned, so explicitly comparing the values is safer.

PTAL.

if (x->line < y->line)
return -1;
if (x->line > y->line)
return 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, that's an interesting bug. So the comparison function was borked all the time and nobody noticed.

@keszybz
keszybz merged commit 1a167ac into systemd:master Aug 2, 2018
@yuwata
yuwata deleted the hash_ops-cleanups branch August 2, 2018 13:54
@filbranden

Copy link
Copy Markdown
Contributor

How about this?
filbranden@ca75d50

(Let me know if you like it, I can polish it and test it, push a PR...)

@yuwata

yuwata commented Aug 2, 2018

Copy link
Copy Markdown
Member Author

@filbranden lgtm.

filbranden added a commit to filbranden/systemd that referenced this pull request Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants