Skip to content

Commit

Permalink
Reduce the number of grn_getenv() calls for grn_ctx::impl::mrb
Browse files Browse the repository at this point in the history
We just call them once on init.
  • Loading branch information
kou committed May 13, 2015
1 parent 74d66a3 commit bf48c20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/ctx.c
Expand Up @@ -834,6 +834,7 @@ grn_init(void)
grn_rc rc;
grn_ctx *ctx = &grn_gctx;
grn_init_from_env();
grn_ctx_impl_mrb_init_from_env();
grn_logger_init();
grn_query_logger_init();
CRITICAL_SECTION_INIT(grn_glock);
Expand Down
24 changes: 18 additions & 6 deletions lib/ctx_impl_mrb.c
Expand Up @@ -60,6 +60,23 @@
# include <mruby/variable.h>
#endif /* GRN_WITH_MRUBY */

static grn_bool grn_ctx_impl_mrb_mruby_enabled = GRN_TRUE;

void
grn_ctx_impl_mrb_init_from_env(void)
{
{
char grn_mruby_enabled_env[GRN_ENV_BUFFER_SIZE];
grn_getenv("GRN_MRUBY_ENABLED",
grn_mruby_enabled_env,
GRN_ENV_BUFFER_SIZE);
if (grn_mruby_enabled_env[0] &&
strcmp(grn_mruby_enabled_env, "no") == 0) {
grn_ctx_impl_mrb_mruby_enabled = GRN_FALSE;
}
}
}

#ifdef GRN_WITH_MRUBY
static mrb_value
mrb_kernel_load(mrb_state *mrb, mrb_value self)
Expand Down Expand Up @@ -147,11 +164,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
void
grn_ctx_impl_mrb_init(grn_ctx *ctx)
{
char grn_mruby_enabled[GRN_ENV_BUFFER_SIZE];
grn_getenv("GRN_MRUBY_ENABLED",
grn_mruby_enabled,
GRN_ENV_BUFFER_SIZE);
if (grn_mruby_enabled[0] && strcmp(grn_mruby_enabled, "no") == 0) {
if (!grn_ctx_impl_mrb_mruby_enabled) {
ctx->impl->mrb.state = NULL;
ctx->impl->mrb.base_directory[0] = '\0';
ctx->impl->mrb.module = NULL;
Expand All @@ -162,7 +175,6 @@ grn_ctx_impl_mrb_init(grn_ctx *ctx)
ctx->impl->mrb.groonga.operator_class = NULL;
} else {
mrb_state *mrb;

mrb = mrb_open();
ctx->impl->mrb.state = mrb;
ctx->impl->mrb.base_directory[0] = '\0';
Expand Down
3 changes: 2 additions & 1 deletion lib/grn_ctx_impl_mrb.h
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2013 Brazil
Copyright(C) 2013-2015 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -26,6 +26,7 @@
extern "C" {
#endif

void grn_ctx_impl_mrb_init_from_env(void);
void grn_ctx_impl_mrb_init(grn_ctx *ctx);
void grn_ctx_impl_mrb_fin(grn_ctx *ctx);

Expand Down

0 comments on commit bf48c20

Please sign in to comment.