summaryrefslogtreecommitdiff
path: root/enumerator.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix ArithmeticSequence#last and ArithmeticSequence#each for non-integer ↵Kenta Murata2020-12-091-8/+91
| | | | | | sequences (#3870) [Bug #17218] [ruby-core:100312]
* Removed more unnecessary ID cachesNobuyoshi Nakada2020-10-211-53/+54
| | | | | | | | | | ``` find . -name \*.o -exec nm {} + |& grep -e 'InitVM_.*\.rbimpl_id' -e 'Init_.*\.rbimpl_id' | sed 's/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' | uniq ``` should be empty.
* Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)Kenta Murata2020-10-211-4/+40
| | | | | | | | | | | | | | | | | * Support ArithmeticSequence in Array#slice * Extract rb_range_component_beg_len * Use rb_range_values to check Range object * Fix ary_make_partial_step * Fix for negative step cases * range.c: Describe the role of err argument in rb_range_component_beg_len * Raise a RangeError when an arithmetic sequence refers the outside of an array [Feature #16812]
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-1/+2
| | | | | | RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
* Improved Enumerable::Lazy#zipNobuyoshi Nakada2020-07-231-42/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |compare-ruby|built-ruby| |:-------------------|-----------:|---------:| |first_ary | 290.514k| 296.331k| | | -| 1.02x| |first_nonary | 166.954k| 169.178k| | | -| 1.01x| |first_noarg | 299.547k| 305.358k| | | -| 1.02x| |take3_ary | 129.388k| 188.360k| | | -| 1.46x| |take3_nonary | 90.684k| 112.688k| | | -| 1.24x| |take3_noarg | 131.940k| 189.471k| | | -| 1.44x| |chain-first_ary | 195.913k| 286.194k| | | -| 1.46x| |chain-first_nonary | 127.483k| 168.716k| | | -| 1.32x| |chain-first_noarg | 201.252k| 298.562k| | | -| 1.48x| |chain-take3_ary | 101.189k| 183.188k| | | -| 1.81x| |chain-take3_nonary | 75.381k| 112.301k| | | -| 1.49x| |chain-take3_noarg | 101.483k| 192.148k| | | -| 1.89x| |block | 296.696k| 292.877k| | | 1.01x| -|
* Improved Enumerable::Lazy#flat_mapNobuyoshi Nakada2020-07-231-42/+40
| | | | | | | | | | | | | | | | | | | | |compare-ruby|built-ruby| |:-------|-----------:|---------:| |num3 | 96.333k| 160.732k| | | -| 1.67x| |num10 | 96.615k| 159.150k| | | -| 1.65x| |ary2 | 103.836k| 172.787k| | | -| 1.66x| |ary10 | 109.249k| 177.252k| | | -| 1.62x| |ary20 | 106.628k| 177.371k| | | -| 1.66x| |ary50 | 107.135k| 162.282k| | | -| 1.51x| |ary100 | 106.513k| 177.626k| | | -| 1.67x|
* New functions to pass more elements than passedNobuyoshi Nakada2020-07-231-4/+26
|
* Update Enumerable::Yielder#to_proc document (#3142)Masataka Pocke Kuwabara2020-05-261-1/+1
|
* Fix non-existent method reference in Enumerator.produce document (#3141)Masataka Pocke Kuwabara2020-05-261-1/+1
|
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-3/+7
|
* Improve documentation for Enumerator#next, next_values, peek and peek_values.Marc-Andre Lafortune2020-05-051-7/+15
| | | | [DOC] [#16829]
* [ci skip] Enumerator doc cleanupgerero202020-04-111-3/+3
| | | | | | This is my first attempt at a pull request. I was reading the ruby docs the other day and noticed that the output didn't match the code sample on the with_object documentation. Inserted spaces to fix it.
* Suppress C4244 "possible loss of data" warningsNobuyoshi Nakada2020-04-081-1/+1
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-1/+1
| | | Split ruby.h
* Removed duplicated codeNobuyoshi Nakada2020-02-091-30/+1
|
* Fully separate positional arguments and keyword argumentsJeremy Evans2020-01-021-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p().
* decouple internal.h headers卜部昌平2019-12-261-3/+11
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* [DOC] Improve docs for Enumerator.produce, Enumerator.newMarcus Stollsteimer2019-12-241-14/+12
|
* Fix typos of previous docs PRzverok2019-12-231-1/+1
| | | | | | In #2612 I made two typos (extra ,, and copy-pasted same line of code instead of showing two different ones), fixing them.
* Some fixes in Enumerator::Lazy docsMarcus Stollsteimer2019-12-221-23/+24
| | | | | | * fix list in #flat_map * fix wrong indentation in #filter_map and #with_index * other small fixes
* Added rb_warn_deprecatedNobuyoshi Nakada2019-12-191-1/+1
|
* Fix Enumerator::Lazy#with_indexJeremy Evans2019-12-111-65/+56
| | | | | | | | | | | | | | | | * Make it correctly handle lambdas * Make it iterate over the block if block is given The original implementation was flawed, based on lazy_set_method instead of lazy_add_method. Note that there is no implicit map when passing a block, the return value of the block passed to with_index is ignored, just as it is for Enumerator#with_index. Also like Enumerator#with_index, when called with a block, the return value is an enumerator without the index. Fixes [Bug #16414]
* Make Enumerator::Chain#each treat lambdas as lambdaJeremy Evans2019-12-031-8/+1
| | | | | | | | Previously, lambdas were converted to procs because of how rb_block_call works. Switch to rb_funcall_with_block, which handles procs as procs and lambdas as lambdas. Fixes [Bug #15613]
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-3/+0
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Right size the Enumerator internal lazy_use_super_method hashLourens Naudé2019-10-291-1/+1
|
* Improve Enumerator.produce docszverok2019-10-271-0/+15
| | | | | * Add to NEWS; * Add examples of while-alike cycles with practical tasks.
* Documentation improvements for Ruby corezverok2019-10-261-1/+7
| | | | | | | | | | | * Top-level `return`; * Documentation for comments syntax; * `rescue` inside blocks; * Enhance `Object#to_enum` docs; * Make `chomp:` option more obvious for `String#each_line` and `#lines`; * Enhance `Proc#>>` and `#<<` docs; * Enhance `Processs` class docs.
* Add rb_enumeratorize_with_size_kw and related macrosJeremy Evans2019-09-301-7/+19
| | | | | | | | | | Currently, there is not a way to create a sized enumerator in C with a different set of arguments than provided by Ruby, and correctly handle keyword arguments. This function allows that. The need for this is fairly uncommon, but it occurs at least in Enumerator.produce, which takes arugments from Ruby but calls rb_enumeratorize_with_size with a different set of arguments.
* Fix more keyword separation issuesJeremy Evans2019-09-261-2/+2
| | | | | | | | | | | | | | | | | | | | | This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block
* Fix keyword argument separation issues in Enumerator::Generator#eachJeremy Evans2019-09-261-1/+1
| | | | This requires adding rb_proc_call_kw to pass the keyword flag.
* Handle keyword argument separation for Enumerator#sizeJeremy Evans2019-09-201-1/+1
| | | | | | | | | When Object#to_enum is passed a block, the block is called to get a size with the arguments given to to_enum. This calls the block with the same keyword flag as to_enum is called with. This requires adding rb_check_funcall_kw and rb_check_funcall_default_kw to handle keyword flags.
* Consolidate empty keyword handlingJeremy Evans2019-09-131-8/+2
| | | | | | | | | | | | | | | | | | | | | | Remove rb_add_empty_keyword, and instead of calling that every place you need to add empty keyword hashes, run that code in a single static function in vm_eval.c. Add 4 defines to include/ruby/ruby.h, these are to be used as int kw_splat values when calling the various rb_*_kw functions: RB_NO_KEYWORDS :: Do not pass keywords RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was called with (for method delegation) rb_empty_keyword_given_p needs to stay. It is required if argument delegation is done but delayed to a later point, which Enumerator does. Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly delegate keyword arguments to super method.
* Document and test Enumerator.produceAkinori MUSHA2019-09-121-0/+22
| | | | Co-authored-by: Victor Shepelev <zverok.offline@gmail.com>
* Implement Enumerator.produce [Feature #14781]Akinori MUSHA2019-09-121-1/+156
|
* Fix keyword argument separation warnings for enumeratorsJeremy Evans2019-09-061-9/+21
| | | | | | | | | | This makes objects created via #to_enum and related methods pass keyword arguments as keywords. To implement this, add a kw_splat member of struct enumerator and struct iter_method_arg, and add rb_block_call_kw, which is the same as rb_block_call_kw with a flag for whether the last argument is keyword options.
* Describe #eager in the Enumerator::Lazy sectionAkinori MUSHA2019-09-041-6/+25
|
* Implement Enumerator::Lazy#eager [Feature #15901]Akinori MUSHA2019-09-041-0/+21
|
* Fix Enumerator::Lazy#{to_enum,enum_for} where method is defined in LazyJeremy Evans2019-09-031-1/+68
| | | | | | | | | | | | | | | | | | | Previously, passing to_enum/enum_for a method that was defined in Lazy itself returned wrong results: [1,2,3].to_enum(:map).to_a # => [1, 2, 3] [1,2,3].lazy.to_enum(:map).to_a # => [] I'm not sure why methods that are designed to be lazy do not work with to_enum/enum_for. However, one possible way to work around this bug is to have to_enum/enum_for use the implementation found in Enumerable/Enumerator, which is what this commit does. While this commit works around the problem, it is a band-aid, not a real fix. It doesn't handle aliases of Enumerable::Lazy methods, for instance. A better fix would be appreciated.
* Make Enumerator::Lazy#with_index be lazyJeremy Evans2019-09-031-0/+66
| | | | | | | | | | Previously, Enumerator::Lazy#with_index was not defined, so it picked up the default implementation from Enumerator, which was not lazy. Based on earlier patch from nobu. Fixes [Bug #7877]
* Revert "Make Enumerator::Lazy#with_index be lazy"Jeremy Evans2019-09-011-66/+0
| | | | | | This reverts commit 83498854eb5a824f1f83c31fac18c9279f9ee10d. This didn't pass rubyspec.
* Make Enumerator::Lazy#with_index be lazyJeremy Evans2019-09-011-0/+66
| | | | | | | | | | Previously, Enumerator::Lazy#with_index was not defined, so it picked up the default implementation from Enumerator, which was not lazy. Based on earlier patch from nobu. Fixes [Bug #7877]
* rb_proc_new / rb_fiber_new now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST wherever necessary.
* rb_rescue / rb_rescue2 now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
* #define RB_BLOCK_CALL_FUNC_STRICT 1卜部昌平2019-08-271-3/+3
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. Let's start from making rb_block_call_func_t strict, and apply RB_BLOCK_CALL_FUNC_ARGLIST liberally.
* Minor documentation fixes [ci skip]Jeremy Evans2019-08-241-4/+4
| | | | | | From zverok (Victor Shepelev) Fixes [Misc #16126]
* * expand tabs.git2019-08-131-4/+4
|
* Add compaction callbacks for EnumeratorAaron Patterson2019-08-131-15/+65
| | | | This commit gives Enumerator compaction support
* Use predefined idTo_procNobuyoshi Nakada2019-08-011-3/+2
|