mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Add a fastpath for rb_str_normalize_ospath
This extra check is a hotspot for path operations on
macOS.
It was added in 9962aad7b0
because of a limitation of HFS+.
But all the invalid characters are outside of ASCII range,
and most paths are ASCII, so we can optimistically check
the coderange instead.
Most `rb_str_normalize_ospath` were first checking for ASCII
range, but a few like `rb_dir_getwd_ospath` in `dir.c` or
`ospath_new` in `file.c` didn't.
This commit is contained in:
1 parent
36b0ae025a
commit
b154cfa98c
1 file changed
+8
-2
Notes:
git
2026-04-10 07:56:47 +00:00
@@ -380,9 +380,15 @@ rb_str_normalize_ospath(const char *ptr, long len)
|
||||
const char *p = ptr;
|
||||
const char *e = ptr + len;
|
||||
const char *p1 = p;
|
||||
VALUE str = rb_str_buf_new(len);
|
||||
rb_encoding *enc = rb_utf8_encoding();
|
||||
rb_enc_associate(str, enc);
|
||||
VALUE str = rb_utf8_str_new(ptr, len);
|
||||
if (RB_LIKELY(rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)) {
|
||||
return str;
|
||||
}
|
||||
else {
|
||||
str = rb_str_buf_new(len);
|
||||
rb_enc_associate(str, enc);
|
||||
}
|
||||
|
||||
while (p < e) {
|
||||
int l, c;
|
||||
|
||||
Reference in new issue
Block a user