summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c60
1 files changed, 54 insertions, 6 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
1212static bool add_uniqbuf(struct tagcache_search *tcs, unsigned long id) 1212static 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)
1470void tagcache_search_set_uniqbuf(struct tagcache_search *tcs, 1512void 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
1478bool tagcache_search_add_filter(struct tagcache_search *tcs, 1521bool 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