performance improvement on plain string edge matching

This commit is contained in:
c9s 2014-05-18 08:29:26 +08:00
parent 00c3b32ad5
commit c1d90dd138
3 changed files with 13 additions and 4 deletions

View file

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <pcre.h> #include <pcre.h>
#include <gvc.h>
#include "str_array.h" #include "str_array.h"
@ -133,5 +134,6 @@ match_entry * match_entry_create(char * path, int path_len);
void match_entry_free(match_entry * entry); void match_entry_free(match_entry * entry);
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, int node_cnt);
#endif /* !NODE_H */ #endif /* !NODE_H */

View file

@ -17,7 +17,7 @@ char * node_id_str(int id) {
return name; return name;
} }
int r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, int node_cnt) { void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, int node_cnt) {
edge * e; edge * e;
Agnode_t *agn_child; Agnode_t *agn_child;
Agedge_t *agn_edge; Agedge_t *agn_edge;

View file

@ -299,12 +299,19 @@ node * r3_tree_match(node * n, char * path, int path_len, match_entry * entry) {
inline edge * r3_node_find_edge_str(node * n, char * str, int str_len) { inline edge * r3_node_find_edge_str(node * n, char * str, int str_len) {
int i = 0; int i = 0;
int matched_idx = 0;
for (; i < n->edge_len ; i++ ) { for (; i < n->edge_len ; i++ ) {
info("matching '%s' with '%s'\n", str, node_edge_pattern(n,i) ); if ( *str == *(n->edges[i]->pattern) ) {
if ( strncmp( node_edge_pattern(n,i), str, node_edge_pattern_len(n,i) ) == 0 ) { matched_idx = i;
return n->edges[i]; break;
} }
} }
// info("matching '%s' with '%s'\n", str, node_edge_pattern(n,i) );
if ( strncmp( node_edge_pattern(n,matched_idx), str, node_edge_pattern_len(n,matched_idx) ) == 0 ) {
return n->edges[matched_idx];
}
return NULL; return NULL;
} }