Mercurial > emacs
comparison src/mac.c @ 66879:6a3a5a23008d
(HASHKEY_QUERY_CACHE): New define.
(xrm_create_database, xrm_q_put_resource): Empty query cache.
(xrm_get_resource): Use query cache.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Tue, 15 Nov 2005 07:56:14 +0000 |
parents | f6840b4933ef |
children | 5e6f93897afb |
comparison
equal
deleted
inserted
replaced
66878:d3fa771c0ae7 | 66879:6a3a5a23008d |
---|---|
852 SINGLE_COMPONENT. Each node has a node id, which is a unique | 852 SINGLE_COMPONENT. Each node has a node id, which is a unique |
853 nonnegative integer, and the root node id is 0. A database is | 853 nonnegative integer, and the root node id is 0. A database is |
854 implemented as a hash table that maps a pair (SRC-NODE-ID . | 854 implemented as a hash table that maps a pair (SRC-NODE-ID . |
855 EDGE-LABEL) to DEST-NODE-ID. It also holds a maximum node id used | 855 EDGE-LABEL) to DEST-NODE-ID. It also holds a maximum node id used |
856 in the table as a value for HASHKEY_MAX_NID. A value associated to | 856 in the table as a value for HASHKEY_MAX_NID. A value associated to |
857 a node is recorded as a value for the node id. */ | 857 a node is recorded as a value for the node id. |
858 | |
859 A database also has a cache for past queries as a value for | |
860 HASHKEY_QUERY_CACHE. It is another hash table that maps | |
861 "NAME-STRING\0CLASS-STRING" to the result of the query. */ | |
858 | 862 |
859 #define HASHKEY_MAX_NID (make_number (0)) | 863 #define HASHKEY_MAX_NID (make_number (0)) |
864 #define HASHKEY_QUERY_CACHE (make_number (-1)) | |
860 | 865 |
861 static XrmDatabase | 866 static XrmDatabase |
862 xrm_create_database () | 867 xrm_create_database () |
863 { | 868 { |
864 XrmDatabase database; | 869 XrmDatabase database; |
866 database = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), | 871 database = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), |
867 make_float (DEFAULT_REHASH_SIZE), | 872 make_float (DEFAULT_REHASH_SIZE), |
868 make_float (DEFAULT_REHASH_THRESHOLD), | 873 make_float (DEFAULT_REHASH_THRESHOLD), |
869 Qnil, Qnil, Qnil); | 874 Qnil, Qnil, Qnil); |
870 Fputhash (HASHKEY_MAX_NID, make_number (0), database); | 875 Fputhash (HASHKEY_MAX_NID, make_number (0), database); |
876 Fputhash (HASHKEY_QUERY_CACHE, Qnil, database); | |
871 | 877 |
872 return database; | 878 return database; |
873 } | 879 } |
874 | 880 |
875 static void | 881 static void |
899 node_id = HASH_VALUE (h, i); | 905 node_id = HASH_VALUE (h, i); |
900 } | 906 } |
901 Fputhash (node_id, value, database); | 907 Fputhash (node_id, value, database); |
902 | 908 |
903 Fputhash (HASHKEY_MAX_NID, make_number (max_nid), database); | 909 Fputhash (HASHKEY_MAX_NID, make_number (max_nid), database); |
910 Fputhash (HASHKEY_QUERY_CACHE, Qnil, database); | |
904 } | 911 } |
905 | 912 |
906 /* Merge multiple resource entries specified by DATA into a resource | 913 /* Merge multiple resource entries specified by DATA into a resource |
907 database DATABASE. DATA points to the head of a null-terminated | 914 database DATABASE. DATA points to the head of a null-terminated |
908 string consisting of multiple resource lines. It's like a | 915 string consisting of multiple resource lines. It's like a |
987 Lisp_Object | 994 Lisp_Object |
988 xrm_get_resource (database, name, class) | 995 xrm_get_resource (database, name, class) |
989 XrmDatabase database; | 996 XrmDatabase database; |
990 char *name, *class; | 997 char *name, *class; |
991 { | 998 { |
992 Lisp_Object quark_name, quark_class, tmp; | 999 Lisp_Object key, query_cache, quark_name, quark_class, tmp; |
993 int nn, nc; | 1000 int i, nn, nc; |
1001 struct Lisp_Hash_Table *h; | |
1002 unsigned hash_code; | |
1003 | |
1004 nn = strlen (name); | |
1005 nc = strlen (class); | |
1006 key = make_uninit_string (nn + nc + 1); | |
1007 strcpy (SDATA (key), name); | |
1008 strncpy (SDATA (key) + nn + 1, class, nc); | |
1009 | |
1010 query_cache = Fgethash (HASHKEY_QUERY_CACHE, database, Qnil); | |
1011 if (NILP (query_cache)) | |
1012 { | |
1013 query_cache = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), | |
1014 make_float (DEFAULT_REHASH_SIZE), | |
1015 make_float (DEFAULT_REHASH_THRESHOLD), | |
1016 Qnil, Qnil, Qnil); | |
1017 Fputhash (HASHKEY_QUERY_CACHE, query_cache, database); | |
1018 } | |
1019 h = XHASH_TABLE (query_cache); | |
1020 i = hash_lookup (h, key, &hash_code); | |
1021 if (i >= 0) | |
1022 return HASH_VALUE (h, i); | |
994 | 1023 |
995 quark_name = parse_resource_name (&name); | 1024 quark_name = parse_resource_name (&name); |
996 if (*name != '\0') | 1025 if (*name != '\0') |
997 return Qnil; | 1026 return Qnil; |
998 for (tmp = quark_name, nn = 0; CONSP (tmp); tmp = XCDR (tmp), nn++) | 1027 for (tmp = quark_name, nn = 0; CONSP (tmp); tmp = XCDR (tmp), nn++) |
1007 return Qnil; | 1036 return Qnil; |
1008 | 1037 |
1009 if (nn != nc) | 1038 if (nn != nc) |
1010 return Qnil; | 1039 return Qnil; |
1011 else | 1040 else |
1012 return xrm_q_get_resource (database, quark_name, quark_class); | 1041 { |
1042 tmp = xrm_q_get_resource (database, quark_name, quark_class); | |
1043 hash_put (h, key, tmp, hash_code); | |
1044 return tmp; | |
1045 } | |
1013 } | 1046 } |
1014 | 1047 |
1015 #if TARGET_API_MAC_CARBON | 1048 #if TARGET_API_MAC_CARBON |
1016 static Lisp_Object | 1049 static Lisp_Object |
1017 xrm_cfproperty_list_to_value (plist) | 1050 xrm_cfproperty_list_to_value (plist) |