Commit Graph
2123 Commits
Author SHA1 Message Date
FletcherDares a6c4e98cbd Improve performance of String#codepoints with ASCII hot path in multi-byte strings. (#16991) 2026-05-23 08:16:43 +09:00
Nobuyoshi Nakada 7480cd8d37 Revert "[DOC] Remove unnecessary require" [ci skip]
This reverts commit bf01f6ae89, that was
an accidental commit by mistake.
2026-05-16 10:59:38 +09:00
Fletcher Dares 6a211f21e8 perf: Avoid eager gsub! copy on no match 2026-05-14 08:46:20 -07:00
John Hawthorn d5bd346c67 do_regsub 2026-05-14 07:07:45 -07:00
Nobuyoshi Nakada bf01f6ae89 [DOC] Remove unnecessary require
RDoc loads `rbs` within `rdoc/rbs_helper.rb`, but this is an internal
process and is not that the wrapper script is concerned with.
2026-05-13 19:08:58 +09:00
Nobuyoshi Nakada 61aa46c416 Adjust indent [ci skip] 2026-05-13 18:10:39 +09:00
Nobuyoshi Nakada de8d33295d pathname: Move same_paths? to pathname.c 2026-05-13 17:37:48 +09:00
John Hawthorn ee19cef31e Replace BEG/END with RMATCH_BEG/RMATCH_END 2026-05-08 13:41:12 -07:00
John Hawthorn 3d861274e6 Introduce RMATCH_{BEG,END,NREGS} helpers
These are internal-only helpers which can be used instead of the
RMATCH_REGS struct directly. RMATCH_REGS is just a pointer offset from
the RMatch VALUE itself, so this should not significantly affect
codegen.

The motivation for this is that it's both simpler, and should move us
towards being able to replace the storage for RMATCH, and to be able to
store the positions embedded instead of in separate malloc memory.
2026-05-08 13:41:12 -07:00
Jean Boussier deceb9f62e Rename rb_shape_obj_* into rb_obj_shape_*
For consistency.
2026-05-06 10:10:16 +02:00
Jean Boussier e4667e5109 Refactor NEWOB_OF for the common protected use case
Almost every objects are now WB protected, with just a few
exceptions, hence we can provide a much simpler interface.

It's also much easier to find the remaining unprotected objects.
2026-04-28 11:11:29 +09:00
Jean Boussier c202bc08e1 Simplify NEWOBJ_OF and introduce EC_NEWOBJ_OF
We only very rarely have the execution context available, so
it's preferable to provide a simpler default macro.
2026-04-28 11:11:29 +09:00
Jean Boussier 267ce6f842 Get rid of RGENGC_WB_PROTECTED_STRING
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 5bd3e85ea1 Make rb_enc_str_coderange inlinable by default
This is a generalization of the optimization done in re.c
as part of d0fbdb005c.

Code that deal with coderange can benefit significantly from
avoiding that function call, assuming coderange is often already
known.

Ref: https://github.com/ruby/json/pull/974
2026-04-22 08:50:38 +09:00
Jean Boussier fcd210086c Allow sharing middlesubstring if the terminator is present
Sharing middle substrings have been behind a compilation flags for
a very long time, and it's unclear if we'll ever make it the default.

However, we can still share middle substrings without breaking the
zero-terminated contract if the source string happens to have the
necessary NUL characters at that specific offset.

This is the case for some file formats such as FlatBuffers, BSON keys
and a few others.
2026-04-07 10:26:25 +02:00
Jean Boussier 42e0660be8 string.c: str_subseq propagate coderange when it is 7bit
Any substring of a 7bit string will be 7bit.
2026-04-07 10:15:35 +02:00
Nobuyoshi Nakada 13ebc5368c [DOC] Fill missing stars 2026-04-05 22:37:47 +09:00
Jean Boussier 53099633e2 Make ruby_xfree_sized and ruby_xrealloc_sized public
[Feature #21861]
2026-04-01 08:10:07 +01:00
ZHIJIE XIE 726205b354 string.c: guard tmp in rb_str_format_m (GH-16280)
Keep tmp alive while RARRAY_CONST_PTR(tmp) is used by rb_str_format.

[alan: sunk the guard below usage]
Reviewed-by: Alan Wu <XrXr@users.noreply.github.com>
2026-03-02 17:40:57 +00:00
Matt Valentine-House 7ca0aa5f73 Copy terminator when moving strings to the heap.
The embedded-to-heap path copied RSTRING_LEN(str) bytes into an
ALLOC_N buffer, missing the null terminator (and any slot padding).
Copy str_embed_capa(str) bytes instead. Always safe since we only
enter this path when str_embed_capa(str) < capacity + termlen.
2026-02-19 22:24:11 +00:00
John Hawthorn e1f49ff79d Don't attempt to convert strings to hashes in gsub 2026-02-18 12:56:04 -08:00
BurdetteLamar f8eed58469 [DOC] Fix links in String 2026-02-06 18:35:02 -05:00
Jean Boussier 44b5971e47 string.c: use ruby_sized_xfree in a few more cases 2026-02-01 12:17:29 +01:00
Peter Zhu 14ccd15156 [DOC] Fix broken links with slash character 2026-01-31 17:52:29 -05:00
Jean Boussier 4292aed14b string.c: Replace ruby_xfree by ruby_sized_xfree 2026-01-31 17:54:33 +01:00
Jean Boussier 91619f0230 gc.c: Verify provided size in rb_gc_impl_free
For now the provided size is just for GC statistics, but in the future
we may want to forward it to C23's `free_sized` and passing an incorrect
size to it is undefined behavior.
2026-01-29 23:32:04 +01:00
Peter Zhu 491e38902c [DOC] Fix links to What's Here
The RDoc link format has changed so these are all broken links.
2026-01-26 17:18:19 -05:00
Jean Boussier 27bb1623cd file.c: Optimize rb_file_dirname_n fixed costs
- `str_null_check` was performed twice, once by `FilePathStringValue`
  and a second time by `StringValueCStr`.
- `StringValueCStr` was checking for the terminator presence, but we
  don't care about that.
- `FilePathStringValue` calls `rb_str_new_frozen` to ensure `fname`
  isn't mutated, but that's costly for such a check. Instead we
  can do it in debug mode only.
- `rb_enc_get` is slow because it accepts arbitrary objects, even immediates,
  so it has to do numerous type checks. Add a much faster `rb_str_enc_get`
  when we know we're dealing with a string.
- `rb_enc_copy` is slow for the same reasons, since we already have the
  encoding, we can use `rb_enc_str_new` instead.
2026-01-20 08:33:42 +01:00
Jean Boussier 7e0e9984d0 rb_file_join_fastpath: optimize searching for separators
`chompdirsep` searches from the start of the string each time, which
perhaps is necessary for certain encodings (not even sure?) but for
the common encodings it's very wasteful. Instead we can start from the
back of the string and only compare one or two characters in most cases.

Also replace `StringValueCStr` for the simpler `rb_str_null_check`
as we only care about whether the string contains `NULL` bytes, we
don't care whether it is NULL terminated or not.

We also only check the final string for NULLs.

```
compare-ruby: ruby 4.1.0dev (2026-01-17T14:40:03Z master 00a3b71eaf) +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-01-18T12:55:15Z spedup-file-join 5948e92e03) +PRISM [arm64-darwin25]
warming up....

|              |compare-ruby|built-ruby|
|:-------------|-----------:|---------:|
|two_strings   |      2.477M|   19.317M|
|              |           -|     7.80x|
|many_strings  |    547.577k|   10.298M|
|              |           -|    18.81x|
|array         |    515.280k|  523.291k|
|              |           -|     1.02x|
|mixed         |    621.840k|  635.422k|
|              |           -|     1.02x|
```
2026-01-18 16:31:31 +01:00
Jean Boussier 6cd4549060 Optimize File.join common use case
`File.join` is a hotspot for common libraries such as Zeitwerk
and Bootsnap. It has a fairly flexible signature, but 99% of
the time it's called with just two (or a small number of) UTF-8 strings.

If we optimistically optimize for that use case we can cut down a large
number of type and encoding checks, significantly speeding up the method.

The one remaining expensive check we could try to optimize is `str_null_check`.
Given it's common to use the same base string for joining, we could memoize it.
Also we could precompute it for literal strings.

```
compare-ruby: ruby 4.1.0dev (2026-01-17T14:40:03Z master 00a3b71eaf) +PRISM [arm64-darwin25]
built-ruby: ruby 4.1.0dev (2026-01-18T12:10:38Z spedup-file-join 069bab58d4) +PRISM [arm64-darwin25]
warming up....

|              |compare-ruby|built-ruby|
|:-------------|-----------:|---------:|
|two_strings   |      2.475M|    9.444M|
|              |           -|     3.82x|
|many_strings  |    551.975k|    2.346M|
|              |           -|     4.25x|
|array         |    514.946k|  522.034k|
|              |           -|     1.01x|
|mixed         |    621.236k|  633.189k|
|              |           -|     1.02x|
```
2026-01-18 16:31:31 +01:00
Nobuyoshi Nakada 78b7646bdb [Bug #21842] Let rb_interned_str return US-ASCII if possible 2026-01-17 14:19:15 +09:00
Nobuyoshi Nakada 8ca2f6489b Revert "Fix rb_interned_str: create strings with BINARY (akak ASCII_8BIT) encoding"
This reverts commit 1f3c52dc15.
2026-01-17 13:38:55 +09:00
Jean Boussier 1f3c52dc15 Fix rb_interned_str: create strings with BINARY (akak ASCII_8BIT) encoding
[Bug #21842]

The documentation always stated as much, and it's consistent with the
rb_str_* family of functions.
2026-01-16 22:44:38 +01:00
Burdette Lamar 3ea6ec8344 [DOC] Harmonize #=~ methods (#15814) 2026-01-07 18:02:22 -05:00
Burdette Lamar 5230f835e8 [DOC] Harmonize #[] methods 2026-01-07 18:01:56 -05:00
Burdette Lamar 58fb95af36 [DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
Peter Zhu 4129256214 Use STR_SET_SHARED in str_duplicate_setup_heap
str_duplicate_setup_heap is missing a call to rb_gc_register_pinning_obj
that STR_SET_SHARED correctly calls.
2025-12-31 21:57:01 -05:00
Peter Zhu 01cd9c9fad Add rb_gc_register_pinning_obj 2025-12-29 09:03:31 -05:00
BurdetteLamar e2243ed232 [DOC] Correct typo 2025-12-20 21:24:37 -05:00
BurdetteLamar addbeb6cf3 [DOC] Note for String#<=> about Comparable 2025-12-20 18:13:08 -05:00
BurdetteLamar b7d4d7c911 [DOC] Harmonize several <=> methods 2025-12-19 21:36:46 -05:00
BurdetteLamar 42c4df9ac6 [DOC] Harmonize String#<=> 2025-12-19 17:09:31 -05:00
Alan Wu d209e6f1c0 search_nonascii(): Replace UB pointer cast with memcpy
Casting a pointer to create an unaligned one is undefined behavior in C
standards. Use memcpy to express the unaligned load instead to play by
the rules.

Practically, this yields the same binary output in many situations
while fixing the crash in [Bug #21715].
2025-12-16 13:06:03 -05:00
Shugo Maeda 71dd272506 Remove useless rb_check_arity() calls 2025-12-13 13:52:13 +09:00
Nobuyoshi Nakada 281a000d66 [Bug #19558] Allow ASCII range to mix with Unicode dump 2025-12-11 19:20:12 +09:00
Shugo MaedaandClaude c76ba839b1 Allow String#strip etc. to take optional character selectors
[Feature #21552]

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-11 17:34:57 +09:00
Hiroshi SHIBATA 79c57d747f Fixed by misspell -w -error -source=text 2025-12-09 17:48:57 +09:00
BurdetteLamar bd64cf00a2 [DOC] Tweaks for String#capitalize 2025-12-05 19:05:55 -08:00
BurdetteLamar 2491a504ff [DOC] Tweaks for String#downcase 2025-12-05 19:05:18 -08:00
BurdetteLamar e5e4175dbd [DOC] Tweaks for String#upcase 2025-12-05 19:04:59 -08:00