cache,kdb: propagate OPMPHM from cache to returned keyset
@@ -838,6 +838,43 @@ static void elektraCacheLoad (KDB * handle, KeySet * cache, Key * parentKey, Key
}
}
+#ifdef ELEKTRA_ENABLE_OPTIMIZATIONS
+/**
+ * @brief Deletes the OPMPHM.
+ *
+ * Clears and frees all memory in Opmphm.
+ *
+ * @param opmphm the OPMPHM
+ */
+static void cacheOpmphmDel (Opmphm * opmphm)
+{
+ ELEKTRA_NOT_NULL (opmphm);
+ if (opmphm && opmphm->size && !test_bit (opmphm->flags, OPMPHM_FLAG_MMAP_GRAPH))
+ {
+ elektraFree (opmphm->graph);
+ }
+ if (opmphm->rUniPar && !test_bit (opmphm->flags, OPMPHM_FLAG_MMAP_HASHFUNCTIONSEEDS))
+ {
+ elektraFree (opmphm->hashFunctionSeeds);
+ }
+ if (!test_bit (opmphm->flags, OPMPHM_FLAG_MMAP_STRUCT)) elektraFree (opmphm);
+}
+
+/**
+ * @brief Deletes the OpmphmPredictor.
+ *
+ * Clears and frees all memory in OpmphmPredictor.
+ *
+ * @param op the OpmphmPredictor
+ */
+static void cacheOpmphmPredictorDel (OpmphmPredictor * op)
+{
+ ELEKTRA_NOT_NULL (op);
+ if (!test_bit (op->flags, OPMPHM_PREDICTOR_FLAG_MMAP_PATTERNTABLE)) elektraFree (op->patternTable);
+ if (!test_bit (op->flags, OPMPHM_PREDICTOR_FLAG_MMAP_STRUCT)) elektraFree (op);
+}
+#endif
+
static int elektraCacheLoadSplit (KDB * handle, Split * split, KeySet * ks, KeySet ** cache, Key ** cacheParent, Key * parentKey,
Key * initialParent, int debugGlobalPositions)
{
@@ -872,11 +909,19 @@ static int elektraCacheLoadSplit (KDB * handle, Split * split, KeySet * ks, KeyS
if (ks->size == 0)
{
ELEKTRA_LOG_DEBUG ("replacing keyset with cached keyset");
+#ifdef ELEKTRA_ENABLE_OPTIMIZATIONS
+ if (ks->opmphm) cacheOpmphmDel (ks->opmphm);
+ if (ks->opmphmPredictor) cacheOpmphmPredictorDel (ks->opmphmPredictor);
+#endif
ksClose (ks);
ks->array = (*cache)->array;
ks->size = (*cache)->size;
ks->alloc = (*cache)->alloc;
ks->flags = (*cache)->flags;
+#ifdef ELEKTRA_ENABLE_OPTIMIZATIONS
+ ks->opmphm = (*cache)->opmphm;
+ ks->opmphmPredictor = (*cache)->opmphmPredictor;
+#endif
elektraFree (*cache);
*cache = 0;
}
