Don't add the same SpellError object to a line's spell_errors list. Works around whatever bug causes gtkhtml3's memory usage to balloon in certain situations where it adds millions of duplicate SpellError objects to a line's spell_errors list. Keep the list sorted when merging objects too. The spell_errors_list_add() code is more complicated because it doesn't call g_list_append_sorted() (which would search back through the list which was already just searched anyway) but instead tries to be clever about where to insert the item if it's not found.
Created attachment 237881 [details] ignore duplicates when adding spelling error objects to a line's spell_errors list
Using a 15375 character long line of multiple words (me pressing asdfgwer and space at random times) I couldn't determine a performance difference between patched and unpatched versions with a stopwatch. Each text line keeps track of it's own spell_list, so the speed impact of searching through the spell_errors list is usually nothing since most lines will have < 10 spelling errors, even if they are computery things like patches with lots of acronyms and non-english words.
Ray; can you take a quick look at the patch too for more assurance that it's correct? Does linked list manipulation and I want to be sure it looks OK to a few people :)
Looks like it should work. An alternate approach that avoids the linked list manipulation might be to define a spell_errors_list_merge() function that consumes two sorted GLists returns a new sorted GList, free of dupes. Something roughly like (in Python): def spell_errors_list_merge(L1, L2): L3 = [] while L1 and L2: if L1[0] < L2[0]: # se_cmp() < 0 n = L1.pop(0) # g_list_remove_link() else: n = L2.pop(0) # g_list_remove_link() if not L3 or n != L3[0]: # se_cmp() != 0 L3.insert(0, n) # g_list_prepend() L3.reverse() # g_list_reverse() L3.extend(L1) # g_list_concat() L3.extend(L2) # g_list_concat() return L3
Pushing this upstream with a revised patch. See [1] for further updates. [1] http://bugzilla.gnome.org/show_bug.cgi?id=495073