Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ releases.
* test-unit 3.7.7
* 3.7.5 to [3.7.6][test-unit-3.7.6], [3.7.7][test-unit-3.7.7]
* net-imap 0.6.4
* 0.6.2 to [v0.6.3][net-imap-v0.6.3]
* 0.6.2 to [v0.6.3][net-imap-v0.6.3], [v0.6.4][net-imap-v0.6.4]
* rbs 4.0.2
* 3.10.0 to [v3.10.1][rbs-v3.10.1], [v3.10.2][rbs-v3.10.2], [v3.10.3][rbs-v3.10.3], [v3.10.4][rbs-v3.10.4], [v4.0.0.dev.5][rbs-v4.0.0.dev.5], [v4.0.0][rbs-v4.0.0], [v4.0.2][rbs-v4.0.2]
* typeprof 0.32.0
* mutex_m 0.3.0
* bigdecimal 4.1.2
* 4.0.1 to [v4.1.0][bigdecimal-v4.1.0], [v4.1.1][bigdecimal-v4.1.1], [v4.1.2][bigdecimal-v4.1.2]
Expand Down Expand Up @@ -221,6 +222,7 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
[test-unit-3.7.6]: https://github.com/test-unit/test-unit/releases/tag/3.7.6
[test-unit-3.7.7]: https://github.com/test-unit/test-unit/releases/tag/3.7.7
[net-imap-v0.6.3]: https://github.com/ruby/net-imap/releases/tag/v0.6.3
[net-imap-v0.6.4]: https://github.com/ruby/net-imap/releases/tag/v0.6.4
[rbs-v3.10.1]: https://github.com/ruby/rbs/releases/tag/v3.10.1
[rbs-v3.10.2]: https://github.com/ruby/rbs/releases/tag/v3.10.2
[rbs-v3.10.3]: https://github.com/ruby/rbs/releases/tag/v3.10.3
Expand Down
11 changes: 11 additions & 0 deletions benchmark/string_gsub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ prelude: |
}
ESCAPE_PATTERN = Regexp.union(ESCAPED_CHARS.keys)
NO_MATCH_SHARED_STRING = ("a" * 100_000).freeze
benchmark:
gsub_no_match_shared: |
str = NO_MATCH_SHARED_STRING.dup
str.gsub!("z", "x")
str
sub_no_match_shared: |
str = NO_MATCH_SHARED_STRING.dup
str.sub!("z", "x")
str
escape: |
str = STR.dup
str.gsub!(ESCAPE_PATTERN, ESCAPED_CHARS)
Expand Down
6 changes: 6 additions & 0 deletions benchmark/vm_regexp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ prelude: |
benchmark:
vm_regexp: |
/hoge/ =~ str
vm_regexp_alternating: |
/hoge/ =~ str
/huge/ =~ str
vm_regexp_invert: |
str =~ /hoge/
vm_regexp_invert_alternating: |
str =~ /hoge/
str =~ /huge/
loop_count: 6000000
1 change: 1 addition & 0 deletions depend
Original file line number Diff line number Diff line change
Expand Up @@ -5952,6 +5952,7 @@ gc.$(OBJEXT): $(top_srcdir)/internal/numeric.h
gc.$(OBJEXT): $(top_srcdir)/internal/object.h
gc.$(OBJEXT): $(top_srcdir)/internal/proc.h
gc.$(OBJEXT): $(top_srcdir)/internal/rational.h
gc.$(OBJEXT): $(top_srcdir)/internal/re.h
gc.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
gc.$(OBJEXT): $(top_srcdir)/internal/serial.h
gc.$(OBJEXT): $(top_srcdir)/internal/set_table.h
Expand Down
2 changes: 1 addition & 1 deletion ext/digest/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static rb_digest_metadata_t *
get_digest_base_metadata(VALUE klass)
{
VALUE p;
VALUE obj;
VALUE obj = Qnil;
rb_digest_metadata_t *algo;

for (p = klass; !NIL_P(p); p = rb_class_superclass(p)) {
Expand Down
15 changes: 10 additions & 5 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#include "internal/object.h"
#include "internal/proc.h"
#include "internal/rational.h"
#include "internal/re.h"
#include "internal/sanitizers.h"
#include "internal/struct.h"
#include "internal/symbol.h"
Expand Down Expand Up @@ -1643,17 +1644,19 @@ rb_gc_obj_free(void *objspace, VALUE obj)
{
struct RMatch *rm = RMATCH(obj);
#if USE_DEBUG_COUNTER
if (rm->regs.num_regs >= 8) {
if (rm->num_regs >= 8) {
RB_DEBUG_COUNTER_INC(obj_match_ge8);
}
else if (rm->regs.num_regs >= 4) {
else if (rm->num_regs >= 4) {
RB_DEBUG_COUNTER_INC(obj_match_ge4);
}
else if (rm->regs.num_regs >= 1) {
else if (rm->num_regs >= 1) {
RB_DEBUG_COUNTER_INC(obj_match_under4);
}
#endif
onig_region_free(&rm->regs, 0);
if (FL_TEST_RAW(obj, RMATCH_ONIG)) {
onig_region_free(&rm->as.onig, 0);
}
SIZED_FREE_N(rm->char_offset, rm->char_offset_num_allocated);

RB_DEBUG_COUNTER_INC(obj_match_ptr);
Expand Down Expand Up @@ -2640,7 +2643,9 @@ rb_obj_memsize_of(VALUE obj)
case T_MATCH:
{
struct RMatch *rm = RMATCH(obj);
size += onig_region_memsize(&rm->regs);
if (FL_TEST_RAW(obj, RMATCH_ONIG)) {
size += onig_region_memsize(&rm->as.onig);
}
size += sizeof(struct rmatch_offset) * rm->char_offset_num_allocated;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ net-smtp 0.5.1 https://github.com/ruby/net-smtp
matrix 0.4.3 https://github.com/ruby/matrix
prime 0.1.4 https://github.com/ruby/prime
rbs 4.0.2 https://github.com/ruby/rbs 36a7e8e38df9efd33db83c3f30f0308bdeb84bd9
typeprof 0.31.1 https://github.com/ruby/typeprof
typeprof 0.32.0 https://github.com/ruby/typeprof
debug 1.11.1 https://github.com/ruby/debug 9dc2024a5a05116b3d38afbc5579d9503d8913f3
racc 1.8.1 https://github.com/ruby/racc
mutex_m 0.3.0 https://github.com/ruby/mutex_m
Expand All @@ -37,7 +37,7 @@ ostruct 0.6.3 https://github.com/ruby/ostruct
pstore 0.2.1 https://github.com/ruby/pstore
benchmark 0.5.0 https://github.com/ruby/benchmark
logger 1.7.0 https://github.com/ruby/logger
rdoc 7.2.0 https://github.com/ruby/rdoc 1f93543615928b6d45357432f16ec6006e2d8b1e
rdoc 7.2.0 https://github.com/ruby/rdoc bc0baee787609f2205e8f1103f3e1d36b923184a
win32ole 1.9.3 https://github.com/ruby/win32ole
irb 1.18.0 https://github.com/ruby/irb
reline 0.6.3 https://github.com/ruby/reline
Expand Down
44 changes: 32 additions & 12 deletions include/ruby/internal/core/rmatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,40 @@ struct RMatch {
*/
VALUE regexp; /* RRegexp */

/**
* "Registers" of a match. This is a quasi-opaque struct that holds
* execution result of a match. Roughly resembles `$~`.
*/
struct re_registers regs;
/** Number of ::rmatch_offset that ::rmatch::char_offset holds. */
int char_offset_num_allocated;

/** 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;

/** 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;

/**
* "Registers" of a match. This is a quasi-opaque struct that holds
* execution result of a match. Roughly resembles `$~`.
*/
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.
*
Expand All @@ -131,7 +150,8 @@ static inline struct re_registers *
RMATCH_REGS(VALUE match)
{
RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH);
return &RMATCH(match)->regs;
rb_match_ensure_onig(match);
return &RMATCH(match)->as.onig;
}

#endif /* RBIMPL_RMATCH_H */
6 changes: 3 additions & 3 deletions internal/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ RCLASS_PRIME_CLASSEXT_WRITABLE_P(VALUE klass)
{
VM_ASSERT(klass != 0, "klass should be a valid object");
VM_ASSERT_BOXABLE_TYPE(klass);
return FL_TEST(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
return FL_TEST_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
}

static inline void
Expand All @@ -306,10 +306,10 @@ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE klass, bool writable)
VM_ASSERT(klass != 0, "klass should be a valid object");
VM_ASSERT_BOXABLE_TYPE(klass);
if (writable) {
FL_SET(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
FL_SET_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
}
else {
FL_UNSET(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
FL_UNSET_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
}
}

Expand Down
19 changes: 16 additions & 3 deletions internal/re.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@
#include "ruby/ruby.h" /* for VALUE */
#include "ruby/re.h" /* for struct RMatch and struct re_registers */

#define RMATCH_ONIG FL_USER1

static inline OnigPosition *
RMATCH_BEG_PTR(VALUE match)
{
return RMATCH(match)->regs.beg;
if (FL_TEST_RAW(match, RMATCH_ONIG)) {
return RMATCH(match)->as.onig.beg;
}
else {
return &RMATCH(match)->as.embed[0];
}
}

static inline OnigPosition *
RMATCH_END_PTR(VALUE match)
{
return RMATCH(match)->regs.end;
if (FL_TEST_RAW(match, RMATCH_ONIG)) {
return RMATCH(match)->as.onig.end;
}
else {
return &RMATCH(match)->as.embed[RMATCH(match)->num_regs];
}
}

static inline long
Expand All @@ -39,7 +51,7 @@ RMATCH_END(VALUE match, int i)
static inline int
RMATCH_NREGS(VALUE match)
{
return RMATCH(match)->regs.num_regs;
return RMATCH(match)->num_regs;
}

/* re.c */
Expand All @@ -48,6 +60,7 @@ VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourcel
VALUE rb_reg_check_preprocess(VALUE);
long rb_reg_search0(VALUE, VALUE, long, int, int, VALUE *);
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
VALUE rb_reg_regsub_match(VALUE str, VALUE src, VALUE match);
bool rb_reg_start_with_p(VALUE re, VALUE str);
VALUE rb_reg_hash(VALUE re);
VALUE rb_reg_equal(VALUE re1, VALUE re2);
Expand Down
Loading