Skip to content

Commit

Permalink
cache mrb_regexp_p(); ref #980
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Feb 4, 2016
1 parent 4344ca0 commit 5e514c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/mruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
13 changes: 12 additions & 1 deletion src/etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e514c9

Please sign in to comment.