diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tagcache.c | 60 | ||||
-rw-r--r-- | apps/tagcache.h | 2 | ||||
-rw-r--r-- | apps/tagtree.c | 2 |
3 files changed, 56 insertions, 8 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 248e57237d..d09ddf486a 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -1209,7 +1209,7 @@ bool tagcache_check_clauses(struct tagcache_search *tcs, | |||
1209 | return check_clauses(tcs, &idx, clause, count); | 1209 | return check_clauses(tcs, &idx, clause, count); |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | static bool add_uniqbuf(struct tagcache_search *tcs, unsigned long id) | 1212 | static bool add_uniqbuf(struct tagcache_search *tcs, uint32_t id) |
1213 | { | 1213 | { |
1214 | int i; | 1214 | int i; |
1215 | 1215 | ||
@@ -1220,11 +1220,53 @@ static bool add_uniqbuf(struct tagcache_search *tcs, unsigned long id) | |||
1220 | return true; | 1220 | return true; |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | for (i = 0; i < tcs->unique_list_count; i++) | 1223 | if (id <= UINT16_MAX) |
1224 | { | 1224 | { |
1225 | /* Return false if entry is found. */ | 1225 | /* place two 16-bit entries in a single 32-bit slot */ |
1226 | if (tcs->unique_list[i] == id) | 1226 | uint32_t idtmp; |
1227 | return false; | 1227 | union uentry{ |
1228 | uint16_t u16[2]; | ||
1229 | uint32_t u32; | ||
1230 | } *entry; | ||
1231 | id |= 1; /*odd - flag 16-bit entry */ | ||
1232 | for (i = 0; i < tcs->unique_list_count; i++) | ||
1233 | { | ||
1234 | entry = (union uentry *) &tcs->unique_list[i]; | ||
1235 | if ((entry->u32 & 1) == 0) /* contains a 32-bit entry */ | ||
1236 | continue; | ||
1237 | |||
1238 | /* Return false if entry is found. */ | ||
1239 | if (entry->u16[0] == id || entry->u16[1] == id) | ||
1240 | { | ||
1241 | logf("%d Exists (16) @ %d", id, i); | ||
1242 | return false; | ||
1243 | } | ||
1244 | |||
1245 | if (entry->u16[1] == 0 && (entry->u16[0] & 1) == 1) | ||
1246 | { | ||
1247 | entry->u16[1] = id & UINT16_MAX; | ||
1248 | return true; /*no more 16bit entries add to empty 16bit slot */ | ||
1249 | } | ||
1250 | |||
1251 | } | ||
1252 | /* Not Found and no empty slot add a new entry */ | ||
1253 | entry = (union uentry *) &idtmp; | ||
1254 | entry->u16[1] = 0; | ||
1255 | entry->u16[0] = id & UINT16_MAX; | ||
1256 | id = idtmp; | ||
1257 | } | ||
1258 | else | ||
1259 | { | ||
1260 | id &= ~1; /* even - flag 32-bit entry */ | ||
1261 | for (i = 0; i < tcs->unique_list_count; i++) | ||
1262 | { | ||
1263 | /* Return false if entry is found. */ | ||
1264 | if (tcs->unique_list[i] == id) | ||
1265 | { | ||
1266 | logf("%d Exists (32)@ %d", id, i); | ||
1267 | return false; | ||
1268 | } | ||
1269 | } | ||
1228 | } | 1270 | } |
1229 | 1271 | ||
1230 | if (tcs->unique_list_count < tcs->unique_list_capacity) | 1272 | if (tcs->unique_list_count < tcs->unique_list_capacity) |
@@ -1470,9 +1512,10 @@ bool tagcache_search(struct tagcache_search *tcs, int tag) | |||
1470 | void tagcache_search_set_uniqbuf(struct tagcache_search *tcs, | 1512 | void tagcache_search_set_uniqbuf(struct tagcache_search *tcs, |
1471 | void *buffer, long length) | 1513 | void *buffer, long length) |
1472 | { | 1514 | { |
1473 | tcs->unique_list = (unsigned long *)buffer; | 1515 | tcs->unique_list = (uint32_t *)buffer; |
1474 | tcs->unique_list_capacity = length / sizeof(*tcs->unique_list); | 1516 | tcs->unique_list_capacity = length / sizeof(*tcs->unique_list); |
1475 | tcs->unique_list_count = 0; | 1517 | tcs->unique_list_count = 0; |
1518 | memset(tcs->unique_list, 0, tcs->unique_list_capacity); | ||
1476 | } | 1519 | } |
1477 | 1520 | ||
1478 | bool tagcache_search_add_filter(struct tagcache_search *tcs, | 1521 | bool tagcache_search_add_filter(struct tagcache_search *tcs, |
@@ -1702,6 +1745,11 @@ bool tagcache_get_next(struct tagcache_search *tcs) | |||
1702 | return true; | 1745 | return true; |
1703 | } | 1746 | } |
1704 | 1747 | ||
1748 | #ifdef LOGF_ENABLE | ||
1749 | if (tcs->unique_list_count > 0) | ||
1750 | logf(" uniqbuf: %d used / %d avail", tcs->unique_list_count, tcs->unique_list_capacity); | ||
1751 | #endif | ||
1752 | |||
1705 | return false; | 1753 | return false; |
1706 | } | 1754 | } |
1707 | 1755 | ||
diff --git a/apps/tagcache.h b/apps/tagcache.h index 52a9283e35..b7c4aadbb1 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -188,7 +188,7 @@ struct tagcache_search { | |||
188 | int entry_count; | 188 | int entry_count; |
189 | bool valid; | 189 | bool valid; |
190 | bool initialized; | 190 | bool initialized; |
191 | unsigned long *unique_list; | 191 | uint32_t *unique_list; |
192 | int unique_list_capacity; | 192 | int unique_list_capacity; |
193 | int unique_list_count; | 193 | int unique_list_count; |
194 | 194 | ||
diff --git a/apps/tagtree.c b/apps/tagtree.c index 9684d5424c..48ef1e28ce 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -111,7 +111,7 @@ enum variables { | |||
111 | 111 | ||
112 | /* Capacity 10 000 entries (for example 10k different artists) */ | 112 | /* Capacity 10 000 entries (for example 10k different artists) */ |
113 | #define UNIQBUF_SIZE (64*1024) | 113 | #define UNIQBUF_SIZE (64*1024) |
114 | static long uniqbuf[UNIQBUF_SIZE / sizeof(long)]; | 114 | static uint32_t uniqbuf[UNIQBUF_SIZE / sizeof(uint32_t)]; |
115 | 115 | ||
116 | #define MAX_TAGS 5 | 116 | #define MAX_TAGS 5 |
117 | #define MAX_MENU_ID_SIZE 32 | 117 | #define MAX_MENU_ID_SIZE 32 |