Move hyperlink to end of hash table when re-referenced
This commit is contained in:
parent
78dc93721d
commit
c8e2061e2a
@ -105,7 +105,13 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) {
|
||||
HyperLinkEntry *s = NULL;
|
||||
if (pool->hyperlinks) {
|
||||
HASH_FIND_STR(pool->hyperlinks, key, s);
|
||||
if (s) return s->id;
|
||||
if (s) {
|
||||
// Remove and re-add s so that it is the last entry in the hash table and
|
||||
// The first entry is discarded when hash table is full.
|
||||
HASH_DEL(pool->hyperlinks, s);
|
||||
HASH_ADD_KEYPTR(hh, pool->hyperlinks, s->key, strlen(s->key), s);
|
||||
return s->id;
|
||||
}
|
||||
}
|
||||
hyperlink_id_type new_id = 0;
|
||||
if (pool->num_of_adds_since_garbage_collection >= MAX_ADDS_BEFORE_GC) screen_garbage_collect_hyperlink_pool(screen);
|
||||
|
||||
@ -585,3 +585,9 @@ class TestScreen(BaseTest):
|
||||
self.ae([(':1', 1), (':3', 2)], s.hyperlinks_as_list())
|
||||
set_link('4'), s.draw('4')
|
||||
self.ae([(':1', 1), (':3', 2), (':4', 3)], s.hyperlinks_as_list())
|
||||
|
||||
s = self.create_screen()
|
||||
set_link('1'), s.draw('1')
|
||||
set_link('2'), s.draw('2')
|
||||
set_link('1'), s.draw('1')
|
||||
self.ae([(':2', 2), (':1', 1)], s.hyperlinks_as_list())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user