detect: faster linked list copy

In DetectAppLayerInspectEngineCopyListToDetectCtx
Avoid quadratic complexity by remembering last element
of the linked list we are inserting into
pull/7242/head
Philippe Antoine 3 years ago committed by Victor Julien
parent 2a22b4ca1f
commit 45d1a9ae77

@ -215,6 +215,7 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
{
const DetectBufferMpmRegistery *list = g_mpm_list[DETECT_BUFFER_MPM_TYPE_APP];
DetectBufferMpmRegistery *toadd = de_ctx->app_mpms_list;
while (list != NULL) {
DetectBufferMpmRegistery *n = SCCalloc(1, sizeof(*n));
BUG_ON(n == NULL);
@ -222,14 +223,12 @@ void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
*n = *list;
n->next = NULL;
if (de_ctx->app_mpms_list == NULL) {
if (toadd == NULL) {
toadd = n;
de_ctx->app_mpms_list = n;
} else {
DetectBufferMpmRegistery *t = de_ctx->app_mpms_list;
while (t->next != NULL) {
t = t->next;
}
t->next = n;
toadd->next = n;
toadd = toadd->next;
}
/* default to whatever the global setting is */

@ -322,6 +322,7 @@ static void DetectAppLayerInspectEngineCopy(
static void DetectAppLayerInspectEngineCopyListToDetectCtx(DetectEngineCtx *de_ctx)
{
const DetectEngineAppInspectionEngine *t = g_app_inspect_engines;
DetectEngineAppInspectionEngine *list = de_ctx->app_inspect_engines;
while (t) {
DetectEngineAppInspectionEngine *new_engine = SCCalloc(1, sizeof(DetectEngineAppInspectionEngine));
if (unlikely(new_engine == NULL)) {
@ -334,16 +335,12 @@ static void DetectAppLayerInspectEngineCopyListToDetectCtx(DetectEngineCtx *de_c
new_engine->progress = t->progress;
new_engine->v2 = t->v2;
if (de_ctx->app_inspect_engines == NULL) {
if (list == NULL) {
de_ctx->app_inspect_engines = new_engine;
} else {
DetectEngineAppInspectionEngine *list = de_ctx->app_inspect_engines;
while (list->next != NULL) {
list = list->next;
}
list->next = new_engine;
}
list = new_engine;
t = t->next;
}

Loading…
Cancel
Save