Kouhei Sutou
null+****@clear*****
Wed May 13 10:53:01 JST 2015
Kouhei Sutou 2015-05-13 10:53:01 +0900 (Wed, 13 May 2015) New Revision: fe119bebc1d209b01ed1004d8654dab208166e5e https://github.com/groonga/groonga/commit/fe119bebc1d209b01ed1004d8654dab208166e5e Message: Reduce the number of grn_getenv() calls We just call them once on init. Modified files: lib/ctx.c lib/grn_proc.h lib/proc.c Modified: lib/ctx.c (+6 -0) =================================================================== --- lib/ctx.c 2015-05-13 03:13:38 +0900 (6887e7e) +++ lib/ctx.c 2015-05-13 10:53:01 +0900 (af18c69) @@ -23,6 +23,7 @@ #include "grn_ctx_impl.h" #include "grn_ii.h" #include "grn_pat.h" +#include "grn_proc.h" #include "grn_plugin.h" #include "grn_snip.h" #include "grn_output.h" @@ -906,6 +907,10 @@ grn_init(void) GRN_LOG(ctx, GRN_LOG_ALERT, "ii initialize failed (%d)", rc); return rc; } + if ((rc = grn_proc_init())) { + GRN_LOG(ctx, GRN_LOG_ALERT, "grn_proc_init failed (%d)", rc); + return rc; + } if ((rc = grn_plugins_init())) { GRN_LOG(ctx, GRN_LOG_ALERT, "plugins initialize failed (%d)", rc); return rc; @@ -1022,6 +1027,7 @@ grn_fin(void) grn_tokenizers_fin(); grn_normalizer_fin(); grn_plugins_fin(); + grn_proc_fin(); grn_ii_fin(); grn_io_fin(); grn_ctx_fin(ctx); Modified: lib/grn_proc.h (+4 -1) =================================================================== --- lib/grn_proc.h 2015-05-13 03:13:38 +0900 (fb01698) +++ lib/grn_proc.h 2015-05-13 10:53:01 +0900 (cebbfca) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2009 Brazil +/* Copyright(C) 2009-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -23,6 +23,9 @@ extern "C" { #endif +grn_rc grn_proc_init(void); +grn_rc grn_proc_fin(void); + GRN_VAR const char *grn_document_root; void grn_db_init_builtin_query(grn_ctx *ctx); Modified: lib/proc.c (+32 -25) =================================================================== --- lib/proc.c 2015-05-13 03:13:38 +0900 (ee1224e) +++ lib/proc.c 2015-05-13 10:53:01 +0900 (249dcd1) @@ -57,6 +57,36 @@ const char *grn_document_root = NULL; #define GRN_SELECT_INTERNAL_VAR_CONDITION "$condition" #define GRN_SELECT_INTERNAL_VAR_MATCH_COLUMNS "$match_columns" + +static double grn_between_too_many_index_match_ratio = 0.01; +static double grn_in_values_too_many_index_match_ratio = 0.01; + +grn_rc +grn_proc_init(void) +{ + { + char grn_between_too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; + grn_getenv("GRN_BETWEEN_TOO_MANY_INDEX_MATCH_RATIO", + grn_between_too_many_index_match_ratio_env, + GRN_ENV_BUFFER_SIZE); + if (grn_between_too_many_index_match_ratio_env[0]) { + grn_between_too_many_index_match_ratio = + atof(grn_between_too_many_index_match_ratio_env); + } + } + + { + char grn_in_values_too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; + grn_getenv("GRN_IN_VALUES_TOO_MANY_INDEX_MATCH_RATIO", + grn_in_values_too_many_index_match_ratio_env, + GRN_ENV_BUFFER_SIZE); + if (grn_in_values_too_many_index_match_ratio_env[0]) { + grn_in_values_too_many_index_match_ratio = + atof(grn_in_values_too_many_index_match_ratio_env); + } + } +} + /* bulk must be initialized grn_bulk or grn_msg */ static int grn_bulk_put_from_file(grn_ctx *ctx, grn_obj *bulk, const char *path) @@ -5713,21 +5743,9 @@ selector_between_sequential_search(grn_ctx *ctx, between_data *data, grn_obj *res, grn_operator op) { - double too_many_index_match_ratio = 0.01; - - { - char too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; - grn_getenv("GRN_BETWEEN_TOO_MANY_INDEX_MATCH_RATIO", - too_many_index_match_ratio_env, - GRN_ENV_BUFFER_SIZE); - if (too_many_index_match_ratio_env[0]) { - too_many_index_match_ratio = atof(too_many_index_match_ratio_env); - } - } - if (!selector_between_sequential_search_should_use( ctx, table, index, index_table, data, res, op, - too_many_index_match_ratio)) { + grn_between_too_many_index_match_ratio)) { return GRN_FALSE; } @@ -6211,19 +6229,8 @@ selector_in_values_sequential_search(grn_ctx *ctx, { grn_obj *source; int n_existing_records; - double too_many_index_match_ratio = 0.01; - { - char too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; - grn_getenv("GRN_IN_VALUES_TOO_MANY_INDEX_MATCH_RATIO", - too_many_index_match_ratio_env, - GRN_ENV_BUFFER_SIZE); - if (too_many_index_match_ratio_env[0]) { - too_many_index_match_ratio = atof(too_many_index_match_ratio_env); - } - } - - if (too_many_index_match_ratio < 0.0) { + if (grn_in_values_too_many_index_match_ratio < 0.0) { return GRN_FALSE; } -------------- next part -------------- HTML����������������������������...다운로드