From 2ce246800782edbbd9e40294952db7e61aa50515498d647ae1ba48ed858308c5 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 17 Aug 2025 21:44:49 -0400 Subject: [PATCH] Start modernizing the cache a bit. --- src/cache.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cache.cc b/src/cache.cc index c79fce1..58ad6cf 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -46,7 +46,10 @@ * Local data types */ -typedef struct { +struct CacheEntry_t +{ + ~CacheEntry_t(); + const DilloUrl *Url; /**< Cached Url. Url is used as a primary Key */ char *TypeDet; /**< MIME type string (detected from data) */ char *TypeHdr; /**< MIME type string as from the HTTP Header */ @@ -64,7 +67,7 @@ typedef struct { int ExpectedSize; /**< Goal size of the HTTP transfer (0 if unknown)*/ int TransferSize; /**< Actual length of the HTTP transfer */ uint_t Flags; /**< See Flag Defines in cache.h */ -} CacheEntry_t; +}; /* @@ -254,7 +257,7 @@ static CacheEntry_t *Cache_entry_add(const DilloUrl *Url) dList_remove(CachedURLs, old_entry); } - new_entry = dNew(CacheEntry_t, 1); + new_entry = new CacheEntry_t{}; Cache_entry_init(new_entry, Url); /* Set safe values */ dList_insert_sorted(CachedURLs, new_entry, Cache_entry_cmp); return new_entry; @@ -294,8 +297,9 @@ static void Cache_auth_free(Dlist *auth) /** * Free the components of a CacheEntry_t struct. */ -static void Cache_entry_free(CacheEntry_t *entry) +CacheEntry_t::~CacheEntry_t() { + auto *const entry= this; delete const_cast< DilloUrl * >( entry->Url ); dFree(entry->TypeDet); dFree(entry->TypeHdr); @@ -312,7 +316,6 @@ static void Cache_entry_free(CacheEntry_t *entry) a_Decode_transfer_free(entry->TransferDecoder); if (entry->ContentDecoder) a_Decode_free(entry->ContentDecoder); - dFree(entry); } /** @@ -346,7 +349,7 @@ static void Cache_entry_remove(CacheEntry_t *entry, DilloUrl *url) /* remove from cache */ dList_remove(CachedURLs, entry); - Cache_entry_free(entry); + delete entry; } /** @@ -1451,7 +1454,7 @@ void a_Cache_freeall(void) /* Remove every cache entry */ while ((data = dList_nth_data(CachedURLs, 0))) { dList_remove_fast(CachedURLs, data); - Cache_entry_free(reinterpret_cast< CacheEntry_t * >( data )); + delete reinterpret_cast< CacheEntry_t * >( data ); } /* Remove the cache list */ dList_free(CachedURLs);