(concord_decode_object): Use `index->decoding_table' as a decoding
[chise/concord.git] / cos.c
diff --git a/cos.c b/cos.c
index db92207..39303b2 100644 (file)
--- a/cos.c
+++ b/cos.c
@@ -514,6 +514,15 @@ concord_decode_object (COS_object ds, COS_object genre,
   if (index == NULL)
     return NULL;
 
+  if ( index->decoding_table != NULL )
+    {
+      COS_object ret = cos_hash_table_get (index->decoding_table, id);
+      if (ret != NULL)
+       return ret;
+    }
+  else
+    index->decoding_table = cos_make_hash_table ();
+
   if (COS_OBJECT_INT_P (id))
     {
       snprintf(buf, 256, "%ld", cos_int_value (id));
@@ -542,14 +551,21 @@ concord_decode_object (COS_object ds, COS_object genre,
   if ( concord_index_strid_get_obj_string (index, id_str, &obj_st) )
     return NULL;
 
-  cid = cos_read_char (CONCORD_String_data (&obj_st),
-                      CONCORD_String_size (&obj_st),
-                      0, &end);
-  if ( cid >= 0 )
-    {
-      return cos_make_char (cid);
-    }
+  {
+    COS_object obj;
 
+    cid = cos_read_char (CONCORD_String_data (&obj_st),
+                        CONCORD_String_size (&obj_st),
+                        0, &end);
+    if ( cid >= 0 )
+      {
+       obj = cos_make_char (cid);
+       cos_retain_object (id);
+       cos_retain_object (obj);
+       cos_hash_table_put (index->decoding_table, id, obj);
+       return obj;
+      }
+  }
   return NULL;
 }
 
@@ -608,6 +624,7 @@ concord_object_get_feature_value (COS_object object, COS_object feature)
     if ( ret == NULL )
       return NULL;
 
+    cos_retain_object (object);
     cos_retain_object (ret);
     cos_hash_table_put (fobj->value_table, object, ret);
     return ret;