aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
Commit message (Collapse)AuthorAgeFilesLines
* Improve performance of implicit type conversionwatson19782017-05-311-21/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To convert the object implicitly, it has had two parts in convert_type() which are 1. lookink up the method's id 2. calling the method Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up the method's id for type conversion. This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id) to call the method without looking up the method's id when convert the object. Array#flatten -> 19 % up Array#+ -> 3 % up [ruby-dev:50024] [Bug #13341] [Fix GH-1537] ### Before Array#flatten 104.119k (± 1.1%) i/s - 525.690k in 5.049517s Array#+ 1.993M (± 1.8%) i/s - 10.010M in 5.024258s ### After Array#flatten 124.005k (± 1.0%) i/s - 624.240k in 5.034477s Array#+ 2.058M (± 4.8%) i/s - 10.302M in 5.019328s ### Test Code require 'benchmark/ips' class Foo def to_ary [1,2,3] end end Benchmark.ips do |x| ary = [] 100.times { |i| ary << i } array = [ary] x.report "Array#flatten" do |i| i.times { array.flatten } end x.report "Array#+" do |i| obj = Foo.new i.times { array + obj } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: improve docsstomar2017-05-301-12/+13
| | | | | | | | | | | * object.c: [DOC] add an example for Object#yield_self that better illustrates its purpose; other small improvements. Reported by Vitaly Tatarintsev (ck3g). Patch by Marcus Stollsteimer. [Fix GH-1637] * object.c: [DOC] improve docs for Object#{itself,tap}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of rb_eql()watson19782017-05-251-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improvement is similar with https://github.com/ruby/ruby/pull/1552 internal.h: add declaration of rb_eql_opt() API. vm_insnhelper.c (rb_eql_opt): add rb_eql_opt() API which provides optimized path for #eql? method such as rb_equal_opt(). object.c (rb_eql): optimize using rb_eql_opt() such as rb_equal(). Array#eql? and some methods have used rb_eql() and Array#eql? will be faster around 20%. [ruby-core:80761] [Bug #13447] [Fix GH-#1589] ### Before user system total real 1.570000 0.000000 1.570000 ( 1.569754) ### After user system total real 1.300000 0.000000 1.300000 ( 1.303624) ### Test code require 'benchmark' Benchmark.bmbm do |x| ary1 = Array.new(1000) { rand(1000) } ary2 = Array.new(1000) { rand(1000) } x.report do 5000000.times do ary1.eql?(ary2) end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of rb_equal()watson19782017-05-251-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * object.c (rb_equal): add optimized path to compare the objects using rb_equal_opt(). Previously, if not same objects were given, rb_equal() would call `==' method via rb_funcall() which took a long time. rb_equal_opt() has provided faster comparing for Fixnum/Float/String objects. Now, Time#eql? uses rb_equal() to compare with argument object and it will be faster around 40% on 64-bit environment. * array.c (rb_ary_index): remove redundant rb_equal_opt() calling. Now, rb_equal() was optimized using rb_equal_opt(). If rb_equal_opt() returns Qundef, it will invoke rb_equal() -> rb_equal_opt(), and it will cause the performance regression. So, this patch will remove first redundant rb_equal_opt() calling. * array.c (rb_ary_rindex): ditto. * array.c (rb_ary_includes): ditto. [ruby-core:80360] [Bug #13365] [Fix GH-#1552] ### Before Time#eql? with other 7.309M (± 1.4%) i/s - 36.647M in 5.014964s Array#index(val) 1.433M (± 1.2%) i/s - 7.207M in 5.030942s Array#rindex(val) 1.418M (± 1.6%) i/s - 7.103M in 5.009164s Array#include?(val) 1.451M (± 0.9%) i/s - 7.295M in 5.026392s ### After Time#eql? with other 10.321M (± 1.9%) i/s - 51.684M in 5.009203s Array#index(val) 1.474M (± 0.9%) i/s - 7.433M in 5.044384s Array#rindex(val) 1.449M (± 1.7%) i/s - 7.292M in 5.034436s Array#include?(val) 1.466M (± 1.7%) i/s - 7.373M in 5.030047s ### Test code require 'benchmark/ips' Benchmark.ips do |x| t1 = Time.now t2 = Time.now x.report "Time#eql? with other" do |i| i.times { t1.eql?(t2) } end # Benchmarks to check whether it didn't introduce the regression obj = Object.new x.report "Array#index(val)" do |i| ary = [1, 2, true, false, obj] i.times { ary.index(obj) } end x.report "Array#rindex(val)" do |i| ary = [1, 2, true, false, obj].reverse i.times { ary.rindex(obj) } end x.report "Array#include?(val)" do |i| ary = [1, 2, true, false, obj] i.times { ary.include?(obj) } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: use a sized enumerator with #yield_selfnobu2017-05-141-1/+7
| | | | | | | | | | * object.c (rb_obj_size): The #yield_self Enumerator instance always has a #count of `1`. This provides a lazy #size of `1` to match the count instead of `nil`. [Fix GH-1615] Author: Shannon Skipper <shannonskipper@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: rb_raise_staticnobu2017-05-021-3/+3
| | | | | | | * internal.h (rb_raise_static): raise with a static message string literal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: Kernel#yield_selfnobu2017-05-011-0/+18
| | | | | | | | * object.c (rb_obj_yield_self): new method which yields the receiver and returns the result. [ruby-core:46320] [Feature #6721] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of type conversion using to_rmrkn2017-04-141-0/+1
| | | | | | | | | | | | | | | | * object.c: Add to_r in conv_method_tbl. * defs/id.def: add to_r. * benchmark/bm_int_quo.rb: added. * benchmark/bm_time_subsec.rb: added. [Bug #13426] [ruby-core:80665] [Fix GH-1582] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: make String#to_f consistent with literalnobu2017-03-151-9/+4
| | | | | | | | | | * object.c (rb_cstr_to_dbl): stop at successive underscores, as well as Float literals. [ruby-core:80098] [Bug #13105] * `_` should be within digits * only one `_` allowed between digits git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: [DOC] simplify Object#tap examplestomar2017-03-091-5/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei2017-03-091-1/+4
| | | | | | | | | This commit is auto-generated using following command: svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* optimize FIXABLE macroshyouhei2017-03-061-4/+1
| | | | | | | | | | | | Looking at the source code, FIXABLE tends to be just before LOING2FIX to check applicability of that operation. Why not try computing first then check for overflow, which should be optimial. I also tried the same thing for unsigned types but resulted in slower execution. It seems RB_POSFIXABLE() is fast enough on modern CPUs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: Numeric#clone and #dupnobu2017-02-221-0/+10
| | | | | | | | | | | * numeric.c (num_clone, num_dup): no longer raises TypeError, returns the receiver instead as well as Integer and Float. [ruby-core:79636] [Bug #13237] * object.c (rb_immutable_obj_clone): immutable object clone with freeze optional keyword argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: refactor rb_obj_clone and rb_obj_clone2nobu2017-02-221-15/+36
| | | | | | | | | | * object.c (rb_obj_clone2): extract option for clone, and split by whether the object is immutable or mutable. * object.c (rb_obj_clone): no arguments, return immutable object immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: message encodingnobu2017-02-211-3/+4
| | | | | | * object.c (rb_obj_clone2): preserve encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: no TypeError at Symbolnobu2017-01-231-0/+1
| | | | | | | | * object.c (special_object_p): uninterned Symbol also should not raise a TypeError but return itself instead, as well as interned Symbols. [ruby-core:79216] [Bug #13145] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: rb_class_allocnobu2017-01-021-4/+11
| | | | | | | | * object.c (rb_obj_alloc): add pathological check of klass for extension libraries which do not check given arguments properly. [ruby-core:78934] [Bug #13093] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: rb_class_s_newnobu2017-01-021-3/+10
| | | | | | | | * object.c (rb_class_new_instance): add pathological check of klass for extension libraries which do not check given arguments properly. [ruby-core:78934] [Bug #13093] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: no TypeError at special constnobu2016-11-291-2/+15
| | | | | | | * object.c (special_object_p): no longer raise a TypeError for Integer and Float, and return itself instead. [Feature#12979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: no TypeError at special const clonenobu2016-11-291-1/+3
| | | | | | | | * object.c (rb_obj_clone2): no longer raise a TypeError for special constants, and return itself instead. however, if freeze option is false, raise an ArgumentError. [Feature#12979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: no TypeError at special const dupnobu2016-11-271-1/+1
| | | | | | | * object.c (rb_obj_dup): no longer raise a TypeError for special constants, and return itself instead. [Feature#12979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: fixable float to fixnumnobu2016-10-271-18/+11
| | | | | | | | * object.c (rb_convert_to_integer): convert a fixable float to a fixnum directly without the convesion method, as well as bignum case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: use converted stringnobu2016-10-271-2/+1
| | | | | | | * object.c (rb_convert_to_integer): should not drop the converted string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] replace Fixnum with Integer [ci skip]nobu2016-10-261-7/+7
| | | | | | * numeric.c: [DOC] update document for Integer class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * object.c: Improve documentation for Integer conversion.hsbt2016-10-141-3/+6
| | | | | | [ruby-core:71661][Bug #11736][ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * basictest/test.rb: Adjust spaces in class declarationshsbt2016-10-071-4/+4
| | | | | | | | | | | | with inheritance. [fix GH-1227] Patch by @adrfer * lib/irb/*: ditto. * lib/prime.rb: ditto. * lib/shell/builtin-command.rb: ditto. * object.c: ditto. * sample/*.rb: ditto. * test/-ext-/method/test_arity.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: update rdocnobu2016-09-091-11/+6
| | | | | | | * object.c (InitVM_Object): update rdoc of NIL/TRUE/FALSE, and use rb_deprecate_constant. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* replace fixnum by integer in documents.akr2016-09-081-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: fix {Module,Class}.new rdoc [ci skip]nobu2016-08-241-2/+2
| | | | | | | | | | * object.c (rb_mod_initialize, rb_class_initialize): [DOC] these methods do not invoke module_eval/class_eval, just eval the given block under the new module/class but sharing the context with the surrounding scope like those methods. [ruby-core:77023] [Bug #12696] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * object.c (InitVM_Object): Update referenced document path.kou2016-08-141-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* deprecate TRUE,FALSE,NILnobu2016-08-071-0/+8
| | | | | | | * object.c (InitVM_Object): deprecate toplevel constants TRUE, FALSE, and NIL. [Feature #12574] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: restrict freeze optionnobu2016-08-031-0/+4
| | | | | | | * object.c (rb_obj_clone2): restrict freeze option to true other than false which only has the effect. [Feature #12300] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: suppress warningnobu2016-08-031-2/+1
| | | | | | | * object.c (rb_obj_clone2): remove set but not used variable to suppress unused-but-set-variable warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Object#clone with freeze: false [Feature #12300]shyouhei2016-08-011-6/+30
| | | | | | | | | | | | * object.c (rb_obj_clone2): Allow Object#clone to take freeze: false keyword argument to not freeze the clone. [ruby-core:75017][Feature #12300] * test/ruby/test_object.rb (TestObject): test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix typo [ci skip]nobu2016-06-281-1/+1
| | | | | | * object.c (rb_mod_eqq): [DOC] Fix typo in RDoc. [Fix GH-1393] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use Integer instead of Fixnum and Bignum.akr2016-05-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | * object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c, lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb, lib/rubygems/specification.rb, lib/uri/generic.rb, bootstraptest/test_eval.rb, basictest/test.rb, test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb, test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb, test/csv/test_data_converters.rb, test/date/test_date.rb, test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb, test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb, test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb, test/ruby/test_bignum.rb, test/ruby/test_case.rb, test/ruby/test_class.rb, test/ruby/test_complex.rb, test/ruby/test_enum.rb, test/ruby/test_eval.rb, test/ruby/test_iseq.rb, test/ruby/test_literal.rb, test/ruby/test_math.rb, test/ruby/test_module.rb, test/ruby/test_numeric.rb, test/ruby/test_range.rb, test/ruby/test_rational.rb, test/ruby/test_refinement.rb, test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb, test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb, test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * variable.c: use uint32_t instead of long to avoid confusion aboutnaruse2016-04-221-1/+1
| | | | | | the type of ivtbl->numiv. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: fix error messagenobu2016-02-191-1/+1
| | | | | | | * object.c (rb_mod_const_get): make error message at uninterned string consistent with symbols. [ruby-dev:49498] [Bug #12089] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* resolve class name earlier and more consistentlynormal2016-01-121-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | | This further avoids class name resolution issues which came about due to relying on hash table ordering before r53376. Pre-caching the class name when it is never used raises memory use, but the overall gain from moving away from st still gives us a small gain. Reverting r53376 and this patch and testing with "valgrind -v ./ruby -rrdoc -eexit" on x86 (32-bit) shows: before: in use at exit: 1,662,239 bytes in 25,286 blocks total heap usage: 49,514 allocs, 24,228 frees, 6,005,561 bytes allocated after, with this change: in use at exit: 1,646,529 bytes in 24,572 blocks total heap usage: 48,891 allocs, 24,319 frees, 6,003,921 bytes allocated * class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP * object.c (rb_mod_const_set): move name resolution to rb_const_set * variable.c (rb_const_set): do class resolution here [ruby-core:72807] [Bug #11977] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: fix prepend cmpnobu2015-12-301-5/+2
| | | | | | | | * object.c (rb_class_inherited_p): search the corresponding ancestor to prepended module from prepending class itself. [ruby-core:72493] [Bug #11878] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use id_table for constant tablesnormal2015-12-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | valgrind 3.9.0 on x86-64 reports a minor reduction in memory usage when loading only RubyGems and RDoc by running: ruby -rrdoc -eexit before: HEAP SUMMARY: in use at exit: 2,913,448 bytes in 27,394 blocks total heap usage: 48,362 allocs, 20,968 frees, 9,034,621 bytes alloc after: HEAP SUMMARY: in use at exit: 2,880,056 bytes in 26,712 blocks total heap usage: 47,791 allocs, 21,079 frees, 9,046,507 bytes alloc * class.c (struct clone_const_arg): adjust for id_table (clone_const): ditto (clone_const_i): ditto (rb_mod_init_copy): ditto (rb_singleton_class_clone_and_attach): ditto (rb_include_class_new): ditto (include_modules_at): ditto * constant.h (rb_free_const_table): ditto * gc.c (free_const_entry_i): ditto (rb_free_const_table): ditto (obj_memsize_of): ditto (mark_const_entry_i): ditto (mark_const_tbl): ditto * internal.h (struct rb_classext_struct): ditto * object.c (rb_mod_const_set): resolve class name on assignment * variable.c (const_update): replace with const_tbl_update (const_tbl_update): new function (fc_i): adjust for id_table (find_class_path): ditto (autoload_const_set): st_update => const_tbl_update (rb_const_remove): adjust for id_table (sv_i): ditto (rb_local_constants_i): ditto (rb_local_constants): ditto (rb_mod_const_at): ditto (rb_mod_const_set): ditto (rb_const_lookup): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * object.c (rb_inspect): check the default internal encoding asshugo2015-12-131-6/+7
| | | | | | | | String#inspect do. [ruby-dev:49415] [Bug #11787] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* object.c: raise TypeErrornobu2015-12-121-1/+12
| | | | | | | * object.c (rb_obj_dig): raise TypeError if an element does not have #dig method. [ruby-core:71798] [Bug #11762] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * object.c (rb_inspect): dump inspected result with rb_str_escape()naruse2015-12-101-2/+3
| | | | | | | | | | instead of raising Encoding::CompatibilityError. [Feature #11801] * string.c (rb_str_escape): added to dump given string like rb_str_inspect without quotes and always dump in US-ASCII like rb_str_dump. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile optimized case dispatch for nil/true/falsenormal2015-12-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | nil/true/false are special literals just like floats, integers, literal strings, and symbols. Optimize when statements with them by using a jump table, too. target 0: a (ruby 2.3.0dev (2015-12-08 trunk 52928) [x86_64-linux]) at "/home/ew/rrrr/b/ruby" target 1: b (ruby 2.3.0dev (2015-12-08 master 52928) [x86_64-linux]) at "/home/ew/ruby/b/ruby" benchmark results: minimum results in each 5 measurements. Execution time (sec) name a b loop_whileloop2 0.102 0.103 vm2_case_lit* 1.657 0.549 Speedup ratio: compare with the result of `a' (greater is better) name b loop_whileloop2 0.988 vm2_case_lit* 3.017 * benchmark/bm_vm2_case_lit.rb: new benchmark * compile.c (case_when_optimizable_literal): add nil/true/false * insns.def (opt_case_dispatch): ditto * vm.c (vm_redefinition_check_flag): ditto * vm.c (vm_init_redefined_flag): ditto * vm_core.h: ditto * object.c (InitVM_Object): define === explicitly for nil/true/false * test/ruby/test_case.rb (test_deoptimize_nil): new test * test/ruby/test_optimization.rb (test_opt_case_dispatch): update (test_eqq): new test [ruby-core:71923] [Feature #11769] Original patch by Aaron Patterson <tenderlove@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* encoding.c: defer finding encodingnobu2015-12-021-2/+8
| | | | | | | | | | | | | * encoding.c (enc_m_loader): defer finding encoding object not to be infected by marshal source. [ruby-core:71793] [Bug #11760] * marshal.c (r_object0): enable compatible loader on USERDEF class. the loader function is called with the class itself, instead of an allocated object, and the loaded data. * marshal.c (compat_allocator_table): intialize compat_allocator_tbl on demand. * object.c (rb_undefined_alloc): extract from rb_obj_alloc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* struct.c: dignobu2015-11-161-1/+8
| | | | | | | | * object.c (rb_obj_dig): dig in nested structs too. * struct.c (rb_struct_dig): new method Struct#dig. [Feature #11688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Module#<=> is not suitable for Comparable.akr2015-11-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_eval.c: rb_check_funcall_defaultnobu2015-11-091-3/+1
| | | | | | | | | * vm_eval.c (rb_check_funcall_default): split from rb_check_funcall to return the given fallback value. * object.c (rb_obj_dig): use rb_check_funcall_default so that tail call optimization will be possible. [Feature #11643] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dignobu2015-11-091-0/+47
| | | | | | | | | * array.c (rb_ary_dig): new method Array#dig. * hash.c (rb_hash_dig): new method Hash#dig. * object.c (rb_obj_dig): dig in nested arrays/hashes. [Feature #11643] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e