PsppireDelimitedText: Remove a useless member variable
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 6 May 2017 22:25:11 +0000 (00:25 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 6 May 2017 22:25:11 +0000 (00:25 +0200)
src/ui/gui/psppire-delimited-text.c
src/ui/gui/psppire-delimited-text.h

index a4874eefe0861909f21edbb8c6f93148fda47015..af040016d684b8089b7b9d96a001f2bd401155c1 100644 (file)
@@ -312,41 +312,42 @@ __iter_nth_child (GtkTreeModel *tree_model,
 static void
 split_row_into_fields (PsppireDelimitedText *file, gint n)
 {
-  if (n != file->cache_row)
+  if (n == file->cache_row)  /* Cache hit */
+    return;
+
+  /* Cache miss */
+  if (file->const_cache.string)
     {
-      if (file->const_cache.string)
-       {
-         ss_dealloc (&file->const_cache);
-       }
-      ss_alloc_substring (&file->const_cache, PSPPIRE_TEXT_FILE (file->child)->lines[n]);
-      file->cache = file->const_cache;
-      int field = 0;
-      file->cache_starts[0] = file->cache.string;
-      for (;
-          UINT32_MAX != ss_first_mb (file->cache);
-          ss_get_mb (&file->cache))
+      ss_dealloc (&file->const_cache);
+    }
+  ss_alloc_substring (&file->const_cache, PSPPIRE_TEXT_FILE (file->child)->lines[n]);
+  struct substring cs = file->const_cache;
+  int field = 0;
+  file->cache_starts[0] = cs.string;
+  for (;
+       UINT32_MAX != ss_first_mb (cs);
+       ss_get_mb (&cs))
+    {
+      ucs4_t xx = ss_first_mb (cs);
+      GSList *del;
+      for (del = file->delimiters; del; del = g_slist_next (del))
        {
-         ucs4_t xx = ss_first_mb (file->cache);
-         GSList *del;
-         for (del = file->delimiters; del; del = g_slist_next (del))
+         if (xx == GPOINTER_TO_INT (del->data))
            {
-             if (xx == GPOINTER_TO_INT (del->data))
+             field++;
+             int char_len = ss_first_mblen (cs);
+             file->cache_starts[field] = cs.string + char_len;
+             while (char_len > 0)
                {
-                 field++;
-                 int char_len = ss_first_mblen (file->cache);
-                 file->cache_starts[field] = file->cache.string + char_len;
-                 while (char_len > 0)
-                   {
-                     file->cache.string[char_len - 1] = '\0';
-                     char_len--;
-                   }
-                 break;
+                 cs.string[char_len - 1] = '\0';
+                 char_len--;
                }
+             break;
            }
        }
-
-      file->cache_row = n;
     }
+
+  file->cache_row = n;
 }
 
 const gchar *
index 1e1f69d116adbda69d6afeef98c8652f58afe320..d18570a83fcf16d5c1510f6db9d801b3afa4b7ee 100644 (file)
@@ -67,7 +67,6 @@ struct _PsppireDelimitedText
 
   /* caching */
   const char *cache_starts[512];
-  struct substring cache;
   struct substring const_cache;
   int cache_row;
 };