X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-z-cache.cpp;h=7f0f41449ba3a59383928073c03ef50a44220b89;hb=9db3735fa68528436821b0349f5acc788f448492;hp=6c283ac232d859fd4c130fafc6e7776f159771d3;hpb=217e153abe5e9c5aae6ef74a839bf01d30e295d3;p=yazpp-moved-to-github.git diff --git a/src/yaz-z-cache.cpp b/src/yaz-z-cache.cpp index 6c283ac..7f0f414 100644 --- a/src/yaz-z-cache.cpp +++ b/src/yaz-z-cache.cpp @@ -1,5 +1,5 @@ /* This file is part of the yazpp toolkit. - * Copyright (C) 1998-2013 Index Data and Mike Taylor + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -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,