[Groonga-commit] groonga/groonga at 3fce068 [master] mrb ctx: cache singleton object

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Sep 12 21:52:56 JST 2014


Kouhei Sutou	2014-09-12 21:52:56 +0900 (Fri, 12 Sep 2014)

  New Revision: 3fce068cc2a15fa47e8e9bc3a948a2c285b8e97c
  https://github.com/groonga/groonga/commit/3fce068cc2a15fa47e8e9bc3a948a2c285b8e97c

  Message:
    mrb ctx: cache singleton object

  Modified files:
    lib/mrb/mrb_ctx.c

  Modified: lib/mrb/mrb_ctx.c (+11 -3)
===================================================================
--- lib/mrb/mrb_ctx.c    2014-09-12 18:14:02 +0900 (81a584d)
+++ lib/mrb/mrb_ctx.c    2014-09-12 21:52:56 +0900 (f9fbb42)
@@ -34,9 +34,17 @@ ctx_class_instance(mrb_state *mrb, mrb_value klass)
 {
   grn_ctx *ctx = (grn_ctx *)mrb->ud;
   mrb_value mrb_ctx;
-
-  mrb_ctx = mrb_obj_value(mrb_obj_alloc(mrb, MRB_TT_DATA, mrb_class_ptr(klass)));
-  DATA_PTR(mrb_ctx) = ctx;
+  mrb_sym iv_name;
+
+  iv_name = mrb_intern_lit(mrb, "@instance");
+  mrb_ctx = mrb_iv_get(mrb, klass, iv_name);
+  if (mrb_nil_p(mrb_ctx)) {
+    struct RBasic *raw_mrb_ctx;
+    raw_mrb_ctx = mrb_obj_alloc(mrb, MRB_TT_DATA, mrb_class_ptr(klass));
+    mrb_ctx = mrb_obj_value(raw_mrb_ctx);
+    DATA_PTR(mrb_ctx) = ctx;
+    mrb_iv_set(mrb, klass, iv_name, mrb_ctx);
+  }
 
   return mrb_ctx;
 }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index