Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arr.sortを非同期処理に変更 #633

Merged
merged 7 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 未リリース分
- `Date:year`系の関数に0を渡すと現在時刻になる問題を修正
- シンタックスエラーなどの位置情報を修正
- `arr.sort`の処理を非同期的にして高速化

# 0.18.0
- `Core:abort`でプログラムを緊急停止できるように
Expand Down
5 changes: 3 additions & 2 deletions src/interpreter/primitive-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
split: (target: VStr): VFn => FN_NATIVE(async ([splitter], _opts) => {
if (splitter) assertString(splitter);
if (splitter) {
return ARR(target.value.split(splitter ? splitter.value : '').map(s => STR(s)));

Check warning on line 89 in src/interpreter/primitive-props.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy
} else {
return ARR(toArray(target.value).map(s => STR(s)));
}
Expand Down Expand Up @@ -231,8 +231,9 @@
const mergeSort = async (arr: Value[], comp: VFn): Promise<Value[]> => {
if (arr.length <= 1) return arr;
const mid = Math.floor(arr.length / 2);
const left = await mergeSort(arr.slice(0, mid), comp);
const right = await mergeSort(arr.slice(mid), comp);
const left_promise = mergeSort(arr.slice(0, mid), comp);
const right_promise = mergeSort(arr.slice(mid), comp);
const [left, right] = await Promise.all([left_promise, right_promise]);
return merge(left, right, comp);
};
const merge = async (left: Value[], right: Value[], comp: VFn): Promise<Value[]> => {
Expand Down
Loading