diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2017-09-23 12:05:13 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2017-09-23 12:05:13 -0400 |
commit | 09b2b146e1ec44b2a7d1f407589e207bf2b176c4 (patch) | |
tree | 0128a51e36f741b7b09acc98de06e213cab2a0c8 /src | |
parent | 93e91954a7058e122ec55421fd4c46acc8a5837d (diff) | |
download | lighttpd-git-09b2b146e1ec44b2a7d1f407589e207bf2b176c4.tar.gz |
[core] make strftime_cache_get() 16-element cache
Prior code was effectively a 1-element cache after the initial fill
of the array since only the first element was replaced after the
initial fill. New code does round-robin replacement.
(whether or not #define FILE_CACHE_MAX 16 is appropriately sized here
is a question for another day)
Diffstat (limited to 'src')
-rw-r--r-- | src/http-header-glue.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/http-header-glue.c b/src/http-header-glue.c index edbabe00..6ec1eb96 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -128,23 +128,19 @@ int http_response_redirect_to_directory(server *srv, connection *con) { } buffer * strftime_cache_get(server *srv, time_t last_mod) { + static int i; struct tm *tm; - size_t i; - for (i = 0; i < FILE_CACHE_MAX; i++) { - /* found cache-entry */ - if (srv->mtime_cache[i].mtime == last_mod) return srv->mtime_cache[i].str; - - /* found empty slot */ - if (srv->mtime_cache[i].mtime == 0) break; + for (int j = 0; j < FILE_CACHE_MAX; ++j) { + if (srv->mtime_cache[j].mtime == last_mod) + return srv->mtime_cache[j].str; /* found cache-entry */ } - if (i == FILE_CACHE_MAX) { + if (++i == FILE_CACHE_MAX) { i = 0; } srv->mtime_cache[i].mtime = last_mod; - buffer_string_prepare_copy(srv->mtime_cache[i].str, 1023); tm = gmtime(&(srv->mtime_cache[i].mtime)); buffer_append_strftime(srv->mtime_cache[i].str, "%a, %d %b %Y %H:%M:%S GMT", tm); |