diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-03-16 14:47:22 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-03-16 14:49:51 +0900 |
| commit | 1a8483f17e61cd30651241d8616d5530d88fdf43 (patch) | |
| tree | 06ca47fb38c1e664a94093c38972825abfddfd1d /mrblib/array.rb | |
| parent | 1abff3f2abdde908410175ea191a7c690e91e077 (diff) | |
| download | mruby-1a8483f17e61cd30651241d8616d5530d88fdf43.tar.gz mruby-1a8483f17e61cd30651241d8616d5530d88fdf43.zip | |
`__sort_sub__` is a method defined in `Array`; fix #3970
Reorganize `__sort_sub__` arguments.
Diffstat (limited to 'mrblib/array.rb')
| -rw-r--r-- | mrblib/array.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb index a75ed6223..046397156 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -200,28 +200,27 @@ class Array ## # Quick sort - # a : the array to sort # left : the beginning of sort region # right : the end of sort region - def __sort_sub__(a, left, right, &block) + def __sort_sub__(left, right, &block) if left < right i = left j = right - pivot = a[i + (j - i) / 2] + pivot = self[i + (j - i) / 2] while true - while ((block)? block.call(a[i], pivot): (a[i] <=> pivot)) < 0 + while ((block)? block.call(self[i], pivot): (self[i] <=> pivot)) < 0 i += 1 end - while ((block)? block.call(pivot, a[j]): (pivot <=> a[j])) < 0 + while ((block)? block.call(pivot, self[j]): (pivot <=> self[j])) < 0 j -= 1 end break if (i >= j) - tmp = a[i]; a[i] = a[j]; a[j] = tmp; + tmp = self[i]; self[i] = self[j]; self[j] = tmp; i += 1 j -= 1 end - __sort_sub__(a, left, i-1, &block) - __sort_sub__(a, j+1, right, &block) + __sort_sub__(left, i-1, &block) + __sort_sub__(j+1, right, &block) end end # private :__sort_sub__ @@ -232,7 +231,7 @@ class Array def sort!(&block) size = self.size if size > 1 - __sort_sub__(self, 0, size - 1, &block) + __sort_sub__(0, size - 1, &block) end self end |
