Subject: bug#496: 23.0.60; ispell-word becomes increasingly slower

From: Markus Triska <[email-masked]>
Date: Sat, 28 Jun 2008 17:21:52 +0200

Eli Zaretskii <[email-masked]> writes:

> your test.el shows a similar problem with Ispell. So either Aspell and
> Ispell share the same problem, or Emacs still has something to do with
> the slowdown.

Aspell's maintainer Kevin Atkinson has generously sent me the following
patch for Aspell that fixes the problem for me with the latest CVS
version of Aspell. He says it will be in Aspell 0.60.7. Here's a simpler
test case for the problem in versions up to 0.60.6:

  while true; do echo "-"; done | aspell -a

Index: common/config.cpp
===================================================================
RCS file: /sources/aspell/aspell/common/config.cpp,v
retrieving revision 1.79
diff -u -r1.79 config.cpp
--- common/config.cpp	12 Oct 2007 00:33:17 -0000	1.79
+++ common/config.cpp	28 Jun 2008 10:42:10 -0000
@@ -1000,7 +1000,7 @@
       }
       
       assert(ki->def != 0); // if null this key should never have values
-      // directly added to it
+                            // directly added to it
       String value(entry->action == Reset ? get_default(ki) : entry->value);
       
       switch (ki->type) {
@@ -1027,11 +1027,13 @@
           goto error;
         }
 
+        clear_others(entry);
         NOTIFY_ALL(item_updated(ki, val));
         break;
         
       } case KeyInfoString:
         
+        clear_others(entry);
         NOTIFY_ALL(item_updated(ki, value));
         break;
         
@@ -1040,6 +1042,7 @@
         int num;
         
         if (sscanf(value.str(), "%i", &num) == 1 && num >= 0) {
+          clear_others(entry);
           NOTIFY_ALL(item_updated(ki, num));
         } else {
           pe = make_err(bad_value, entry->key, value, _("a positive integer"));
@@ -1049,6 +1052,9 @@
         break;
       }
       case KeyInfoList:
+
+        if (entry->action == ListSet || entry->action == ListClear)
+          clear_others(entry);
         
         NOTIFY_ALL(list_updated(ki));
         break;
@@ -1064,6 +1070,26 @@
       return (PosibErrBase &)pe;
   }
 
+  // Delete all previous entries with the same key
+  void Config::clear_others(Entry * entry) {
+
+    String & key = entry->key;
+    //printf("Clear Others For %s\n", key.c_str());
+    Entry * * cur = &first_;
+    while (*cur != entry) {
+      assert(*cur != *insert_point_);
+      if ((*cur)->key == key) {
+        //printf("JAP \"%s\"!\n", (*cur)->value.c_str());
+        Entry * tmp = *cur;
+        *cur = (*cur)->next;
+        delete tmp;
+      } else {
+        cur = &(*cur)->next;
+      }
+    }
+    
+  }
+
 #undef NOTIFY_ALL

Index: common/config.hpp
===================================================================
RCS file: /sources/aspell/aspell/common/config.hpp,v
retrieving revision 1.27
diff -u -r1.27 config.hpp
--- common/config.hpp	3 May 2005 05:08:19 -0000	1.27
+++ common/config.hpp	28 Jun 2008 10:42:10 -0000
@@ -132,6 +132,8 @@
 
     PosibErr<int> commit(Entry * entry, Conv * conv = 0);
 
+    void clear_others(Entry * entry);
+
     bool settings_read_in_;
 
   public: