Add struct fields optimization

This commit is contained in:
c9s 2014-05-24 17:13:55 +08:00
parent dcf4bf0f14
commit c1cd7444cb
3 changed files with 26 additions and 18 deletions

View file

@ -511,3 +511,5 @@
1400837774,11190990.08,4331119.44,45590.26,2587281.10
1400837785,10306507.50,3909290.89,47662.55,2827471.10
1400837797,10323334.38,4221122.48,55924.05,2294463.55
1400922358,11238818.94,4585324.58,59074.70,2649691.23
1400922668,10605016.95,4435942.19,52428.80,2805666.62

Can't render this file because it has a wrong number of fields in line 447.

View file

@ -31,16 +31,21 @@ typedef struct _route route;
struct _node {
edge ** edges;
route ** routes;
int edge_len;
int edge_cap;
int route_len;
int route_cap;
int endpoint;
// almost less than 255
unsigned char edge_len;
unsigned char edge_cap;
// almost less than 255
unsigned char route_len;
unsigned char route_cap;
unsigned char compare_type;
unsigned char endpoint;
/** compile-time variables here.... **/
/* the combined regexp pattern string from pattern_tokens */
int compare_type;
char * combined_pattern;
pcre * pcre_pattern;
pcre_extra * pcre_extra;
@ -49,15 +54,14 @@ struct _node {
* the pointer of route data
*/
void * data;
};
struct _edge {
char * pattern;
int pattern_len;
int opcode;
bool has_slug;
node * child;
unsigned char opcode;
unsigned short pattern_len;
bool has_slug:1;
};
typedef struct {

View file

@ -254,13 +254,16 @@ node * r3_tree_matchl(const node * n, char * path, int path_len, match_entry * e
info("try matching: %s\n", path);
edge *e;
int rc;
int i;
int ov_cnt;
int restlen;
char rc;
unsigned short i;
unsigned short ov_cnt;
unsigned short restlen;
char *pp;
char *pp_end = path + path_len;
char *substring_start = NULL;
int substring_length = 0;
if (n->compare_type == NODE_COMPARE_OPCODE) {
for (i = 0; i < n->edge_len ; i++ ) {
pp = path;
@ -333,8 +336,6 @@ node * r3_tree_matchl(const node * n, char * path, int path_len, match_entry * e
}
char *substring_start;
int substring_length;
for (i = 1; i < rc; i++)
{
substring_start = path + ov[2*i];
@ -372,6 +373,8 @@ node * r3_tree_matchl(const node * n, char * path, int path_len, match_entry * e
return NULL;
}
route * r3_tree_match_route(const node *tree, match_entry * entry) {
node *n;
n = r3_tree_match_entry(tree, entry);
@ -387,8 +390,7 @@ route * r3_tree_match_route(const node *tree, match_entry * entry) {
}
inline edge * r3_node_find_edge_str(const node * n, char * str, int str_len) {
int i = 0;
int matched_idx = -1;
unsigned short i = 0;
char firstbyte = *str;
for (; i < n->edge_len ; i++ ) {
if ( firstbyte == *(n->edges[i]->pattern) ) {