diff options
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/history.c b/src/history.c index 202549a9..59d515dc 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
27 | #include <the_Foundation/mutex.h> | 27 | #include <the_Foundation/mutex.h> |
28 | #include <the_Foundation/path.h> | 28 | #include <the_Foundation/path.h> |
29 | #include <the_Foundation/stringset.h> | 29 | #include <the_Foundation/stringset.h> |
30 | #include <math.h> | ||
30 | 31 | ||
31 | static const size_t maxStack_History_ = 50; /* back/forward navigable items */ | 32 | static const size_t maxStack_History_ = 50; /* back/forward navigable items */ |
32 | 33 | ||
@@ -285,6 +286,48 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) { | |||
285 | unlock_Mutex(d->mtx); | 286 | unlock_Mutex(d->mtx); |
286 | } | 287 | } |
287 | 288 | ||
289 | size_t cacheSize_History(const iHistory *d) { | ||
290 | size_t cached = 0; | ||
291 | lock_Mutex(d->mtx); | ||
292 | iConstForEach(Array, i, &d->recent) { | ||
293 | const iRecentUrl *url = i.value; | ||
294 | if (url->cachedResponse) { | ||
295 | cached += size_Block(&url->cachedResponse->body); | ||
296 | } | ||
297 | } | ||
298 | unlock_Mutex(d->mtx); | ||
299 | return cached; | ||
300 | } | ||
301 | |||
302 | size_t pruneLeastImportant_History(iHistory *d) { | ||
303 | size_t delta = 0; | ||
304 | size_t chosen = iInvalidPos; | ||
305 | double score = 0.0f; | ||
306 | iTime now; | ||
307 | initCurrent_Time(&now); | ||
308 | lock_Mutex(d->mtx); | ||
309 | iConstForEach(Array, i, &d->recent) { | ||
310 | const iRecentUrl *url = i.value; | ||
311 | if (url->cachedResponse) { | ||
312 | const double urlScore = | ||
313 | size_Block(&url->cachedResponse->body) * | ||
314 | pow(secondsSince_Time(&now, &url->cachedResponse->when) / 60.0, 1.25); | ||
315 | if (urlScore > score) { | ||
316 | chosen = index_ArrayConstIterator(&i); | ||
317 | score = urlScore; | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | if (chosen != iInvalidPos) { | ||
322 | iRecentUrl *url = at_Array(&d->recent, chosen); | ||
323 | delta = size_Block(&url->cachedResponse->body); | ||
324 | delete_GmResponse(url->cachedResponse); | ||
325 | url->cachedResponse = NULL; | ||
326 | } | ||
327 | unlock_Mutex(d->mtx); | ||
328 | return delta; | ||
329 | } | ||
330 | |||
288 | const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { | 331 | const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { |
289 | iStringArray *urls = iClob(new_StringArray()); | 332 | iStringArray *urls = iClob(new_StringArray()); |
290 | lock_Mutex(d->mtx); | 333 | lock_Mutex(d->mtx); |