Kaydet (Commit) 6010e5bf authored tarafından Nick Treleaven's avatar Nick Treleaven

Cache the current function name for efficiency in utils_get_current_function, other related fixes

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@451 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 6f864d88
......@@ -11,6 +11,9 @@
* src/notebook.c, src/notebook.h, src/main.c, src/Makefile.am:
Added currently disabled drag reordering of notebook tabs.
* src/callbacks.c: Execute: only save file if the run command uses it.
* src/templates.c, src/templates.h, src/utils.c, src/utils.h,
src/callbacks.c: Cache the current function name for efficiency in
utils_get_current_function, other related fixes.
2006-06-15 Enrico Troeger <enrico.troeger@uvena.de>
......
......@@ -2008,7 +2008,7 @@ on_comments_function_activate (GtkMenuItem *menuitem,
{
gint idx = document_get_cur_idx();
gchar *text;
gchar *cur_tag = NULL;
const gchar *cur_tag = NULL;
gint line = -1, pos = 0;
if (doc_list[idx].file_type == NULL)
......@@ -2017,14 +2017,10 @@ on_comments_function_activate (GtkMenuItem *menuitem,
return;
}
if (doc_list[idx].file_type->id != GEANY_FILETYPES_JAVA &&
doc_list[idx].file_type->id != GEANY_FILETYPES_ALL)
{
line = utils_get_current_tag(idx, &cur_tag);
// utils_get_current_tag returns -1 on failure, so sci_get_position_from_line
// utils_get_current_function returns -1 on failure, so sci_get_position_from_line
// returns the current position, so it should be safe
line = utils_get_current_function(idx, &cur_tag);
pos = sci_get_position_from_line(doc_list[idx].sci, line - 1);
}
switch (doc_list[idx].file_type->id)
{
......@@ -2049,7 +2045,6 @@ on_comments_function_activate (GtkMenuItem *menuitem,
}
sci_insert_text(doc_list[idx].sci, pos, text);
g_free(cur_tag);
g_free(text);
}
......
......@@ -229,7 +229,7 @@ gchar *templates_get_template_generic(gint template)
}
gchar *templates_get_template_function(gint template, gchar *func_name)
gchar *templates_get_template_function(gint template, const gchar *func_name)
{
gchar *result = g_strdup(templates[template]);
gchar *date = utils_get_date();
......
......@@ -32,7 +32,7 @@ gchar *templates_get_template_changelog(void);
gchar *templates_get_template_generic(gint template);
gchar *templates_get_template_function(gint template, gchar *func_name);
gchar *templates_get_template_function(gint template, const gchar *func_name);
gchar *templates_get_template_gpl(gint template);
......
......@@ -94,23 +94,14 @@ void utils_update_statusbar(gint idx, gint pos)
{
// currently text need in German and C locale about 150 chars
gchar *text = (gchar*) g_malloc0(250);
gchar *cur_tag;
const gchar *cur_tag;
guint line, col;
if (idx == -1) idx = document_get_cur_idx();
if (idx >= 0 && doc_list[idx].is_valid)
{
if (doc_list[idx].file_type == NULL ||
doc_list[idx].file_type->id == GEANY_FILETYPES_JAVA ||
doc_list[idx].file_type->id == GEANY_FILETYPES_ALL)
{
cur_tag = g_strdup(_("unknown"));
}
else
{
utils_get_current_tag(idx, &cur_tag);
}
utils_get_current_function(idx, &cur_tag);
if (pos == -1) pos = sci_get_current_position(doc_list[idx].sci);
line = sci_get_line_from_position(doc_list[idx].sci, pos);
......@@ -129,7 +120,6 @@ _("%c line: % 4d column: % 3d selection: % 4d %s mode: %s%s cur. f
(doc_list[idx].file_type) ? doc_list[idx].file_type->title : _("unknown"));
gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1);
gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text);
g_free(cur_tag);
}
else
{
......@@ -966,40 +956,59 @@ void utils_check_disk_status(gint idx)
}
gint utils_get_current_tag(gint idx, gchar **tagname)
gint utils_get_current_function(gint idx, const gchar **tagname)
{
gint tag_line;
gint pos;
static gint tag_line = -1;
gint line;
static gint old_line = -1;
static gint old_idx = -1;
static gchar *cur_tag = NULL;
gint fold_level;
gint start, end, last_pos;
gint tmp;
const GList *tags;
pos = sci_get_current_position(doc_list[idx].sci);
line = sci_get_line_from_position(doc_list[idx].sci, pos);
fold_level = sci_get_fold_level(doc_list[idx].sci, line);
if ((fold_level & 0xFF) != 0)
{
while((fold_level & SC_FOLDLEVELNUMBERMASK) != SC_FOLDLEVELBASE && line >= 0)
line = sci_get_current_line(doc_list[idx].sci, -1);
// check if the cached line and file index have changed since last time:
if (line == old_line && idx == old_idx)
{
fold_level = sci_get_fold_level(doc_list[idx].sci, --line);
// we can assume same current function as before
*tagname = cur_tag;
return tag_line;
}
g_free(cur_tag); // free the old tag, it will be replaced.
//record current line and file index for next time
old_line = line;
old_idx = idx;
// look first in the tag list
tags = utils_get_tag_list(idx, tm_tag_max_t);
for (; tags; tags = g_list_next(tags))
{
tag_line = ((GeanySymbol*)tags->data)->line;
if (line == tag_line)
if (line + 1 == tag_line)
{
*tagname = g_strdup(strtok(((GeanySymbol*)tags->data)->str, " "));
cur_tag = g_strdup(strtok(((GeanySymbol*)tags->data)->str, " "));
*tagname = cur_tag;
return tag_line;
}
}
start = sci_get_position_from_line(doc_list[idx].sci, line - 2);
if (doc_list[idx].file_type != NULL &&
doc_list[idx].file_type->id != GEANY_FILETYPES_JAVA &&
doc_list[idx].file_type->id != GEANY_FILETYPES_ALL)
{
fold_level = sci_get_fold_level(doc_list[idx].sci, line);
if ((fold_level & 0xFF) != 0)
{
tag_line = line;
while((fold_level & SC_FOLDLEVELNUMBERMASK) != SC_FOLDLEVELBASE && tag_line >= 0)
{
fold_level = sci_get_fold_level(doc_list[idx].sci, --tag_line);
}
start = sci_get_position_from_line(doc_list[idx].sci, tag_line - 2);
last_pos = sci_get_length(doc_list[idx].sci);
tmp = 0;
while (sci_get_style_at(doc_list[idx].sci, start) != SCE_C_IDENTIFIER
......@@ -1021,14 +1030,18 @@ gint utils_get_current_tag(gint idx, gchar **tagname)
|| sci_get_char_at(doc_list[idx].sci, end) == ':')
&& end < last_pos) end++;
*tagname = g_malloc(end - start + 1);
sci_get_text_range(doc_list[idx].sci, start, end, *tagname);
cur_tag = g_malloc(end - start + 1);
sci_get_text_range(doc_list[idx].sci, start, end, cur_tag);
*tagname = cur_tag;
return line;
return tag_line;
}
}
*tagname = g_strdup(_("unknown"));
return -1;
cur_tag = g_strdup(_("unknown"));
*tagname = cur_tag;
tag_line = -1;
return tag_line;
}
......
......@@ -99,7 +99,7 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag)
void utils_check_disk_status(gint idx);
//gchar *utils_get_current_tag(gint idx, gint direction);
gint utils_get_current_tag(gint idx, gchar **tagname);
gint utils_get_current_function(gint idx, const gchar **tagname);
void utils_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment