From: Adam Dickmeiss Date: Thu, 14 Nov 2013 13:18:52 +0000 (+0100) Subject: Make improved RecordCache::add YPP-10 X-Git-Tag: v1.5.2~2 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=d54b824ca309141da489284e5b6d78d7094f5494;p=yazpp-moved-to-github.git Make improved RecordCache::add YPP-10 This will take a CompSpec as argument. We leave existing RecordCache:add for now. --- diff --git a/include/yazpp/record-cache.h b/include/yazpp/record-cache.h index 935b4a7..027f064 100644 --- a/include/yazpp/record-cache.h +++ b/include/yazpp/record-cache.h @@ -36,6 +36,8 @@ class YAZ_EXPORT RecordCache { RecordCache (); ~RecordCache (); void add(ODR o, Z_NamePlusRecordList *npr, int start, int hits); + void add(ODR o, Z_NamePlusRecordList *npr, int start, + Z_RecordComposition *comp); int lookup(ODR o, Z_NamePlusRecordList **npr, int start, int num, Odr_oid *syntax, Z_RecordComposition *comp); diff --git a/src/yaz-z-cache.cpp b/src/yaz-z-cache.cpp index 6c283ac..f023924 100644 --- a/src/yaz-z-cache.cpp +++ b/src/yaz-z-cache.cpp @@ -100,12 +100,29 @@ void RecordCache::copy_presentRequest(Z_PresentRequest *pr) odr_destroy(decode); } - void RecordCache::add(ODR o, Z_NamePlusRecordList *npr, int start, - int hits) + Z_RecordComposition *comp) { if (nmem_total(m_p->nmem) > m_p->max_size) return; + // Insert individual records in cache + int i; + for (i = 0; i < npr->num_records; i++) + { + RecordCache_Entry *entry = (RecordCache_Entry *) + nmem_malloc(m_p->nmem, sizeof(*entry)); + entry->m_record = + yaz_clone_z_NamePlusRecord(npr->records[i], m_p->nmem); + entry->m_comp = yaz_clone_z_RecordComposition(comp, m_p->nmem); + entry->m_offset = i + start; + entry->m_next = m_p->entries; + m_p->entries = entry; + } +} + +void RecordCache::add(ODR o, Z_NamePlusRecordList *npr, int start, + int hits) +{ // Build appropriate compspec for this response Z_RecordComposition *comp = 0; if (hits == -1 && m_p->presentRequest) @@ -122,20 +139,7 @@ void RecordCache::add(ODR o, Z_NamePlusRecordList *npr, int start, comp->which = Z_RecordComp_simple; comp->u.simple = esn; } - - // Insert individual records in cache - int i; - for (i = 0; inum_records; i++) - { - RecordCache_Entry *entry = (RecordCache_Entry *) - nmem_malloc(m_p->nmem, sizeof(*entry)); - entry->m_record = - yaz_clone_z_NamePlusRecord(npr->records[i], m_p->nmem); - entry->m_comp = yaz_clone_z_RecordComposition(comp, m_p->nmem); - entry->m_offset = i + start; - entry->m_next = m_p->entries; - m_p->entries = entry; - } + add(o, npr, start, comp); } int RecordCache::Rep::match(RecordCache_Entry *entry,