simplify functions to macro

This commit is contained in:
c9s 2014-06-04 23:13:08 +08:00
parent 8e39e58c88
commit 5137d4d8e4
4 changed files with 15 additions and 12 deletions

View file

@ -126,6 +126,10 @@ edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data); node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data);
#define r3_tree_insert_pathl(tree, path, path_len, data) r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL)
route * r3_tree_insert_routel(node *tree, int method, const char *path, int path_len, void *data); route * r3_tree_insert_routel(node *tree, int method, const char *path, int path_len, void *data);
route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int path_len, void *data, char **errstr); route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int path_len, void *data, char **errstr);
@ -184,6 +188,9 @@ int r3_route_cmp(const route *r1, const match_entry *r2);
route * r3_tree_match_route(const node *n, match_entry * entry); route * r3_tree_match_route(const node *n, match_entry * entry);
#define r3_route_create(p) r3_route_createl(p, strlen(p))
#define METHOD_GET 2 #define METHOD_GET 2
#define METHOD_POST 2<<1 #define METHOD_POST 2<<1
#define METHOD_PUT 2<<2 #define METHOD_PUT 2<<2

View file

@ -23,8 +23,15 @@
#include "slug.h" #include "slug.h"
#include "zmalloc.h" #include "zmalloc.h"
#define CHECK_PTR(ptr) if (ptr == NULL) return NULL;
edge * r3_edge_createl(const char * pattern, int pattern_len, node * child) { edge * r3_edge_createl(const char * pattern, int pattern_len, node * child) {
edge * e = (edge*) zmalloc( sizeof(edge) ); edge * e = (edge*) zmalloc( sizeof(edge) );
CHECK_PTR(e);
e->pattern = (char*) pattern; e->pattern = (char*) pattern;
e->pattern_len = pattern_len; e->pattern_len = pattern_len;
e->opcode = 0; e->opcode = 0;

View file

@ -450,11 +450,6 @@ node * r3_node_create() {
return n; return n;
} }
route * r3_route_create(const char * path) {
return r3_route_createl(path, strlen(path));
}
void r3_route_free(route * route) { void r3_route_free(route * route) {
zfree(route); zfree(route);
} }
@ -497,12 +492,6 @@ route * r3_tree_insert_routel_ex(node *tree, int method, const char *path, int p
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data)
{
return r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL);
}
/** /**
* Find common prefix from the edges of the node. * Find common prefix from the edges of the node.
* *

View file

@ -674,7 +674,7 @@ START_TEST(test_insert_route)
r3_tree_insert_route(n, METHOD_POST, "/blog/post", &var2); r3_tree_insert_route(n, METHOD_POST, "/blog/post", &var2);
route *c = r3_tree_match_route(n, entry); route *c = r3_tree_match_route(n, entry);
fail_if(c == NULL); ck_assert(c != NULL);
r3_tree_free(n); r3_tree_free(n);
match_entry_free(entry); match_entry_free(entry);