SF.net SVN: geany: [451] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Fri Jun 16 17:11:21 UTC 2006
Revision: 451
Author: ntrel
Date: 2006-06-16 10:11:09 -0700 (Fri, 16 Jun 2006)
ViewCVS: http://svn.sourceforge.net/geany/?rev=451&view=rev
Log Message:
-----------
Cache the current function name for efficiency in utils_get_current_function, other related fixes
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/templates.c
trunk/src/templates.h
trunk/src/utils.c
trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/ChangeLog 2006-06-16 17:11:09 UTC (rev 451)
@@ -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 at uvena.de>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/src/callbacks.c 2006-06-16 17:11:09 UTC (rev 451)
@@ -2008,7 +2008,7 @@
{
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 @@
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
- // returns the current position, so it should be safe
- pos = sci_get_position_from_line(doc_list[idx].sci, line - 1);
- }
+ // 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 @@
}
sci_insert_text(doc_list[idx].sci, pos, text);
- g_free(cur_tag);
g_free(text);
}
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/src/templates.c 2006-06-16 17:11:09 UTC (rev 451)
@@ -229,7 +229,7 @@
}
-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();
Modified: trunk/src/templates.h
===================================================================
--- trunk/src/templates.h 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/src/templates.h 2006-06-16 17:11:09 UTC (rev 451)
@@ -32,7 +32,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 *templates_get_template_gpl(gint template);
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/src/utils.c 2006-06-16 17:11:09 UTC (rev 451)
@@ -94,23 +94,14 @@
{
// 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 @@
(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,69 +956,92 @@
}
-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);
+ 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)
+ {
+ // 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;
- fold_level = sci_get_fold_level(doc_list[idx].sci, line);
- if ((fold_level & 0xFF) != 0)
+ // look first in the tag list
+ tags = utils_get_tag_list(idx, tm_tag_max_t);
+ for (; tags; tags = g_list_next(tags))
{
- while((fold_level & SC_FOLDLEVELNUMBERMASK) != SC_FOLDLEVELBASE && line >= 0)
+ tag_line = ((GeanySymbol*)tags->data)->line;
+ if (line + 1 == tag_line)
{
- fold_level = sci_get_fold_level(doc_list[idx].sci, --line);
+ cur_tag = g_strdup(strtok(((GeanySymbol*)tags->data)->str, " "));
+ *tagname = cur_tag;
+ return tag_line;
}
+ }
- // look first in the tag list
- tags = utils_get_tag_list(idx, tm_tag_max_t);
- for (; tags; tags = g_list_next(tags))
+ 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 = ((GeanySymbol*)tags->data)->line;
- if (line == tag_line)
+ tag_line = line;
+ while((fold_level & SC_FOLDLEVELNUMBERMASK) != SC_FOLDLEVELBASE && tag_line >= 0)
{
- *tagname = g_strdup(strtok(((GeanySymbol*)tags->data)->str, " "));
- return tag_line;
+ fold_level = sci_get_fold_level(doc_list[idx].sci, --tag_line);
}
- }
- start = sci_get_position_from_line(doc_list[idx].sci, 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
- && sci_get_style_at(doc_list[idx].sci, start) != SCE_C_GLOBALCLASS
- && start < last_pos) start++;
- end = start;
- // Use tmp to find SCE_C_IDENTIFIER or SCE_C_GLOBALCLASS chars
- // this fails on C++ code like 'Vek3 Vek3::mul(double s)' this code returns
- // "Vek3" because the return type of the prototype is also a GLOBALCLASS,
- // no idea how to fix at the moment
- // fails also in C with code like
- // typedef void viod;
- // viod do_nothing() {} -> return viod instead of do_nothing
- // perhaps: get the first colon, read forward the second colon and then method
- // name, then go from the first colon backwards and read class name until space
- while (((tmp = sci_get_style_at(doc_list[idx].sci, end)) == SCE_C_IDENTIFIER
- || tmp == SCE_C_GLOBALCLASS
- || sci_get_char_at(doc_list[idx].sci, end) == '~'
- || sci_get_char_at(doc_list[idx].sci, end) == ':')
- && end < last_pos) end++;
+ 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
+ && sci_get_style_at(doc_list[idx].sci, start) != SCE_C_GLOBALCLASS
+ && start < last_pos) start++;
+ end = start;
+ // Use tmp to find SCE_C_IDENTIFIER or SCE_C_GLOBALCLASS chars
+ // this fails on C++ code like 'Vek3 Vek3::mul(double s)' this code returns
+ // "Vek3" because the return type of the prototype is also a GLOBALCLASS,
+ // no idea how to fix at the moment
+ // fails also in C with code like
+ // typedef void viod;
+ // viod do_nothing() {} -> return viod instead of do_nothing
+ // perhaps: get the first colon, read forward the second colon and then method
+ // name, then go from the first colon backwards and read class name until space
+ while (((tmp = sci_get_style_at(doc_list[idx].sci, end)) == SCE_C_IDENTIFIER
+ || tmp == SCE_C_GLOBALCLASS
+ || sci_get_char_at(doc_list[idx].sci, end) == '~'
+ || 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;
}
Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h 2006-06-16 14:28:53 UTC (rev 450)
+++ trunk/src/utils.h 2006-06-16 17:11:09 UTC (rev 451)
@@ -99,7 +99,7 @@
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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list