Yukihiro "Matz" Matsumoto
5bd63d6232
array.c: replace sort! method implementation
...
- use heap sort (O(1)) instead of merge sort (O(n)) for better space
complexity.
- method implemented in C for better performance
As a result, simple sorting now consumes far less memory and is faster.
Since it's implemented in C, fiber context switching is not allowed from
comparison, but we consider the risk is minimal (no one switches context
in the comparison, right?)
2024-06-26 11:28:56 +09:00
dearblue
f0cd35c78b
Passes the nonexistent key as a block argument in Array#delete
...
```ruby
a = %w(R G B A)
p a.delete("Y") { _1 }
# BEFORE => nil (same for mruby 3.3)
# AFTER => "Y" (same for CRuby)
```
2024-05-10 22:46:11 +09:00
leviongit
67df0aca67
fix: Array#delete mistakingly calling block even if not passed
2024-05-09 14:33:23 +02:00
leviongit
bb78c2cbc9
reimplement Array#delete with a helper method
2024-04-13 07:41:00 +02:00
leviongit
312d49c59f
reimplement Array#delete in ruby
2024-04-13 07:21:51 +02:00
leviongit
c04afb9e99
revert moving Array#delete to c
2024-04-13 06:52:37 +02:00
leviongit
14bd875d70
fix Array#delete
...
reimplement `Array#delete` in c, fixing `ary.delete(nil, &blk)` firing the block regardless of removal
minimal reproduction:
```rb
ary = [nil]
ret = ary.delete(nil) { "not deleted?" }
```
2024-04-12 17:30:03 +02:00
Yukihiro "Matz" Matsumoto
5cb0c7463b
array.c (mrb_ary_to_s): add recursive check to Array#inspect
2023-06-20 07:06:33 +09:00
Yukihiro "Matz" Matsumoto
6bc44f8aa8
Remove non-existent ISO section numbers suffixed with "(x)" [ci skip]
...
We don't know how we introduced these section references.
Weak memories.
2023-01-08 22:32:16 +09:00
John Bampton
ea8964ef35
ruby: standardize whitespace
2022-10-31 16:25:56 +10:00
John Bampton
44db4f18d3
Remove # coding: utf-8 from Ruby files
...
The default script encoding is Encoding::UTF-8 after v2.0.
https://ruby-doc.org/core-2.1.2/Encoding.html#class-Encoding-label-Script+encoding
2022-10-27 04:43:13 +10:00
Yukihiro "Matz" Matsumoto
01392e2719
mrblib/array.rb: add call-seq to each method description. [ci skip]
2022-06-22 19:02:54 +09:00
Yukihiro "Matz" Matsumoto
91255c7e9f
mrblib/array.rb: Array#<=> to handle NoMethodError exception.
...
Array element may not respond to `<=>` method.
2022-03-26 22:57:41 +09:00
Yukihiro "Matz" Matsumoto
5c7aa4f299
Simplify module inclusion for Array, Hash and Range.
2021-05-13 16:07:09 +09:00
Yukihiro "Matz" Matsumoto
955c7f703e
array.rb: add Array#entries as an alias to Array#to_a.
...
The performance of `Enumerable#entries` are significantly slower than
`Array#to_a`.
2021-05-12 07:17:49 +09:00
John Bampton
4fa3359d44
refactor: remove trailing whitespace from C, Header, Ruby and YAML files
...
Lint
2020-12-15 19:44:02 +10:00
Yukihiro "Matz" Matsumoto
71f9add1c5
Move inline iseq in array.c to array.rb.
...
There's no efficiency difference since `cdump` is implemented.
2020-11-25 23:14:38 +09:00
Yukihiro "Matz" Matsumoto
afba74ff50
Add Array.new([1,2,3]) initialization.
2020-11-05 14:29:25 +09:00
Yukihiro "Matz" Matsumoto
0bb4d10ca7
Define Array#to_a to avoid unnecessary loops.
2020-07-22 14:56:56 +09:00
Yukihiro "Matz" Matsumoto
914da3d712
Small comment fix in mrblib/array.c.
2020-07-22 14:56:36 +09:00
Yukihiro "Matz" Matsumoto
5b1f25a4e0
Implement Array#each using inline mruby bytecode.
2019-08-17 14:46:32 +09:00
Yukihiro "Matz" Matsumoto
d605b72c1d
Merge branch 'master' into i110/inspect-recursion
2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto
af51119d3a
Raise error on failed comparison in sort; ref #4307
2019-03-02 15:46:50 +09:00
Yukihiro "Matz" Matsumoto
afca99a40b
Remove implicit conversion using to_int method.
...
The ISO standard does not include implicit type conversion using
`to_int`. This implicit conversion often causes vulnerability.
There will be no more attacks like #4120 .
In addition, we have added internal convenience method `__to_int` which
does type check and conversion (from floats).
2018-11-19 11:28:51 +09:00
Yukihiro "Matz" Matsumoto
34872e90d4
Re-implement Array#_inspect and Hash#_inspect without blocks.
...
To reduce the env object allocation; ref #4143
2018-10-29 11:55:49 +09:00
Tomoyuki Sahara
91444c4747
replace quicksort with mergesort.
2018-10-18 13:07:47 +09:00
Yukihiro "Matz" Matsumoto
fee9ec61bb
Make Array.new to accept both integers and floats.
...
This time we used `Integral` module which is mruby specific.
2018-08-13 23:15:52 +09:00
Ichito Nagata
2af92d0ebc
Let inspect recursion do the right thing
2018-06-04 11:25:10 +09:00
Tomoyuki Sahara
f0e54df4fe
sort method should not consume system stack.
2018-04-23 12:28:15 +09:00
Yukihiro "Matz" Matsumoto
d88191e7e7
Implement Array#__svalue in C.
2018-04-17 11:32:31 +09:00
Yukihiro "Matz" Matsumoto
1a8483f17e
__sort_sub__ is a method defined in Array; fix #3970
...
Reorganize `__sort_sub__` arguments.
2018-03-16 14:49:51 +09:00
Christopher Aue
c956e17c02
Replaced Array#each with while loop for performance reasons
...
Example benchmark:
$ time build/bench/bin/mruby -e "Array.new(2_000_000){ |i| i }.index{ |i| i == 1_999_999 }"
Before:
real 0m0.934s
user 0m0.922s
sys 0m0.003s
After:
real 0m0.590s
user 0m0.583s
sys 0m0.007s
2017-08-26 15:57:25 +02:00
Christopher Aue
3359b86ec7
Improved speed of enumeration methods
2017-07-30 13:19:31 +02:00
Yukihiro "Matz" Matsumoto
7b8d784040
Reimplement sort method to reduce array copying.
2017-07-25 14:42:38 +09:00
Jun Hiroe
88076901fd
Refactor Array#each
2015-12-26 10:12:01 +09:00
Yusuke Tanaka
d3f59db597
Remove redundant conditions of Array#each in ruby extension
2015-12-15 19:54:29 +09:00
go.kikuta
931a7223e6
array.rb: refactor (use onliner code if possible)
2015-08-21 14:56:49 +09:00
go.kikuta
c326f065e1
array.rb: refactor some code
2015-08-19 16:17:06 +09:00
Franck Verrot
2588507285
Remove unnecessary backticks.
...
Dr Markus Kuhn published in 1999 an article [1] explaining in details
why we shouldn't use the ASCII grave accent (0x60) as a left quotation.
Backticks have been used most notably to produce nice-looking LaTeX
documents but it doesn't seem to be an issue on modern platforms and
for the oldest ones, there are workarounds as mentioned by Dr Kuhn.
[1]: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
2015-06-24 13:07:07 +02:00
Yukihiro "Matz" Matsumoto
b05d736b49
update mrblib/*.rb files to conform (some of) Rubocop checks
2015-05-29 17:01:52 +09:00
Yukihiro "Matz" Matsumoto
79fb18445d
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
2014-07-12 23:22:20 +09:00
mirichi
d2e4937cea
Refactoring Array#__svalue
2014-04-25 21:36:52 +09:00
Yukihiro "Matz" Matsumoto
b4043256d0
implement part of Array#<=> in C
2014-04-02 18:04:09 +09:00
Yukihiro "Matz" Matsumoto
94effc6a37
implement Array comparisons by Ruby
2014-04-02 17:33:25 +09:00
Yukihiro "Matz" Matsumoto
d9feed6703
move Array#inspect implementation to mrblib/array.rb
2014-04-01 14:31:39 +09:00
Yukihiro "Matz" Matsumoto
a85fdbdba4
according to JIS/ISO, Array is not Comparable
2014-03-31 00:50:16 +09:00
Yukihiro "Matz" Matsumoto
027d6407cc
make Enumerable methods to support multiple values; collect, detect, each_with_index, find_all, inject, max, min, partition, reject, sort
2014-03-17 00:53:08 +09:00
Yukihiro "Matz" Matsumoto
ed2fe64076
Enumerable#entries to support multiple values; close #1868
2014-03-17 00:34:47 +09:00
ksss
bc63518fa7
modify core method that return Enumerator object if not block given
2014-03-15 08:15:04 +09:00
Yukihiro "Matz" Matsumoto
113ab60784
mruby-enumerator: move definitions in core_mod.rb to mrblib core
2014-03-14 02:41:22 +09:00