summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2026-01-19 07:32:09 +0100
committerJean Boussier <jean.boussier@gmail.com>2026-01-20 08:33:42 +0100
commit27bb1623cd048f3cbfc527cc315894803deabba2 (patch)
treea7bcabe824382632378a07ad099ee1fcae1aa0cc /string.c
parent826dbcfb2be33ffbfbc99554244881e014513d20 (diff)
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.
Diffstat (limited to 'string.c')
-rw-r--r--string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/string.c b/string.c
index 1e0b9929ef..464eab2146 100644
--- a/string.c
+++ b/string.c
@@ -2880,7 +2880,7 @@ str_null_check(VALUE str, int *w)
int minlen = 1;
if (RB_UNLIKELY(!rb_str_enc_fastpath(str))) {
- rb_encoding *enc = rb_enc_get(str);
+ rb_encoding *enc = rb_str_enc_get(str);
minlen = rb_enc_mbminlen(enc);
if (minlen > 1) {