null+****@clear*****
null+****@clear*****
2011年 6月 14日 (火) 16:31:52 JST
Kouhei Sutou 2011-06-14 07:31:52 +0000 (Tue, 14 Jun 2011) New Revision: 125f64acb0b3f703851617f9d4bc6e5854a0ab3e Log: [default] split columns open code. Modified files: ha_mroonga.cc ha_mroonga.h Modified: ha_mroonga.cc (+39 -25) =================================================================== --- ha_mroonga.cc 2011-06-14 07:01:44 +0000 (f3e077d) +++ ha_mroonga.cc 2011-06-14 07:31:52 +0000 (6a06788) @@ -1586,31 +1586,10 @@ int ha_mroonga::default_open(const char *name, int mode, uint test_if_locked) if (error) DBUG_RETURN(error); - /* open columns */ - int n_columns = table->s->fields; - grn_columns = (grn_obj**) malloc(sizeof(grn_obj*) * n_columns); - - int i; - for (i = 0; i < n_columns; i++) { - Field *field = table->field[i]; - const char *col_name = field->field_name; - int col_name_size = strlen(col_name); - - if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) { - grn_columns[i] = NULL; - continue; - } - if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) { - grn_columns[i] = NULL; - continue; - } - - grn_columns[i] = grn_obj_column(ctx, grn_table, col_name, col_name_size); - if (ctx->rc) { - grn_obj_unlink(ctx, grn_table); - my_message(ER_CANT_OPEN_FILE, ctx->errbuf, MYF(0)); - DBUG_RETURN(ER_CANT_OPEN_FILE); - } + error = default_open_columns(); + if (error) { + grn_obj_unlink(ctx, grn_table); + DBUG_RETURN(error); } /* open indexes */ @@ -1629,6 +1608,7 @@ int ha_mroonga::default_open(const char *name, int mode, uint test_if_locked) char table_name[MRN_MAX_PATH_SIZE]; mrn_table_name_gen(name, table_name); + int i; for (i = 0; i < n_keys; i++) { key_min[i] = (char*) malloc(MRN_MAX_KEY_SIZE); key_max[i] = (char*) malloc(MRN_MAX_KEY_SIZE); @@ -1679,6 +1659,40 @@ int ha_mroonga::open_table(const char *name) DBUG_RETURN(0); } +int ha_mroonga::default_open_columns(void) +{ + MRN_DBUG_ENTER_METHOD(); + + int n_columns = table->s->fields; + grn_columns = (grn_obj **)malloc(sizeof(grn_obj *) * n_columns); + + int i; + for (i = 0; i < n_columns; i++) { + Field *field = table->field[i]; + const char *column_name = field->field_name; + int column_name_size = strlen(column_name); + + if (strncmp(MRN_ID_COL_NAME, column_name, column_name_size) == 0) { + grn_columns[i] = NULL; + continue; + } + if (strncmp(MRN_SCORE_COL_NAME, column_name, column_name_size) == 0) { + grn_columns[i] = NULL; + continue; + } + + grn_columns[i] = grn_obj_column(ctx, grn_table, + column_name, column_name_size); + if (ctx->rc) { + int error = ER_CANT_OPEN_FILE; + my_message(error, ctx->errbuf, MYF(0)); + DBUG_RETURN(error); + } + } + + DBUG_RETURN(0); +} + int ha_mroonga::open(const char *name, int mode, uint test_if_locked) { int error; Modified: ha_mroonga.h (+1 -0) =================================================================== --- ha_mroonga.h 2011-06-14 07:01:44 +0000 (320c785) +++ ha_mroonga.h 2011-06-14 07:31:52 +0000 (18f74c1) @@ -228,6 +228,7 @@ private: int wrapper_open(const char *name, int mode, uint test_if_locked); int default_open(const char *name, int mode, uint test_if_locked); int open_table(const char *name); + int default_open_columns(void); int wrapper_close(); int default_close(); int mrn_extra(enum ha_extra_function operation);