[gnome-builder] vim: avoid creating regex unless other branches fail.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: avoid creating regex unless other branches fail.
- Date: Mon, 19 Jan 2015 10:56:11 +0000 (UTC)
commit 6078840e1d7ab78bfaefc203c5e8cf392e4a1af9
Author: Christian Hergert <christian hergert me>
Date: Mon Jan 19 02:54:44 2015 -0800
vim: avoid creating regex unless other branches fail.
src/vim/gb-source-vim.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index 58a385b..89b78bd 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -4039,13 +4039,11 @@ gb_source_vim_op_set (GbSourceVim *vim,
static GbSourceVimOperation
gb_source_vim_parse_operation (const gchar *command_text)
{
- GRegex *goto_line_regex;
+ GRegex *goto_line_regex = NULL;
GbSourceVimOperation ret = NULL;
g_return_val_if_fail (command_text, NULL);
- goto_line_regex = g_regex_new ("^([0-9]+|\\$)$", 0, 0, NULL);
-
if (g_str_equal (command_text, "sort"))
ret = gb_source_vim_op_sort;
else if (g_str_equal (command_text, "nohl"))
@@ -4060,10 +4058,11 @@ gb_source_vim_parse_operation (const gchar *command_text)
ret = gb_source_vim_op_search_and_replace;
else if (g_str_has_prefix (command_text, "s")) /* not ideal */
ret = gb_source_vim_op_search_and_replace;
- else if (g_regex_match (goto_line_regex, command_text, 0, NULL))
+ else if ((goto_line_regex = g_regex_new ("^([0-9]+|\\$)$", 0, 0, NULL)) &&
+ g_regex_match (goto_line_regex, command_text, 0, NULL))
ret = gb_source_vim_op_goto_line;
- g_regex_unref (goto_line_regex);
+ g_clear_pointer (&goto_line_regex, g_regex_unref);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]