From 9c7b9397c1bc47c31808b4fad512972a8fa202a2 Mon Sep 17 00:00:00 2001 From: MORIOKA Tomohiko Date: Tue, 23 Apr 2013 23:21:20 +0900 Subject: [PATCH] (cos_release_object): Fixed. (concord_object_get_feature_value): Use `fobj->value_table' as an object cache. --- cos.c | 60 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/cos.c b/cos.c index 5df8af2..db92207 100644 --- 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; } @@ -557,26 +556,21 @@ concord_decode_object (COS_object ds, COS_object genre, COS_object concord_object_get_feature_value (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 (!COS_OBJECT_DS_P (concord_current_env)) - { - concord_current_env = NULL; - return NULL; - } - - gobj = concord_get_genre (concord_current_env, "character"); if (gobj == NULL) return NULL; @@ -584,10 +578,38 @@ concord_object_get_feature_value (COS_object object, COS_object 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 (ret); + cos_hash_table_put (fobj->value_table, object, ret); + return ret; + } } -- 1.7.10.4