summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimmo Saan <simmo.saan@gmail.com>2019-02-18 11:48:48 +0200
committerSimmo Saan <simmo.saan@gmail.com>2019-02-18 11:48:48 +0200
commit62dfe2ac63d4ce9c4c3f3c5d51cc9e9b227d2cd5 (patch)
tree83750555c3897199202698831843a8980ded382c
parentd512cc324adda4b0f9b8538b14156f369a915920 (diff)
downloadweechat-62dfe2ac63d4ce9c4c3f3c5d51cc9e9b227d2cd5.zip
aspell: optimize stripping of nick_completer (issue #1306)
-rw-r--r--src/plugins/aspell/weechat-aspell.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c
index 83bd16efe..6151f5be7 100644
--- a/src/plugins/aspell/weechat-aspell.c
+++ b/src/plugins/aspell/weechat-aspell.c
@@ -52,6 +52,9 @@ struct t_weechat_plugin *weechat_aspell_plugin = NULL;
int aspell_enabled = 0;
+char *aspell_nick_completer = NULL;
+int aspell_len_nick_completer = 0;
+
#ifdef USE_ENCHANT
EnchantBroker *broker = NULL;
#endif /* USE_ENCHANT */
@@ -354,28 +357,19 @@ weechat_aspell_string_is_url (const char *word)
int
weechat_aspell_string_is_nick (struct t_gui_buffer *buffer, const char *word)
{
- char *nick_completer, *pos, *pos_nick_completer, *pos_space, saved_char;
+ char *pos, *pos_nick_completer, *pos_space, saved_char;
const char *buffer_type, *buffer_nick, *buffer_channel;
- int rc, len_completer;
-
- nick_completer = weechat_string_strip (
- weechat_config_string (
- weechat_config_get ("weechat.completion.nick_completer")),
- 0, 1, " ");
- len_completer = (nick_completer) ? strlen (nick_completer) : 0;
+ int rc;
- pos_nick_completer = (nick_completer) ?
- strstr (word, nick_completer) : NULL;
+ pos_nick_completer = (aspell_nick_completer) ?
+ strstr (word, aspell_nick_completer) : NULL;
pos_space = strchr (word, ' ');
- if (nick_completer)
- free (nick_completer);
-
pos = NULL;
if (pos_nick_completer && pos_space)
{
if ((pos_nick_completer < pos_space)
- && (pos_nick_completer + len_completer == pos_space))
+ && (pos_nick_completer + aspell_len_nick_completer == pos_space))
{
pos = pos_nick_completer;
}
@@ -384,7 +378,7 @@ weechat_aspell_string_is_nick (struct t_gui_buffer *buffer, const char *word)
}
else
{
- pos = (pos_nick_completer && !pos_nick_completer[len_completer]) ?
+ pos = (pos_nick_completer && !pos_nick_completer[aspell_len_nick_completer]) ?
pos_nick_completer : pos_space;
}
@@ -1062,6 +1056,30 @@ weechat_aspell_debug_libs_cb (const void *pointer, void *data,
}
/*
+ * Callback for changes to option "weechat.completion.nick_completer".
+ */
+
+int
+weechat_aspell_config_change_nick_completer_cb (const void *pointer, void *data,
+ const char *option,
+ const char *value)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ if (aspell_nick_completer)
+ free (aspell_nick_completer);
+
+ aspell_nick_completer = weechat_string_strip (value, 0, 1, " ");
+ aspell_len_nick_completer =
+ (aspell_nick_completer) ? strlen (aspell_nick_completer) : 0;
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* Initializes aspell plugin.
*/
@@ -1114,6 +1132,15 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("debug_libs",
&weechat_aspell_debug_libs_cb, NULL, NULL);
+ weechat_hook_config ("weechat.completion.nick_completer",
+ &weechat_aspell_config_change_nick_completer_cb,
+ NULL, NULL);
+ /* manually call callback to initialize */
+ weechat_aspell_config_change_nick_completer_cb (
+ NULL, NULL, "weechat.completion.nick_completer",
+ weechat_config_string (
+ weechat_config_get ("weechat.completion.nick_completer")));
+
return WEECHAT_RC_OK;
}
@@ -1137,5 +1164,8 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
enchant_broker_free (broker);
#endif /* USE_ENCHANT */
+ if (aspell_nick_completer)
+ free (aspell_nick_completer);
+
return WEECHAT_RC_OK;
}