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
core: add hash seed to nick colors to allow for reshuffling of colors #635
Conversation
If you rebase your commit on top of current master, tests should be OK. |
Does exactly what it says on the tin, I've found no problems when I tested this. |
src/core/wee-config.c
Outdated
@@ -152,6 +152,7 @@ struct t_config_option *config_look_mouse; | |||
struct t_config_option *config_look_mouse_timer_delay; | |||
struct t_config_option *config_look_nick_color_force; | |||
struct t_config_option *config_look_nick_color_hash; | |||
struct t_config_option *config_look_nick_color_hash_seed; |
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.
salt
instead of seed
would be a more appropriate name: the value is used as a salt to a hash function, not as a seed to some PRNG.
src/gui/gui-nick.c
Outdated
@@ -57,7 +59,21 @@ gui_nick_hash_color (const char *nickname) | |||
if (config_num_nick_colors == 0) | |||
return 0; | |||
|
|||
ptr_nick = nickname; | |||
length = strlen (CONFIG_STRING(config_look_nick_color_hash_seed)) + |
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.
Add conditional to only do the malloc
and salt concatenation when the salt is non-empty. Avoids unnecessary allocations and string operations by default and in most cases.
For future reference, there are further micro-optimizations that could be done but aren't necessary:
|
For the first remark, I'll update the function to not allocate a new string, and using a double loop in hash algorithm (no duplicate code), to loop on both strings (if salt is set to a non-empty string). For the second remark, it could be done, but I think this is not a so critical code, and not necessary to to such optimization. |
…ffling of colors (issue #635)
Merged, thanks. |
This patch adds the possibility of shuffling nick colors without having to choose a different hash algorithm or adding/removing colors in
chat_nick_colors
. The seed option's string is prepended to the nick before it's hashed. The default of an empty string means that by default, nothing gets changed from previous versions.Feature requested by m_ben in #weechat.