(concord_object_get_attribute): Renamed from
[chise/concord.git] / cos.c
diff --git a/cos.c b/cos.c
index 878b8c9..39ae317 100644 (file)
--- a/cos.c
+++ b/cos.c
@@ -136,12 +136,11 @@ cos_release_object (COS_object obj)
 {
   if (COS_OBJECT_P (obj))
     {
+      ((COS_Object)obj)->header.reference_count--;
       if ( ((COS_Object)obj)->header.reference_count <= 0 )
        return (*COS_Object_release_function_table
                [((COS_Object)obj)->header.type
                 - COS_FAT_OBJECT_TYPE_MIN])(obj);
-      else
-       ((COS_Object)obj)->header.reference_count--;
     }
   return 0;
 }
@@ -386,6 +385,12 @@ cos_release_ds (COS_Object obj)
   return concord_close_ds ((COS_DS)obj);
 }
 
+int
+concord_ds_p (COS_object obj)
+{
+  return COS_OBJECT_DS_P (obj);
+}
+
 
 COS_Genre
 concord_get_genre (COS_object ds, COS_object genre)
@@ -509,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));
@@ -537,41 +551,82 @@ 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;
 }
 
 COS_object
-concord_object_get_feature_value (COS_object object, COS_object feature)
+concord_object_get_attribute (COS_object object, COS_object feature)
 {
-  char id_buf[256];
+  CONCORD_Genre gobj;
   CONCORD_Feature fobj;
-  CONCORD_String_Tank val_st;
-  size_t end;
+  COS_object ret;
 
   if (COS_OBJECT_CHAR_P (object))
     {
-      cos_utf8_print_char (object, (unsigned char*)id_buf, 256);
+      if (!COS_OBJECT_DS_P (concord_current_env))
+       {
+         concord_current_env = NULL;
+         return NULL;
+       }
+      gobj = concord_get_genre (concord_current_env, "character");
     }
   else
     return NULL;
+  if (gobj == NULL)
+    return NULL;
 
-  fobj = concord_get_feature (concord_current_env,
-                             "character", feature);
+  fobj = concord_get_feature (concord_current_env, gobj, feature);
   if (fobj == NULL)
     return NULL;
 
-  if ( concord_obj_get_feature_value_string (id_buf, fobj, &val_st) )
-    return NULL;
+  if ( fobj->value_table != NULL )
+    {
+      ret = cos_hash_table_get (fobj->value_table, object);
+      if (ret != NULL)
+       return ret;
+    }
+  else
+    fobj->value_table = cos_make_hash_table ();
+
+  {
+    char id_buf[256];
+    CONCORD_String_Tank val_st;
+    size_t end;
+
+    if (COS_OBJECT_CHAR_P (object))
+      {
+       cos_utf8_print_char (object, (unsigned char*)id_buf, 256);
+      }
+    else
+      return NULL;
+
+    if ( concord_obj_get_feature_value_string (id_buf, fobj, &val_st) )
+      return NULL;
+
+    ret = cos_read_object (CONCORD_String_data (&val_st),
+                          CONCORD_String_size (&val_st),
+                          0, &end);
+    if ( ret == NULL )
+      return NULL;
 
-  return cos_read_object (CONCORD_String_data (&val_st),
-                         CONCORD_String_size (&val_st),
-                         0, &end);
+    cos_retain_object (object);
+    cos_retain_object (ret);
+    cos_hash_table_put (fobj->value_table, object, ret);
+    return ret;
+  }
 }