Remove unnecessary `mrb_regexp_check()` and related functions.

parent 9ca9af60
...@@ -196,13 +196,9 @@ struct mrb_jmpbuf; ...@@ -196,13 +196,9 @@ struct mrb_jmpbuf;
typedef void (*mrb_atexit_func)(struct mrb_state*); typedef void (*mrb_atexit_func)(struct mrb_state*);
#define MRB_STATE_NO_REGEXP 1
#define MRB_STATE_REGEXP 2
typedef struct mrb_state { typedef struct mrb_state {
struct mrb_jmpbuf *jmp; struct mrb_jmpbuf *jmp;
uint32_t flags;
mrb_allocf allocf; /* memory allocation function */ mrb_allocf allocf; /* memory allocation function */
void *allocf_ud; /* auxiliary data of allocf */ void *allocf_ud; /* auxiliary data of allocf */
......
...@@ -433,9 +433,6 @@ mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); ...@@ -433,9 +433,6 @@ mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
*/ */
mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str);
void mrb_noregexp(mrb_state *mrb, mrb_value self);
void mrb_regexp_check(mrb_state *mrb, mrb_value obj);
/* For backward compatibility */ /* For backward compatibility */
#define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr) #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr)
#define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len) #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len)
......
...@@ -180,7 +180,6 @@ typedef void mrb_value; ...@@ -180,7 +180,6 @@ typedef void mrb_value;
#define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR) #define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
#define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION) #define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
#define mrb_test(o) mrb_bool(o) #define mrb_test(o) mrb_bool(o)
MRB_API mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
/* /*
* Returns a float in Ruby. * Returns a float in Ruby.
......
...@@ -194,22 +194,6 @@ mrb_word_boxing_cptr_value(mrb_state *mrb, void *p) ...@@ -194,22 +194,6 @@ mrb_word_boxing_cptr_value(mrb_state *mrb, void *p)
} }
#endif /* MRB_WORD_BOXING */ #endif /* MRB_WORD_BOXING */
MRB_API mrb_bool
mrb_regexp_p(mrb_state *mrb, mrb_value v)
{
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_NO_REGEXP;
}
return FALSE;
}
#if defined _MSC_VER && _MSC_VER < 1900 #if defined _MSC_VER && _MSC_VER < 1900
#ifndef va_copy #ifndef va_copy
......
...@@ -997,20 +997,6 @@ mrb_string_value_len(mrb_state *mrb, mrb_value ptr) ...@@ -997,20 +997,6 @@ mrb_string_value_len(mrb_state *mrb, mrb_value ptr)
return RSTRING_LEN(ptr); return RSTRING_LEN(ptr);
} }
void
mrb_noregexp(mrb_state *mrb, mrb_value self)
{
mrb_raise(mrb, E_NOTIMP_ERROR, "Regexp class not implemented");
}
void
mrb_regexp_check(mrb_state *mrb, mrb_value obj)
{
if (mrb_regexp_p(mrb, obj)) {
mrb_noregexp(mrb, obj);
}
}
MRB_API mrb_value MRB_API mrb_value
mrb_str_dup(mrb_state *mrb, mrb_value str) mrb_str_dup(mrb_state *mrb, mrb_value str)
{ {
...@@ -1026,7 +1012,6 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx) ...@@ -1026,7 +1012,6 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
{ {
mrb_int idx; mrb_int idx;
mrb_regexp_check(mrb, indx);
switch (mrb_type(indx)) { switch (mrb_type(indx)) {
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
idx = mrb_fixnum(indx); idx = mrb_fixnum(indx);
...@@ -1119,7 +1104,6 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) ...@@ -1119,7 +1104,6 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str)
if (argc == 2) { if (argc == 2) {
mrb_int n1, n2; mrb_int n1, n2;
mrb_regexp_check(mrb, a1);
mrb_get_args(mrb, "ii", &n1, &n2); mrb_get_args(mrb, "ii", &n1, &n2);
return str_substr(mrb, str, n1, n2); return str_substr(mrb, str, n1, n2);
} }
...@@ -1549,7 +1533,6 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) ...@@ -1549,7 +1533,6 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str)
else else
sub = mrb_nil_value(); sub = mrb_nil_value();
} }
mrb_regexp_check(mrb, sub);
clen = RSTRING_CHAR_LEN(str); clen = RSTRING_CHAR_LEN(str);
if (pos < 0) { if (pos < 0) {
pos += clen; pos += clen;
...@@ -1801,7 +1784,6 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str) ...@@ -1801,7 +1784,6 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str)
if (pos < 0) { if (pos < 0) {
pos += len; pos += len;
if (pos < 0) { if (pos < 0) {
mrb_regexp_check(mrb, sub);
return mrb_nil_value(); return mrb_nil_value();
} }
} }
...@@ -1815,7 +1797,6 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str) ...@@ -1815,7 +1797,6 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str)
sub = mrb_nil_value(); sub = mrb_nil_value();
} }
pos = chars2bytes(str, 0, pos); pos = chars2bytes(str, 0, pos);
mrb_regexp_check(mrb, sub);
switch (mrb_type(sub)) { switch (mrb_type(sub)) {
default: { default: {
...@@ -1909,16 +1890,11 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -1909,16 +1890,11 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
if (argc == 0 || mrb_nil_p(spat)) { if (argc == 0 || mrb_nil_p(spat)) {
split_type = awk; split_type = awk;
} }
else { else if (!mrb_string_p(spat)) {
if (mrb_string_p(spat)) { mrb_raise(mrb, E_TYPE_ERROR, "expected String");
split_type = string; }
if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' ') { else if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' ') {
split_type = awk; split_type = awk;
}
}
else {
mrb_noregexp(mrb, str);
}
} }
result = mrb_ary_new(mrb); result = mrb_ary_new(mrb);
...@@ -1955,7 +1931,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -1955,7 +1931,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
} }
} }
} }
else if (split_type == string) { else { /* split_type == string */
mrb_int str_len = RSTRING_LEN(str); mrb_int str_len = RSTRING_LEN(str);
mrb_int pat_len = RSTRING_LEN(spat); mrb_int pat_len = RSTRING_LEN(spat);
mrb_int idx = 0; mrb_int idx = 0;
...@@ -1976,9 +1952,6 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -1976,9 +1952,6 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
} }
beg = idx; beg = idx;
} }
else {
mrb_noregexp(mrb, str);
}
if (RSTRING_LEN(str) > 0 && (lim_p || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) > 0 && (lim_p || RSTRING_LEN(str) > beg || lim < 0)) {
if (RSTRING_LEN(str) == beg) { if (RSTRING_LEN(str) == beg) {
tmp = mrb_str_new_empty(mrb, str); tmp = mrb_str_new_empty(mrb, str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment