X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fyaz-z-cache.cpp;h=3ab0ba6c5dd9bd48d56cf774bacda7c8f753ecd6;hb=cd57d092689576508ec75cec0b837cbee83cd141;hp=fd35f7cf87affbbfce90103fafa71c8f59afa1fb;hpb=0cc824e02bc2c69986bec8c9dd9ff53f07a0cd3d;p=yazpp-moved-to-github.git diff --git a/src/yaz-z-cache.cpp b/src/yaz-z-cache.cpp index fd35f7c..3ab0ba6 100644 --- a/src/yaz-z-cache.cpp +++ b/src/yaz-z-cache.cpp @@ -1,12 +1,14 @@ -/* - * Copyright (c) 2002-2004, Index Data. +/* This file is part of the yazpp toolkit. + * Copyright (C) 1998-2012 Index Data and Mike Taylor * See the file LICENSE for details. - * - * $Id: yaz-z-cache.cpp,v 1.15 2006-03-29 13:14:18 adam Exp $ */ +#if HAVE_CONFIG_H +#include +#endif #include #include +#include #include using namespace yazpp_1; @@ -32,7 +34,7 @@ RecordCache::~RecordCache () nmem_destroy(m_mem); } -void RecordCache::set_max_size(int sz) +void RecordCache::set_max_size(size_t sz) { m_max_size = sz; } @@ -70,7 +72,7 @@ void RecordCache::copy_presentRequest(Z_PresentRequest *pr) { ODR encode = odr_createmem(ODR_ENCODE); ODR decode = odr_createmem(ODR_DECODE); - + m_searchRequest = 0; m_presentRequest = 0; int v = z_PresentRequest (encode, &pr, 1, 0); @@ -86,6 +88,7 @@ void RecordCache::copy_presentRequest(Z_PresentRequest *pr) odr_destroy(decode); } + void RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, int hits) { @@ -108,23 +111,14 @@ void RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, comp->u.simple = esn; } - // Z_NamePlusRecordList *npr to be owned by m_mem.. - NMEM tmp_mem = odr_extract_mem(o); - nmem_transfer(m_mem, tmp_mem); - nmem_destroy(tmp_mem); - // Insert individual records in cache int i; for (i = 0; inum_records; i++) { RecordCache_Entry *entry = (RecordCache_Entry *) nmem_malloc(m_mem, sizeof(*entry)); - entry->m_record = (Z_NamePlusRecord *) - nmem_malloc(m_mem, sizeof(*entry->m_record)); - entry->m_record->databaseName = npr->records[i]->databaseName; - entry->m_record->which = npr->records[i]->which; - entry->m_record->u.databaseRecord = npr->records[i]->u.databaseRecord; - entry->m_comp = comp; + entry->m_record = yaz_clone_z_NamePlusRecord(npr->records[i], m_mem); + entry->m_comp = yaz_clone_z_RecordComposition(comp, m_mem); entry->m_offset = i + start; entry->m_next = m_entries; m_entries = entry; @@ -139,7 +133,7 @@ int RecordCache::match (RecordCache_Entry *entry, int match = 0; ODR o1 = odr_createmem(ODR_ENCODE); ODR o2 = odr_createmem(ODR_ENCODE); - + z_RecordComposition(o1, &comp, 1, 0); z_RecordComposition(o2, &entry->m_comp, 1, 0); @@ -147,12 +141,12 @@ int RecordCache::match (RecordCache_Entry *entry, char *buf1 = odr_getbuf(o1, &len1, 0); int len2 = -1; char *buf2 = odr_getbuf(o2, &len2, 0); - + if (buf1 && buf2 && len1 && len1 == len2 && !memcmp(buf1, buf2, len1)) match = 1; else if (!buf1 && !buf2 && !len1 && !len2) match = 1; - + odr_destroy(o1); odr_destroy(o2); if (!match) @@ -217,6 +211,7 @@ int RecordCache::lookup (ODR o, Z_NamePlusRecordList **npr, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab