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
2 changes: 1 addition & 1 deletion .github/workflows/pr-playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
&& github.event.workflow_run.event == 'pull_request')
}}
steps:
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zjit-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
rustup install ${{ matrix.rust_version }} --profile minimal
rustup default ${{ matrix.rust_version }}
- uses: taiki-e/install-action@80e6af7a2ec7f280fffe2d0a9d3a12a9d11d86e9 # v2.75.1
- uses: taiki-e/install-action@b8be7f5e140177087325943c4a8e169d01c59b3d # v2.75.3
with:
tool: nextest@0.9
if: ${{ matrix.test_task == 'zjit-check' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zjit-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
ruby-version: '3.1'
bundler: none

- uses: taiki-e/install-action@80e6af7a2ec7f280fffe2d0a9d3a12a9d11d86e9 # v2.75.1
- uses: taiki-e/install-action@b8be7f5e140177087325943c4a8e169d01c59b3d # v2.75.3
with:
tool: nextest@0.9
if: ${{ matrix.test_task == 'zjit-check' }}
Expand Down
4 changes: 4 additions & 0 deletions benchmark/file_expand_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prelude: |
# frozen_string_literal: true
benchmark:
expand_path: File.expand_path("../../foo.txt", __FILE__)
29 changes: 20 additions & 9 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3707,8 +3707,9 @@ skipprefixroot(const char *path, const char *end, rb_encoding *enc)
#endif
}

char *
rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)

static char *
enc_path_last_separator(const char *path, const char *end, bool mb_enc, rb_encoding *enc)
{
char *last = NULL;
while (path < end) {
Expand All @@ -3719,17 +3720,22 @@ rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
last = (char *)tmp;
}
else {
Inc(path, end, true, enc);
Inc(path, end, mb_enc, enc);
}
}
return last;
}
char *
rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
{
return enc_path_last_separator(path, end, true, enc);
}

static inline char *
strrdirsep(const char *path, const char *end, bool mb_enc, rb_encoding *enc)
{
if (RB_UNLIKELY(mb_enc)) {
return rb_enc_path_last_separator(path, end, enc);
return enc_path_last_separator(path, end, mb_enc, enc);
}

const char *cursor = end - 1;
Expand Down Expand Up @@ -4021,7 +4027,12 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na

s = StringValuePtr(fname);
fend = s + RSTRING_LEN(fname);
enc = rb_enc_get(fname);
enc = rb_str_enc_get(fname);
bool mb_enc = !rb_str_encindex_fastpath(rb_enc_to_index(enc));
if (!mb_enc && RTEST(dname)) {
mb_enc = !rb_str_encindex_fastpath(rb_enc_to_index(rb_str_enc_get(dname)));
}

BUFINIT();

if (s < fend && s[0] == '~' && abs_mode == 0) { /* execute only if NOT absolute_path() */
Expand Down Expand Up @@ -4115,7 +4126,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
else
#endif /* defined DOSISH || defined __CYGWIN__ */
p = chompdirsep(skiproot(buf, p), p, true, enc);
p = chompdirsep(skiproot(buf, p), p, mb_enc, enc);
}
else {
size_t len;
Expand All @@ -4139,7 +4150,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
rb_str_set_len(result, p-buf+1);
BUFCHECK(bdiff + 1 >= buflen);
p[1] = 0;
root = skipprefix(buf, p+1, true, enc);
root = skipprefix(buf, p+1, mb_enc, enc);

b = s;
while (s < fend) {
Expand All @@ -4156,7 +4167,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
/* We must go back to the parent */
char *n;
*p = '\0';
if (!(n = strrdirsep(root, p, true, enc))) {
if (!(n = strrdirsep(root, p, mb_enc, enc))) {
*p = '/';
}
else {
Expand Down Expand Up @@ -4219,7 +4230,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
}
#endif /* __APPLE__ */
Inc(s, fend, true, enc);
Inc(s, fend, mb_enc, enc);
break;
}
}
Expand Down