diff options
| author | YAMAMOTO Mitsuharu | 2005-11-15 07:56:27 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2005-11-15 07:56:27 +0000 |
| commit | fc09d07f39284e1120c4aab51f56ded01830cb0d (patch) | |
| tree | 6bf6500943ace183b15a5be6969aec68a24f8605 /src/mac.c | |
| parent | 308a660736c673a6596f980c382fca5187068978 (diff) | |
| download | emacs-fc09d07f39284e1120c4aab51f56ded01830cb0d.tar.gz emacs-fc09d07f39284e1120c4aab51f56ded01830cb0d.zip | |
(HASHKEY_QUERY_CACHE): New define.
(xrm_create_database, xrm_q_put_resource): Empty query cache.
(xrm_get_resource): Use query cache.
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 41 |
1 files changed, 37 insertions, 4 deletions
| @@ -854,9 +854,14 @@ parse_resource_line (p) | |||
| 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 () |
| @@ -868,6 +873,7 @@ xrm_create_database () | |||
| 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 | } |
| @@ -901,6 +907,7 @@ xrm_q_put_resource (database, quarks, value) | |||
| 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 |
| @@ -989,8 +996,30 @@ 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') |
| @@ -1009,7 +1038,11 @@ xrm_get_resource (database, name, class) | |||
| 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 |