[PATCH]remove duplicate code for expr_matcher
This commit is contained in:
@@ -756,6 +756,54 @@ static void adapter_hs_stream_reset(struct adapter_hs_stream *hs_stream)
|
||||
utarray_clear(hs_stream->matched_pat->pattern_ids);
|
||||
}
|
||||
|
||||
int adapter_hs_scan_match(struct bool_matcher *bm, UT_array *pattern_ids,
|
||||
struct bool_expr_match *match_buff, size_t buff_size,
|
||||
struct expr_scan_result *results, size_t n_result,
|
||||
size_t *n_hit_result)
|
||||
{
|
||||
size_t n_pattern_id = utarray_len(pattern_ids);
|
||||
if (0 == n_pattern_id) {
|
||||
*n_hit_result = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
utarray_sort(pattern_ids, compare_pattern_id);
|
||||
|
||||
unsigned long long prev_pattern_id = 0xFFFFFFFFFFFFFFFF;
|
||||
unsigned long long tmp_pattern_id = 0;
|
||||
size_t n_unique_pattern_id = 0;
|
||||
unsigned long long unique_pattern_ids[n_pattern_id];
|
||||
|
||||
for (size_t i = 0; i < n_pattern_id; i++) {
|
||||
tmp_pattern_id = *(unsigned long long *)utarray_eltptr(pattern_ids, i);
|
||||
if (tmp_pattern_id != prev_pattern_id) {
|
||||
unique_pattern_ids[n_unique_pattern_id++] = tmp_pattern_id;
|
||||
prev_pattern_id = tmp_pattern_id;
|
||||
}
|
||||
}
|
||||
|
||||
int bool_matcher_ret = bool_matcher_match(bm, unique_pattern_ids,
|
||||
n_unique_pattern_id,
|
||||
match_buff, buff_size);
|
||||
if (bool_matcher_ret < 0) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (bool_matcher_ret > (int)n_result) {
|
||||
bool_matcher_ret = n_result;
|
||||
}
|
||||
|
||||
for (int index = 0; index < bool_matcher_ret; index++) {
|
||||
results[index].rule_id = match_buff[index].expr_id;
|
||||
results[index].user_tag = match_buff[index].user_tag;
|
||||
}
|
||||
*n_hit_result = bool_matcher_ret;
|
||||
|
||||
next:
|
||||
utarray_clear(pattern_ids);
|
||||
return bool_matcher_ret;
|
||||
}
|
||||
|
||||
int adapter_hs_scan_stream(void *hs_stream, const char *data, size_t data_len,
|
||||
struct expr_scan_result *results, size_t n_result,
|
||||
size_t *n_hit_result)
|
||||
@@ -822,51 +870,9 @@ int adapter_hs_scan_stream(void *hs_stream, const char *data, size_t data_len,
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t n_pattern_id = utarray_len(stream->matched_pat->pattern_ids);
|
||||
if (0 == n_pattern_id) {
|
||||
*n_hit_result = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
utarray_sort(stream->matched_pat->pattern_ids, compare_pattern_id);
|
||||
|
||||
unsigned long long prev_pattern_id = 0xFFFFFFFFFFFFFFFF;
|
||||
unsigned long long tmp_pattern_id = 0;
|
||||
size_t n_unique_pattern_id = 0;
|
||||
unsigned long long unique_pattern_ids[n_pattern_id];
|
||||
|
||||
for (size_t i = 0; i < n_pattern_id; i++) {
|
||||
tmp_pattern_id = *(unsigned long long *)utarray_eltptr(stream->matched_pat->pattern_ids, i);
|
||||
if (tmp_pattern_id != prev_pattern_id) {
|
||||
unique_pattern_ids[n_unique_pattern_id++] = tmp_pattern_id;
|
||||
prev_pattern_id = tmp_pattern_id;
|
||||
}
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
struct bool_expr_match *bool_matcher_results = scratch->bool_match_buffs[thread_id];
|
||||
int bool_matcher_ret = bool_matcher_match(stream->ref_hs_rt->bm, unique_pattern_ids,
|
||||
n_unique_pattern_id, bool_matcher_results,
|
||||
MAX_HIT_EXPR_NUM);
|
||||
if (bool_matcher_ret < 0) {
|
||||
ret = -1;
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (bool_matcher_ret > (int)n_result) {
|
||||
bool_matcher_ret = n_result;
|
||||
}
|
||||
|
||||
for (int index = 0; index < bool_matcher_ret; index++) {
|
||||
results[index].rule_id = bool_matcher_results[index].expr_id;
|
||||
results[index].user_tag = bool_matcher_results[index].user_tag;
|
||||
}
|
||||
*n_hit_result = bool_matcher_ret;
|
||||
|
||||
next:
|
||||
utarray_clear(stream->matched_pat->pattern_ids);
|
||||
|
||||
return ret;
|
||||
return adapter_hs_scan_match(stream->ref_hs_rt->bm, stream->matched_pat->pattern_ids,
|
||||
scratch->bool_match_buffs[thread_id], MAX_HIT_EXPR_NUM,
|
||||
results, n_result, n_hit_result);
|
||||
}
|
||||
|
||||
int adapter_hs_scan(void *hs_instance, int thread_id, const char *data, size_t data_len,
|
||||
|
||||
Reference in New Issue
Block a user