Permalink
Browse files

cache mrb_regexp_p(); ref #980

  • Loading branch information...
matz committed Feb 4, 2016
1 parent 4344ca0 commit 5e514c910fdde7ec29c9110e8c9535d8e83b2a8f
Showing with 16 additions and 1 deletion.
  1. +4 −0 include/mruby.h
  2. +12 −1 src/etc.c
View
@@ -124,9 +124,13 @@ typedef struct {
typedef void (*mrb_atexit_func)(struct mrb_state*);
#define MRB_STATE_NO_REGEXP 1
#define MRB_STATE_REGEXP 2
typedef struct mrb_state {
struct mrb_jmpbuf *jmp;
uint32_t flags;
mrb_allocf allocf; /* memory allocation function */
void *allocf_ud; /* auxiliary data of allocf */
View
@@ -179,7 +179,18 @@ mrb_word_boxing_cptr_value(mrb_state *mrb, void *p)
MRB_API mrb_bool
mrb_regexp_p(mrb_state *mrb, mrb_value v)
{
return mrb_class_defined(mrb, REGEXP_CLASS) && mrb_obj_is_kind_of(mrb, v, mrb_class_get(mrb, REGEXP_CLASS));
if (mrb->flags & MRB_STATE_NO_REGEXP) {
return FALSE;
}
if ((mrb->flags & MRB_STATE_REGEXP) || mrb_class_defined(mrb, REGEXP_CLASS)) {
mrb->flags |= MRB_STATE_REGEXP;
return mrb_obj_is_kind_of(mrb, v, mrb_class_get(mrb, REGEXP_CLASS));
}
else {
mrb->flags |= MRB_STATE_REGEXP;
mrb->flags |= MRB_STATE_NO_REGEXP;
}
return FALSE;
}
#if defined _MSC_VER && _MSC_VER < 1900

0 comments on commit 5e514c9

Please sign in to comment.