[geany/geany] 8ff8cb: Sane implementation of find_scope_members_tags()

Jiří Techet git-noreply at xxxxx
Thu Feb 11 14:35:51 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sun, 10 Jan 2016 11:31:46 UTC
Commit:      8ff8cbc3a33ba920a6113a8a9cb62ea007789641
             https://github.com/geany/geany/commit/8ff8cbc3a33ba920a6113a8a9cb62ea007789641

Log Message:
-----------
Sane implementation of find_scope_members_tags()

Disclaimer: I have absolutely no idea how the original function works.
After gazing into the code for one hour, I just gave up and wrote my own
version of it based on what I think the function should do
but maybe I'm just missing something what justifies the original
implementation's insanity.


Modified Paths:
--------------
    tagmanager/src/tm_workspace.c

Modified: tagmanager/src/tm_workspace.c
110 lines changed, 10 insertions(+), 100 deletions(-)
===================================================================
@@ -780,113 +780,23 @@ static void add_member(GPtrArray * tags, TMTag *tag)
 }
 
 
-static int
+static void
 find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
-						 const char *name, langType lang)
+						 const char *scope, langType lang)
 {
-	GPtrArray *local = g_ptr_array_new ();
-	unsigned int i;
-	TMTag *tag;
-	size_t len = strlen (name);
-	for (i = 0; (i < all->len); ++i)
+	guint i;
+
+	for (i = 0; i < all->len; ++i)
 	{
-		tag = TM_TAG (all->pdata[i]);
+		TMTag *tag = TM_TAG (all->pdata[i]);
+
 		if (tag && tag->scope && tag->scope[0] != '\0' &&
-			langs_compatible(tag->lang, lang))
-		{
-			if (0 == strncmp (name, tag->scope, len))
-			{
-				g_ptr_array_add (local, tag);
-			}
-		}
-	}
-	if (local->len > 0)
-	{
-		unsigned int j;
-		TMTag *tag2;
-		char backup = 0;
-		char *s_backup = NULL;
-		char *var_type = NULL;
-		char *scope;
-		for (i = 0; (i < local->len); ++i)
+			langs_compatible(tag->lang, lang) &&
+			strcmp(scope, tag->scope) == 0)
 		{
-			tag = TM_TAG (local->pdata[i]);
-			scope = tag->scope;
-			if (scope && 0 == strcmp (name, scope))
-			{
-				add_member (tags, tag);
-				continue;
-			}
-			s_backup = NULL;
-			j = 0;				/* someone could write better code :P */
-			while (scope)
-			{
-				if (s_backup)
-				{
-					backup = s_backup[0];
-					s_backup[0] = '\0';
-					if (0 == strcmp (name, tag->scope))
-					{
-						j = local->len;
-						s_backup[0] = backup;
-						break;
-					}
-				}
-				if (tag->file
-					&& tag->file->lang == TM_PARSER_JAVA)
-				{
-					scope = strrchr (tag->scope, '.');
-					if (scope)
-						var_type = scope + 1;
-				}
-				else
-				{
-					scope = strrchr (tag->scope, ':');
-					if (scope)
-					{
-						var_type = scope + 1;
-						scope--;
-					}
-				}
-				if (s_backup)
-				{
-					s_backup[0] = backup;
-				}
-				if (scope)
-				{
-					if (s_backup)
-					{
-						backup = s_backup[0];
-						s_backup[0] = '\0';
-					}
-					for (j = 0; (j < local->len); ++j)
-					{
-						if (i == j)
-							continue;
-						tag2 = TM_TAG (local->pdata[j]);
-						if (tag2->var_type &&
-							0 == strcmp (var_type, tag2->var_type))
-						{
-							break;
-						}
-					}
-					if (s_backup)
-						s_backup[0] = backup;
-				}
-				if (j < local->len)
-				{
-					break;
-				}
-				s_backup = scope;
-			}
-			if (j == local->len)
-			{
-				add_member (tags, tag);
-			}
+			add_member (tags, tag);
 		}
 	}
-	g_ptr_array_free (local, TRUE);
-	return (int) tags->len;
 }
 
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list