diff options
author | Ziv Scully <ziv@mit.edu> | 2015-11-12 09:15:50 -0500 |
---|---|---|
committer | Ziv Scully <ziv@mit.edu> | 2015-11-12 09:15:50 -0500 |
commit | 011b7148c87f8b0d90abee2f454ef7689493e1f9 (patch) | |
tree | f5b03f75a02e3e5c82828452198dde19e048554d /src | |
parent | 6205c6660874af4147828e2610ca5c2feec834ad (diff) |
Simplify C interface.
Diffstat (limited to 'src')
-rw-r--r-- | src/c/urweb.c | 11 | ||||
-rw-r--r-- | src/lru_cache.sml | 11 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 30619314..71130cc7 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -488,7 +488,7 @@ struct uw_context { char *output_buffer; size_t output_buffer_size; - // For caching. + // Sqlcache. int numRecording; int recordingOffset; @@ -4616,7 +4616,8 @@ char *uw_Sqlcache_keyCopy(char *buf, char *key) { // The NUL-terminated prefix of [key] below always looks something like "_k1_k2_k3..._kn". // TODO: strlen(key) = buf - key? -uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { +uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeInvalid = cache->timeInvalid; @@ -4636,7 +4637,8 @@ uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys, int return value && value->timeValid > timeInvalid ? value : NULL; } -void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, int numKeys, uw_Sqlcache_Value *value) { +void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, uw_Sqlcache_Value *value) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeNow = uw_Sqlcache_getTimeNow(cache); @@ -4659,7 +4661,8 @@ void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, int numKeys, uw_Sq entry->value->timeValid = timeNow; } -void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { +void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeNow = uw_Sqlcache_getTimeNow(cache); diff --git a/src/lru_cache.sml b/src/lru_cache.sml index 6fcfdc55..d4da2849 100644 --- a/src/lru_cache.sml +++ b/src/lru_cache.sml @@ -62,14 +62,14 @@ fun setupQuery {index, params} = val revArgs = paramRepeatRev (fn p => "p" ^ p) ", " - val numArgs = Int.toString params - in Print.box [string ("static uw_Sqlcache_Cache cacheStruct" ^ i ^ " = {"), newline, string " .table = NULL,", newline, + string (" .numKeys = " ^ Int.toString params ^ ","), + newline, string " .timeInvalid = 0,", newline, string " .timeNow = 0};", @@ -83,8 +83,7 @@ fun setupQuery {index, params} = newline, string (" char *ks[] = {" ^ revArgs ^ "};"), newline, - string " uw_Sqlcache_Value *v = ", - string ("uw_Sqlcache_check(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), + string (" uw_Sqlcache_Value *v = uw_Sqlcache_check(cache" ^ i ^ ", ks);"), newline, (* If the output is null, it means we had too much recursion, so it's a miss. *) string " if (v && v->output != NULL) {", @@ -122,7 +121,7 @@ fun setupQuery {index, params} = newline, string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"), newline, - string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, " ^ numArgs ^ ", v);"), + string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, v);"), newline, string " return uw_unit_v;", newline, @@ -135,7 +134,7 @@ fun setupQuery {index, params} = newline, string (" char *ks[] = {" ^ revArgs ^ "};"), newline, - string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), + string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks);"), newline, string " return uw_unit_v;", newline, |