Kouhei Sutou
null+****@clear*****
Wed May 13 11:08:31 JST 2015
Kouhei Sutou 2015-05-13 11:08:31 +0900 (Wed, 13 May 2015) New Revision: de2337dbb14a1b82791241bf1afc0ce1dac89084 https://github.com/groonga/groonga/commit/de2337dbb14a1b82791241bf1afc0ce1dac89084 Message: Reduce the number of grn_getenv() calls for grn_mrb We just call them once on init. Modified files: lib/ctx.c lib/grn_mrb.h lib/mrb.c Modified: lib/ctx.c (+8 -0) =================================================================== --- lib/ctx.c 2015-05-13 11:01:40 +0900 (78b5758) +++ lib/ctx.c 2015-05-13 11:08:31 +0900 (fb5bd89) @@ -28,6 +28,7 @@ #include "grn_snip.h" #include "grn_output.h" #include "grn_normalizer.h" +#include "grn_mrb.h" #include "grn_ctx_impl_mrb.h" #include "grn_logger.h" #include <stdio.h> @@ -837,6 +838,12 @@ grn_init(void) grn_query_logger_init(); CRITICAL_SECTION_INIT(grn_glock); grn_gtick = 0; +#ifdef GRN_WITH_MRUBY + if ((rc = grn_mrb_init())) { + GRN_LOG(ctx, GRN_LOG_ALERT, "grn_mrb_init failed (%d)", rc); + return rc; + } +#endif ctx->next = ctx; ctx->prev = ctx; grn_ctx_init_internal(ctx, 0); @@ -1042,6 +1049,7 @@ grn_fin(void) grn_ii_fin(); grn_io_fin(); grn_ctx_fin(ctx); + grn_mrb_fin(); grn_com_fin(); GRN_LOG(ctx, GRN_LOG_NOTICE, "grn_fin (%d)", alloc_count); grn_logger_fin(ctx); Modified: lib/grn_mrb.h (+3 -0) =================================================================== --- lib/grn_mrb.h 2015-05-13 11:01:40 +0900 (7fae820) +++ lib/grn_mrb.h 2015-05-13 11:08:31 +0900 (ecf8666) @@ -31,6 +31,9 @@ extern "C" { #endif #ifdef GRN_WITH_MRUBY +grn_rc grn_mrb_init(void); +grn_rc grn_mrb_fin(void); + GRN_API mrb_value grn_mrb_eval(grn_ctx *ctx, const char *script, int script_length); GRN_API mrb_value grn_mrb_load(grn_ctx *ctx, const char *path); GRN_API grn_rc grn_mrb_to_grn(grn_ctx *ctx, mrb_value mrb_object, grn_obj *grn_object); Modified: lib/mrb.c (+17 -7) =================================================================== --- lib/mrb.c 2015-05-13 11:01:40 +0900 (60d2172) +++ lib/mrb.c 2015-05-13 11:08:31 +0900 (310afe3) @@ -36,6 +36,21 @@ #define E_LOAD_ERROR (mrb_class_get(mrb, "LoadError")) #ifdef GRN_WITH_MRUBY +static char grn_mrb_ruby_scripts_dir[GRN_ENV_BUFFER_SIZE]; + +grn_rc +grn_mrb_init(void) +{ + grn_getenv("GRN_RUBY_SCRIPTS_DIR", + grn_mrb_ruby_scripts_dir, + GRN_ENV_BUFFER_SIZE); +} + +grn_rc +grn_mrb_fin(void) +{ +} + # ifdef WIN32 static char *win32_ruby_scripts_dir = NULL; static char win32_ruby_scripts_dir_buffer[PATH_MAX]; @@ -68,13 +83,8 @@ grn_mrb_get_default_system_ruby_scripts_dir(void) const char * grn_mrb_get_system_ruby_scripts_dir(grn_ctx *ctx) { - static char ruby_scripts_dir[GRN_ENV_BUFFER_SIZE]; - - grn_getenv("GRN_RUBY_SCRIPTS_DIR", - ruby_scripts_dir, - GRN_ENV_BUFFER_SIZE); - if (ruby_scripts_dir[0]) { - return ruby_scripts_dir; + if (grn_mrb_ruby_scripts_dir[0]) { + return grn_mrb_ruby_scripts_dir; } else { return grn_mrb_get_default_system_ruby_scripts_dir(); } -------------- next part -------------- HTML����������������������������...Download