Commit Graph
2097 Commits
Author SHA1 Message Date
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
BurdetteLamar da2c67388a [DOC] Tweaks for String#swapcase 2025-12-05 19:04:23 -08:00
Nobuyoshi Nakada 29a12297c3 Refine non-nil warnings for the deprecated variables 2025-12-05 01:04:08 +09:00
Nobuyoshi Nakada cf12aff059 [Bug #21764] Propagate the encoding of ID to warning 2025-12-05 00:27:45 +09:00
Jean Boussier b78db63be4 fstring_concurrent_set_create: only assert the string has no ivars
The NEWOBJ tracepoint can generate an object_id, that's alright,
what we don't want is actual instance variables.
2025-12-03 15:57:26 +01:00
Jean Boussier 5770c186d1 Rename rb_obj_exivar_p -> rb_obj_gen_fields_p
The "EXIVAR" terminology has been replaced by "gen fields"
AKA "generic fields".

Exivar implies variable, but generic fields include more than
just variables, e.g. `object_id`.
2025-12-03 15:57:26 +01:00
Max Bernstein 8aed311038 ZJIT: Specialize String#<< with Fixnum
Append a codepoint.
2025-12-01 15:19:26 -08:00
Stan Lo 4cd6661e18 Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Burdette Lamar d5368fc515 [DOC] Tweaks for String#valid_encoding? 2025-11-20 17:07:44 -05:00
BurdetteLamar d1b11592af [DOC] Tweaks for String#upto 2025-11-20 14:06:16 -08:00
BurdetteLamar a4a99a24e8 [DOC] TWeaks for String#upcase! 2025-11-20 14:04:22 -08:00
Burdette Lamar 59e0489248 [DOC] Tweaks for String#upcase (#15244) 2025-11-20 17:03:58 -05:00
BurdetteLamar 1443f89d69 [DOC] Tweaks for String#unicode_normalize 2025-11-18 18:57:29 -08:00
Burdette Lamar 319001192d [DOC] Tweaks for String#dump and String#undump 2025-11-18 21:56:14 -05:00
Luke Gruber 371a295e19 Fix improper termlen fill in str_duplicate_setup_embed.
When term len != 1 (for example: Encoding::UTF32BE), term fill is wrong size.
2025-11-18 00:53:47 +09:00
BurdetteLamar 3cd30814d4 [DOC] Tweaks for String#unicode_normalize! 2025-11-16 13:27:06 -08:00
BurdetteLamar 17f3588a43 [DOC] Tweaks for String#unicode_normalized? 2025-11-16 13:26:46 -08:00
BurdetteLamar e826f815bf [DOC] Tweaks for String#tr_s! 2025-11-13 18:28:09 -08:00
BurdetteLamar 6c7453c5de [DOC] Tweaks for String#tr_s 2025-11-13 18:27:43 -08:00
BurdetteLamar 7ea0d36966 [DOC] Tweaks for String#tr! 2025-11-13 18:27:01 -08:00
BurdetteLamar a4916a6f38 [DOC] Tweaks for String#tr 2025-11-12 14:02:07 -08:00
BurdetteLamar c13b4d79e1 [DOC] Tweaks for String#to_s 2025-11-12 14:01:43 -08:00
Burdette Lamar 79eed1158d [DOC] Tweaks for String#to_i (#15036) 2025-11-08 17:27:26 -05:00
John Hawthorn 3b588dab91 Don't modify fstrings in rb_str_tmp_frozen_no_embed_acquire
[Bug #21671]
2025-11-07 17:06:56 -08:00
BurdetteLamar 4a3d8346a6 [DOC] Tweaks for String#to_f 2025-11-02 13:44:11 -05:00
Peter Zhu 37c7153668 Make rb_str_embed_size aware of termlen 2025-11-02 09:17:17 -05:00
Peter Zhu dba4c9fbe7 Fix string allocation when slot size < 40 bytes
We need to allocate at least sizeof(struct RString) when the string is
embedded on garbage collectors that support slot sizes less than 40 bytes.
2025-11-02 09:17:17 -05:00