使用cJSON_ArrayForEach替代cJSON_GetArrayItem,提高maat json解析速度。
This commit is contained in:
@@ -631,6 +631,10 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
|
|||||||
break;
|
break;
|
||||||
case MAAT_OPT_JSON_FILE_PATH:
|
case MAAT_OPT_JSON_FILE_PATH:
|
||||||
assert(_feather->input_mode==SOURCE_NONE);
|
assert(_feather->input_mode==SOURCE_NONE);
|
||||||
|
MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module ,
|
||||||
|
"Maat initial with JSON file %s, formating..",
|
||||||
|
(const char*)value);
|
||||||
|
|
||||||
ret=json2iris((const char*)value,
|
ret=json2iris((const char*)value,
|
||||||
_feather->compile_tn,_feather->group_tn,
|
_feather->compile_tn,_feather->group_tn,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -647,7 +651,7 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
|
|||||||
|
|
||||||
md5_file(_feather->json_ctx.json_file, _feather->json_ctx.effective_json_md5);
|
md5_file(_feather->json_ctx.json_file, _feather->json_ctx.effective_json_md5);
|
||||||
MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module ,
|
MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module ,
|
||||||
"Maat initial with JSON file %s md5: %s, generate index file %s OK.",
|
"JSON file %s md5: %s, generate index file %s OK.",
|
||||||
_feather->json_ctx.json_file,
|
_feather->json_ctx.json_file,
|
||||||
_feather->json_ctx.effective_json_md5,
|
_feather->json_ctx.effective_json_md5,
|
||||||
_feather->json_ctx.iris_file);
|
_feather->json_ctx.iris_file);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#include "stream_fuzzy_hash.h"
|
#include "stream_fuzzy_hash.h"
|
||||||
#include "gram_index_engine.h"
|
#include "gram_index_engine.h"
|
||||||
|
|
||||||
int MAAT_FRAME_VERSION_2_8_20190728=1;
|
int MAAT_FRAME_VERSION_2_8_20190816=1;
|
||||||
|
|
||||||
|
|
||||||
int is_valid_expr_type(enum MAAT_EXPR_TYPE expr_type)
|
int is_valid_expr_type(enum MAAT_EXPR_TYPE expr_type)
|
||||||
|
|||||||
@@ -937,8 +937,6 @@ int write_index_file(struct iris_description_t *p_iris,void* logger)
|
|||||||
int write_group_rule(cJSON *group_json, int parent_id, int parent_type, int tracking_compile_id, struct iris_description_t *p_iris, void* logger)
|
int write_group_rule(cJSON *group_json, int parent_id, int parent_type, int tracking_compile_id, struct iris_description_t *p_iris, void* logger)
|
||||||
{
|
{
|
||||||
const char* _str_parent_type[2]={"compile", "group"};
|
const char* _str_parent_type[2]={"compile", "group"};
|
||||||
int i=0;
|
|
||||||
int sub_group_cnt=0, region_cnt=0;
|
|
||||||
int ret=0;
|
int ret=0;
|
||||||
int group_not_flag=0;
|
int group_not_flag=0;
|
||||||
cJSON *region_json=NULL, *item=NULL;
|
cJSON *region_json=NULL, *item=NULL;
|
||||||
@@ -1005,10 +1003,8 @@ int write_group_rule(cJSON *group_json, int parent_id, int parent_type, int trac
|
|||||||
region_json=cJSON_GetObjectItem(group_json,"regions");
|
region_json=cJSON_GetObjectItem(group_json,"regions");
|
||||||
if(region_json!=NULL)
|
if(region_json!=NULL)
|
||||||
{
|
{
|
||||||
region_cnt=cJSON_GetArraySize(region_json);
|
cJSON_ArrayForEach(region_rule, region_json)
|
||||||
for(i=0; i<region_cnt; i++)
|
|
||||||
{
|
{
|
||||||
region_rule=cJSON_GetArrayItem(region_json,i);
|
|
||||||
ret=write_region_rule(region_rule, tracking_compile_id, group_info->group_id, p_iris, logger);
|
ret=write_region_rule(region_rule, tracking_compile_id, group_info->group_id, p_iris, logger);
|
||||||
if(ret<0)
|
if(ret<0)
|
||||||
{
|
{
|
||||||
@@ -1022,10 +1018,9 @@ int write_group_rule(cJSON *group_json, int parent_id, int parent_type, int trac
|
|||||||
if(sub_groups!=NULL)
|
if(sub_groups!=NULL)
|
||||||
{
|
{
|
||||||
//recursively
|
//recursively
|
||||||
sub_group_cnt=cJSON_GetArraySize(sub_groups);
|
|
||||||
for(i=0; i<sub_group_cnt; i++)
|
cJSON_ArrayForEach(item, sub_groups)
|
||||||
{
|
{
|
||||||
item=cJSON_GetArrayItem(sub_groups, i);
|
|
||||||
ret=write_group_rule(item, group_info->group_id, PARENT_TYPE_GROUP, tracking_compile_id, p_iris, logger);
|
ret=write_group_rule(item, group_info->group_id, PARENT_TYPE_GROUP, tracking_compile_id, p_iris, logger);
|
||||||
if(ret<0)
|
if(ret<0)
|
||||||
{
|
{
|
||||||
@@ -1037,18 +1032,16 @@ int write_group_rule(cJSON *group_json, int parent_id, int parent_type, int trac
|
|||||||
}
|
}
|
||||||
int write_iris(cJSON *json, struct iris_description_t *p_iris, void* logger)
|
int write_iris(cJSON *json, struct iris_description_t *p_iris, void* logger)
|
||||||
{
|
{
|
||||||
int i=0,j=0;
|
int i=0;
|
||||||
int compile_id=-1, compile_cnt=0, group_cnt=0, plug_table_cnt=0;
|
int compile_id=-1, compile_cnt=0, group_cnt=0;
|
||||||
int ret=0;
|
int ret=0;
|
||||||
cJSON *c_rules=NULL, *g_rules=NULL, *plug_tables=NULL;
|
cJSON *c_rules=NULL, *g_rules=NULL, *plug_tables=NULL;
|
||||||
cJSON *compile_rule=NULL,*group_rule=NULL, *each_plug_table=NULL;
|
cJSON *compile_rule=NULL,*group_rule=NULL, *each_plug_table=NULL;
|
||||||
plug_tables=cJSON_GetObjectItem(json,"plugin_table");
|
plug_tables=cJSON_GetObjectItem(json,"plugin_table");
|
||||||
if(NULL!=plug_tables)
|
if(NULL!=plug_tables)
|
||||||
{
|
{
|
||||||
plug_table_cnt=cJSON_GetArraySize(plug_tables);
|
cJSON_ArrayForEach(each_plug_table, plug_tables)
|
||||||
for(i=0;i<plug_table_cnt;i++)
|
|
||||||
{
|
{
|
||||||
each_plug_table=cJSON_GetArrayItem(plug_tables,i);
|
|
||||||
write_plugin_line(each_plug_table, i, p_iris, logger);
|
write_plugin_line(each_plug_table, i, p_iris, logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1067,9 +1060,8 @@ int write_iris(cJSON *json, struct iris_description_t *p_iris, void* logger)
|
|||||||
"have no rules.");
|
"have no rules.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(i=0;i<compile_cnt;i++)
|
cJSON_ArrayForEach(compile_rule, c_rules)
|
||||||
{
|
{
|
||||||
compile_rule=cJSON_GetArrayItem(c_rules,i);
|
|
||||||
compile_id=write_compile_line(compile_rule,p_iris, logger);
|
compile_id=write_compile_line(compile_rule,p_iris, logger);
|
||||||
if(compile_id<0)
|
if(compile_id<0)
|
||||||
{
|
{
|
||||||
@@ -1091,9 +1083,8 @@ int write_iris(cJSON *json, struct iris_description_t *p_iris, void* logger)
|
|||||||
"compile rule %d have no groups.",compile_id);
|
"compile rule %d have no groups.",compile_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(j=0;j<group_cnt;j++)
|
cJSON_ArrayForEach(group_rule, g_rules)
|
||||||
{
|
{
|
||||||
group_rule=cJSON_GetArrayItem(g_rules,j);
|
|
||||||
ret=write_group_rule(group_rule, compile_id, PARENT_TYPE_COMPILE, compile_id, p_iris, logger);
|
ret=write_group_rule(group_rule, compile_id, PARENT_TYPE_COMPILE, compile_id, p_iris, logger);
|
||||||
if(ret<0)
|
if(ret<0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ int main() {
|
|||||||
igraph_integer_t edge_num_before=0, edge_num_after=0;
|
igraph_integer_t edge_num_before=0, edge_num_after=0;
|
||||||
int v[10];
|
int v[10];
|
||||||
int i=0;
|
int i=0;
|
||||||
for(i=0; i<sizeof(v)/sizeof(int); i++)
|
for(i=0; (unsigned int)i<sizeof(v)/sizeof(int); i++)
|
||||||
{
|
{
|
||||||
v[i]=i;
|
v[i]=i;
|
||||||
igraph_add_vertices(&g, 1, NULL); //Add 1 vertice.
|
igraph_add_vertices(&g, 1, NULL); //Add 1 vertice.
|
||||||
|
|||||||
Reference in New Issue
Block a user