diff options
Diffstat (limited to 'include/ruby/internal/core/rmatch.h')
| -rw-r--r-- | include/ruby/internal/core/rmatch.h | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/include/ruby/internal/core/rmatch.h b/include/ruby/internal/core/rmatch.h index 2d2fd897f5..ae93755531 100644 --- a/include/ruby/internal/core/rmatch.h +++ b/include/ruby/internal/core/rmatch.h @@ -67,21 +67,6 @@ struct rmatch_offset { long end; /**< End of a group. */ }; -/** Represents a match. */ -struct rmatch { - /** - * "Registers" of a match. This is a quasi-opaque struct that holds - * execution result of a match. Roughly resembles `&~`. - */ - struct re_registers regs; - - /** Capture group offsets, in C array. */ - struct rmatch_offset *char_offset; - - /** Number of ::rmatch_offset that ::rmatch::char_offset holds. */ - int char_offset_num_allocated; -}; - /** * Regular expression execution context. When a regular expression "matches" * to a string, it generates capture groups etc. This struct holds that info. @@ -102,18 +87,44 @@ struct RMatch { VALUE str; /** - * The result of this match. + * The expression of this match. */ - struct rmatch *rmatch; + VALUE regexp; /* RRegexp */ + + /** Number of ::rmatch_offset that ::rmatch::char_offset holds. */ + int char_offset_num_allocated; + + /** Capture group offsets, in C array. */ + struct rmatch_offset *char_offset; + + /** Number of capture-group registers. */ + int num_regs; + + /** Capacity of `as.embed`, in OnigPosition slots. */ + int capa; /** - * The expression of this match. + * "Registers" of a match. This is a quasi-opaque struct that holds + * execution result of a match. Roughly resembles `$~`. */ - VALUE regexp; /* RRegexp */ + union { + OnigPosition embed[1]; + struct re_registers onig; + } as; }; -RBIMPL_ATTR_PURE_UNLESS_DEBUG() -RBIMPL_ATTR_ARTIFICIAL() +RBIMPL_SYMBOL_EXPORT_BEGIN() +/** + * @private + * + * Converts an embedded match to onig form. This is an implementation + * detail of #RMATCH_REGS. People don't use it directly. + * + * @param[out] match A match object, possibly in embedded form. + */ +void rb_match_ensure_onig(VALUE match); +RBIMPL_SYMBOL_EXPORT_END() + /** * Queries the raw ::re_registers. * @@ -139,8 +150,8 @@ static inline struct re_registers * RMATCH_REGS(VALUE match) { RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH); - RBIMPL_ASSERT_OR_ASSUME(RMATCH(match)->rmatch != NULL); - return &RMATCH(match)->rmatch->regs; + rb_match_ensure_onig(match); + return &RMATCH(match)->as.onig; } #endif /* RBIMPL_RMATCH_H */ |
