From af71481a5f4b0ddb9d5ca55187981dfe9ae2558c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 17 Nov 2015 18:50:14 +0000 Subject: [PATCH] Use a hash as the skiplist key --- amiga/Makefile.target | 2 +- amiga/fnv/fnv.h | 7 ++++--- amiga/font.c | 25 ++++++++++++++++--------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index 29b3905d3..8b48b07d5 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -76,7 +76,7 @@ S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \ datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \ stringview/stringview.c stringview/urlhistory.c rtg.c \ agclass/amigaguide_class.c os3support.c font_bitmap.c \ - selectmenu.c + selectmenu.c fnv/hash_32a.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # This is the final source build list diff --git a/amiga/fnv/fnv.h b/amiga/fnv/fnv.h index 2083a4aa2..70f0e59fd 100644 --- a/amiga/fnv/fnv.h +++ b/amiga/fnv/fnv.h @@ -77,6 +77,7 @@ #define __FNV_H__ #include +#include #define FNV_VERSION "5.0.2" /* @(#) FNV Version */ @@ -84,7 +85,7 @@ /* * 32 bit FNV-0 hash type */ -typedef u_int32_t Fnv32_t; +typedef uint32_t Fnv32_t; /* @@ -115,7 +116,7 @@ typedef u_int32_t Fnv32_t; /* * determine how 64 bit unsigned values are represented */ -#include "longlong.h" +//#include "longlong.h" /* @@ -125,7 +126,7 @@ typedef u_int32_t Fnv32_t; typedef u_int64_t Fnv64_t; #else /* HAVE_64BIT_LONG_LONG */ typedef struct { - u_int32_t w32[2]; /* w32[0] is low order, w32[1] is high order word */ + uint32_t w32[2]; /* w32[0] is low order, w32[1] is high order word */ } Fnv64_t; #endif /* HAVE_64BIT_LONG_LONG */ diff --git a/amiga/font.c b/amiga/font.c index 7569bb645..0655a06e5 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -52,6 +52,9 @@ #include "amiga/utf8.h" #include "amiga/object.h" #include "amiga/schedule.h" +#ifdef __amigaos4__ +#include +#endif #define NSA_UNICODE_FONT PLOT_FONT_FAMILY_COUNT @@ -373,8 +376,10 @@ static struct ami_font_node *ami_font_open(const char *font, bool critical) struct ami_font_node *nodedata = NULL; #ifdef __amigaos4__ - nodedata = (struct ami_font_node *)FindSkipNode(ami_font_list, (APTR)font); + Fnv32_t hash = fnv_32a_str(font, FNV1_32A_INIT); + nodedata = (struct ami_font_node *)FindSkipNode(ami_font_list, (APTR)hash); #else + int hash = 0; struct nsObject *node = (struct nsObject *)FindIName((struct List *)ami_font_list, font); if(node) nodedata = node->objstruct; #endif @@ -384,10 +389,10 @@ static struct ami_font_node *ami_font_open(const char *font, bool critical) return nodedata; } - LOG("Font cache miss: %s", font); + LOG("Font cache miss: %s (%lx)", font, hash); #ifdef __amigaos4__ - nodedata = (struct ami_font_node *)InsertSkipNode(ami_font_list, (APTR)font, sizeof(struct ami_font_node)); + nodedata = (struct ami_font_node *)InsertSkipNode(ami_font_list, (APTR)hash, sizeof(struct ami_font_node)); #else nodedata = AllocVecTagList(sizeof(struct ami_font_node), NULL); #endif @@ -916,7 +921,9 @@ void ami_font_savescanner(void) #ifdef __amigaos4__ static LONG ami_font_cache_sort(struct Hook *hook, APTR key1, APTR key2) { - return stricmp(key1, key2); + if(key1 == key2) return 0; + if(key1 < key2) return -1; + return 1; } #endif @@ -936,7 +943,7 @@ static void ami_font_cleanup(struct SkipList *skiplist) SubTime(&curtime, &node->lastused); if(curtime.Seconds > 300) { - LOG("Freeing %s not used for %ld seconds", node->skip_node.sn_Key, curtime.Seconds); + LOG("Freeing %ld not used for %ld seconds", node->skip_node.sn_Key, curtime.Seconds); ami_font_close(node); RemoveSkipNode(skiplist, node->skip_node.sn_Key); } @@ -998,15 +1005,15 @@ void ami_init_fonts(void) #ifdef __amigaos4__ static void ami_font_del_skiplist(struct SkipList *skiplist) { - struct SkipNode *node; + struct ami_font_node *node; struct SkipNode *nnode; - node = GetFirstSkipNode(skiplist); + node = (struct ami_font_node *)GetFirstSkipNode(skiplist); if(node == NULL) return; do { - nnode = GetNextSkipNode(skiplist, node); - ami_font_close((struct ami_font_node *)node); + nnode = GetNextSkipNode(skiplist, (struct SkipNode *)node); + ami_font_close(node); } while((node = nnode));