aboutsummaryrefslogtreecommitdiffstats
path: root/internal.h
Commit message (Collapse)AuthorAgeFilesLines
* remove unused rb_obj_basic_to_s_p functionnormal2017-06-291-1/+0
| | | | | | | | | | | This hasn't been used since r36709 (2012-08-15) ("Kernel#inspect: improve consistency and do not call #to_s.") and was never part of public API in include/ruby/ * class.c (rb_obj_basic_to_s_p): remove function * internal.h (rb_obj_basic_to_s_p): remove declaration git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_catch_protect() accepts enum ruby_tag_type *.ko12017-06-231-1/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* removed ruby_error_printnobu2017-06-161-1/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* remove ruby_kill() introduced for [Bug #7951].ko12017-06-121-1/+0
| | | | | | | | | | | | | | | | | | * thread.c (rbuy_kill): removed. This function is used with SIGSEGV, SIGBUS, SIGKILL, SIGILL, SIGFPE and SIGSTOP and these signals are affect immediately. So that `kill(2)' is enough for them. * signal.c (rb_f_kill): ditto. * vm_core.h (rb_thread_t::interrupt_cond): removed because only `ruby_kill()' uses this field. * test/ruby/test_signal.rb: Without this patch sending SIGSTOP to own process wait another interrupt even if another process sends SIGCONT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* file.c: realpath in OS path encodingnobu2017-06-081-0/+3
| | | | | | | | | * dir.c (rb_dir_getwd_ospath): return cwd path in the OS path encoding. * file.c (rb_realpath_internal): work in the OS path encoding git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rename functions and clean parameters.ko12017-06-051-1/+1
| | | | | | | | | | | | | | | | | | | | | * internal.h (rb_yield_lambda): rename to rb_yield_force_blockarg() because this function prohibt lambda arg setup (strict setup). * vm.c (invoke_iseq_block_from_c): remove splattable argument because it is not used. * vm.c (invoke_block_from_c_splattable): rename to invoke_block_from_c_bh() because `splattable` doesn't make sense on current this function. Also accept `force_blockarg' parameter instead of `splattable` parameter. It is more clear. * vm.c (invoke_block_from_c_unsplattable): rename to invoke_block_from_c_proc() and accept `proc` instead of `block'. This function is used only by proc block invocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c: convert by rb_get_path_checknobu2017-06-011-0/+1
| | | | | | | * load.c (rb_require_internal): convert to path name with the given safe level, without setting global safe level. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of implicit type conversionwatson19782017-05-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Improve performance of some Time methodswatson19782017-05-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | internal.h : add rb_numeric_quo() as internal API. rational.c : rename numeric_quo() to rb_numeric_quo() as internal API. time.c (quov): optimize by invoking rb_numeric_quo() to retrieve a value of Numeric#quo instead of method dispatching via rb_funcall(). Time#subsec -> 7 % up Time#- -> 26 % up Time#to_f -> 30 % up Time#to_r -> 7 % up [ruby-core:80915] [Bug #13519] [Fix GH-1601] ### Before Time#subsec 2.024M (± 8.7%) i/s - 10.062M in 5.009762s Time#- 5.049M (± 4.7%) i/s - 25.186M in 5.002379s Time#to_f 5.625M (± 4.2%) i/s - 28.066M in 5.000749s Time#to_r 1.880M (± 9.7%) i/s - 9.361M in 5.027527s ### After Time#subsec 2.155M (± 9.7%) i/s - 10.724M in 5.022579s Time#- 6.362M (± 2.0%) i/s - 31.824M in 5.004625s Time#to_f 7.287M (± 4.8%) i/s - 36.402M in 5.010983s Time#to_r 2.020M (± 9.4%) i/s - 10.059M in 5.021852s ### Test code require 'benchmark/ips' Benchmark.ips do |x| x.report "Time#subsec" do |t| time = Time.now t.times { time.subsec } end x.report "Time#-" do |t| time1 = Time.now time2 = Time.now t.times { time1 - time2 } end x.report "Time#to_f" do |t| time = Time.now t.times { time.to_f } end x.report "Time#to_r" do |t| time = Time.now t.times { time.to_r } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_insnhelper.c: rb_eql_opt should call eql?nobu2017-05-251-0/+2
| | | | | | | * vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and String, not #==. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of rb_eql()watson19782017-05-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* internal.h (rb_gc_resurrect): remove stale declarationktsj2017-05-041-2/+0
| | | | | | rb_gc_resurrect is no longer defined since r47444. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: rb_raise_staticnobu2017-05-021-0/+5
| | | | | | | * 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
* Send the backtrace of the circular require warning as a single String to ↵eregon2017-04-271-0/+1
| | | | | | | | | | | Warning.warn * load.c: send as a single string. * error.c: expose the string formatted by rb_warning as rb_warning_string(). * test/ruby/test_exception.rb: update tests. [ruby-core:80850] [Bug #13505] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* refactor newhash (revision 58463 another try) [fix GH-1600]shyouhei2017-04-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * st.c (rb_hash_bulk_insert): new API to bulk insert entries into a hash. Given arguments are first inserted into the table at once, then reindexed. This is faster than inserting things using rb_hash_aset() one by one. This arrangement (rb_ prefixed function placed in st.c) is unavoidable because it both touches table internal and write barrier at once. * internal.h: delcare the new function. * hash.c (rb_hash_s_create): use the new function. * vm.c (core_hash_merge): ditto. * insns.def (newhash): ditto. * test/ruby/test_hash.rb: more coverage on hash creation. * test/ruby/test_literal.rb: ditto. ----------------------------------------------------------- benchmark results: minimum results in each 7 measurements. Execution time (sec) name before after loop_whileloop2 0.136 0.137 vm2_bighash* 1.249 0.623 Speedup ratio: compare with the result of `before' (greater is better) name after loop_whileloop2 0.996 vm2_bighash* 2.004 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c: backtrace of circular requirenobu2017-04-251-1/+2
| | | | | | | * load.c (load_lock): print backtrace of circular require via `Warning.warn` [ruby-core:80850] [Bug #13505] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert newhash refactoringshyouhei2017-04-241-1/+0
| | | | | | | | We need to fix GC bug before merging this. Revert revisions 58452, 58435, 58434, 58428, 58427 in this order. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* refactor hash literalshyouhei2017-04-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Same as rb_ary_tmp_new_from_values(), it reduces vm_exec_core binary size from 26,176 bytes to 26,080 bytes. But this time, also with a bit of optimizations: - Because we are allocating a new hash and no back references are introduced at all, we can safely skip write barriers. - Also, the iteration never recurs. We can avoid complicated function callbacks by using st_insert instead of st_update. ---- * hash.c (rb_hash_new_from_values): refactor extract the bulk insert into a function. * hash.c (rb_hash_new_from_object): also refactor. * hash.c (rb_hash_s_create): use the new functions. * insns.def (newhash): ditto. * vm.c (core_hash_from_ary): ditto. * iternal.h: export the new function. ----------------------------------------------------------- benchmark results: minimum results in each 7 measurements. Execution time (sec) name before after loop_whileloop2 0.135 0.134 vm2_bighash* 1.236 0.687 Speedup ratio: compare with the result of `before' (greater is better) name after loop_whileloop2 1.008 vm2_bighash* 1.798 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* split insns.def into functionsshyouhei2017-04-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Contemporary C compilers are good at function inlining. They fold multiple functions into one. However they are not yet smart enough to unfold a function into several ones. So generally speaking, it is wiser for a C programmer to manually split C functions whenever possible. That should make rooms for compilers to optimize at will. Before this changeset insns.def was converted into single HUGE function called vm_exec_core(). By moving each instruction's core into individual functions, generated C source code is reduced from 3,428 lines to 2,847 lines. Looking at the generated assembly however, it seems my compiler (gcc 6.2) is extraordinary smart so that it inlines almost all functions I introduced in this changeset back into that vm_exec_core. On my machine compiled machine binary of the function does not shrink very much in size (28,432 bytes to 26,816 bytes, according to nm(1)). I believe this change is zero-cost. Several benchmarks I exercised showed no significant difference beyond error mergin. For instance 3 repeated runs of optcarrot benchmark on my machine resulted in: before this: 28.330329285707490, 27.513378371065920, 29.40420215754537 after this: 27.107195867280414, 25.549324021385907, 30.31581919050884 in fps (greater==faster). ---- * internal.h (rb_obj_not_equal): used from vm_insnhelper.c * insns.def: move vast majority of lines into vm_insnhelper.c * vm_insnhelper.c: moved here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_backtrace.c: backtrace functions per threadsnobu2017-04-171-1/+0
| | | | | | | | | | | | * vm_backtrace.c (rb_threadptr_backtrace_object): rename and extern. * vm_backtrace.c (rb_threadptr_backtrace_str_ary): rename as threadptr since the parameter is rb_thread_t*. * vm_backtrace.c (rb_threadptr_backtrace_location_ary): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c: Improve performance of Array#sort with float elementsmrkn2017-04-131-0/+4
| | | | | | | | | | | | | | | | | * array.c (sort_2): improve performance of Array#sort with float elements. * internal.h (cmp_opt_Float, cmp_opt_data): added for checking whether or not Float#<=> can be optimizable. * numeric.c (rb_float_cmp): added for internal use. * internal.h (rb_float_cmp): ditto. [Bug #13340] [ruby-dev:50023] [Fix GH-1539] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* introduce imemo_type_p(v, imemo_type)ko12017-04-071-0/+15
| | | | | | | | * internal.h: introduce imemo_type_p() which checks the given value is T_IMEMO and imemo_type() == given imemo_type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: parenthesize macro argumentnobu2017-04-061-1/+1
| | | | | | | * internal.h (THROW_DATA_P): parenthesize the argument which is casted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix TracePoint#return_value with non-local exitsko12017-04-061-1/+3
| | | | | | | | | | | | | | | | | | * vm.c: get return_value from imemo_throw_data object (THROW_DATA_VAL()). imemo_throw_data (TAG_BREAK) contains returned value. However, imemo_throw_data (TAG_BREAK) can skip several frames so that we need to use it only once (at most internal frame). To record it, we introduced THROW_DATA_CONSUMED and check it. * internal.h: define THROW_DATA_CONSUMED flag. * test/ruby/test_settracefunc.rb: add tests for [Bug #13369] * vm_insnhelper.h: add THROW_DATA_CONSUMED_P() and THROW_DATA_CONSUMED_SET(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Remove unused Init_frozen_strings declarationsorah2017-03-291-1/+0
| | | | | | | | | | | | Init_frozen_strings definition is removed in r51511. https://bugs.ruby-lang.org/issues/11423 Patch by Kohei Suzuki <eagletmt@gmail.com> * internal.h: Remove declaration of unexist function [Fix GH-1558] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* error.c: warning functionsnobu2017-03-271-0/+8
| | | | | | | | | * error.c: define warning functions in all combinations of * no errno, system errno, argument * without/with encoding * enabled/disabled by default git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_args.c: arity check of lambdanobu2017-03-191-0/+1
| | | | | | | | | | | | * vm_eval.c (rb_yield_lambda): new function which yields an array to a proc and splat to a lambda. mainly for Enumerable only. * vm_args.c (setup_parameters_complex): remove special lambda splatting for [Bug #9605]. [ruby-core:77065] [Bug #12705] * vm_insnhelper.c (vm_callee_setup_block_arg): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* bignum.c: rb_int_parse_cstrnobu2017-03-161-0/+8
| | | | | | | * bignum.c (rb_int_parse_cstr): extend rb_cstr_parse_inum with flags. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei2017-03-091-11/+0
| | | | | | | | | 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
* re-introduce __builtin_add_overflowshyouhei2017-03-081-5/+4
| | | | | | | | | | | | | r57789 (74cdd89) was gradually "improve"d by naruse through r57793 to r57806, resulted in reverting the efect of r57789 while retaining its complexity. I think the current situation is slightly worse than before (same output complicated source code). Here I introduce __builtin_add_overflow again, which (I think) is what naruse wanted to do in r57793. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use RB_POSFIXABLE and RB_NEGFIXABLE to avoid cast introduced at r57793naruse2017-03-071-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* optimize FIXABLE macroshyouhei2017-03-061-0/+12
| | | | | | | | | | | | 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
* LONG_LONG_MAX not always availableshyouhei2017-03-061-1/+1
| | | | | | | | | I was not aware of cases when LONG_LONG_MAX is undefined. Sorry. Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* opt_eq_func refactornobu2017-03-061-0/+1
| | | | | | | | | | * vm_insnhelper.c (opt_eq_func): method to dispatch is resolved by only the receiver's class, not including the argument class. even if basic operation is redefined, other class conditions never meet. optimize Float and non-Float case, delegate to rb_float_equal directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use HAVE_BUILTIN___BUILTIN_MUL_OVERFLOWshyouhei2017-03-061-2/+28
| | | | | | | | | | | | | | | | | | | We already check for __builtin_mul_overflow in configure but never actually referred it before. Why not call it if available, because that should render supposedly-optimial assembly outputs. Optionally if __builtin_mul_overflow_p is available, which is the case for recent GCC, use that to detect fixnum overflow. This is much faster than the previous. On my machine generated assembly of numeric.c:int_pow reduces from 480 to 448 bytes, according to nm(1). Also on my machine, following script boosts from 7.819 to 6.929 sec. time ./miniruby -e 'i=0; while i < 30_000_000 do i += 1; 7 ** 23; end' Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval_error.c: backstrace in reverse ordernobu2017-02-221-0/+1
| | | | | | | | * eval_error.c (rb_threadptr_error_print): print backtrace and error message in reverse order if STDERR is unchanged and a tty. [Feature #8661] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: Numeric#clone and #dupnobu2017-02-221-0/+1
| | | | | | | | | | | * 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
* internal.h: removed function declarationnobu2017-02-211-1/+0
| | | | | | | * internal.h (rb_compile_error_str): remove declaration of removed internal function at r54189. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* DEPRECATED_INTERNAL_FEATUREnobu2017-02-171-2/+3
| | | | | | | | | * error.c (ruby_deprecated_internal_feature): renamed, to explicitly represent deprecation. * internal.h (DEPRECATED_INTERNAL_FEATURE): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix description for current implementationnaruse2017-02-041-5/+17
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: fix r57507nobu2017-02-031-5/+5
| | | | | | | * internal.h (rb_overflowed_fix_to_int): invert sign bit. should not set LSB of fixnum value, which is always set, to MSB. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use carry flag to reduce instructionsnaruse2017-02-021-0/+47
| | | | | | | | | | | | | | | | NOTE: (1) Fixnum's LSB is always 1. It means you can always run `x - 1` without overflow. (2) Of course `z = x + (y-1)` may overflow. Now z's LSB is always 1, and the MSB of true result is also 1. You can get true result in long as `(1<<63)|(z>>1)`, and it equals to `(z<<63)|(z>>1)` == `ror(z)`. GCC and Clang have __builtin_add_ovewflow: * https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html * https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: recycle garbage on writenormal2017-01-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * string.c (STR_IS_SHARED_M): new flag to mark shared mulitple times (STR_SET_SHARED): set STR_IS_SHARED_M (rb_str_tmp_frozen_acquire, rb_str_tmp_frozen_release): new functions (str_new_frozen): set/unset STR_IS_SHARED_M as appropriate * internal.h: declare new functions * io.c (fwrite_arg, fwrite_do, fwrite_end): new (io_fwrite): use new functions Introduce rb_str_tmp_frozen_acquire and rb_str_tmp_frozen_release to manage a hidden, frozen string. Reuse one bit of the embed length for shared strings as STR_IS_SHARED_M to indicate a string has been shared multiple times. In the common case, the string is only shared once so the object slot can be reclaimed immediately. minimum results in each 3 measurements. (time and size) Execution time (sec) name trunk built io_copy_stream_write 0.682 0.254 io_copy_stream_write_socket 1.225 0.751 Speedup ratio: compare with the result of `trunk' (greater is better) name built io_copy_stream_write 2.680 io_copy_stream_write_socket 1.630 Memory usage (last size) (B) name trunk built io_copy_stream_write 95436800.000 6512640.000 io_copy_stream_write_socket 117628928.000 7127040.000 Memory consuming ratio (size) with the result of `trunk' (greater is better) name built io_copy_stream_write 14.654 io_copy_stream_write_socket 16.505 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix up r57461nobu2017-01-301-4/+7
| | | | | | | * internal.h: Microsoft Visual C++ has never supported C99 yet, even in 2017. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* #include <stdbool.h>shyouhei2017-01-301-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 17+ years passed since standardized in ISO, 8 years since we added AC_HEADER_STDBOOL to configure.in. I'm quite confident that it's already safe to use <stdbool.h>. I understand that when we introduced AC_HEADER_STDBOOL, <stdbool.h> was remain not included because C standard and SVR4 curses conflicted miserably back then (#1). Though I believe such situation has been fixed already(#2), I'm afraid of your operating system might ship a proprietary curses that still conflicts with the standard. So to avoid potential problem, we limit the inclusion to our internal use only. #1 : 1997 version of SUSv2 said bool is "defined though typedef" in <curses.h>, while C99 said bool is a macro, plus in C++ bool is a keyword. AFASIK the curses library has never been a part of POSIX. #2 : In reality ncurses and NetBSD curses both just follow C99 to include <stdbool.h> from <curses.h>. I think C99 is now widely adopted. ---- * internal.h: #include <stdbool.h> if present. That is believed to be the case for 99.9% systems that lives today. Non-C99, non-C++ situations are intentionally left undefined, advised by Motohiro Kosaki. If you have such compiler, please fill the definition appropriately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval.c: copy special exceptionnobu2017-01-241-1/+1
| | | | | | | * eval.c (setup_exception): make unfrozen copy of special exception before setting up a cause. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* file.c: refine messagenobu2017-01-161-0/+1
| | | | | | | * file.c (rb_get_path_check_convert): refine the error message when the path name contains null byte. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix optimization for hash aset/aref with fstringeregon2017-01-071-0/+1
| | | | | | | | | | | Patch by Eric Wong [ruby-core:78797]. I don't like the idea of making insns.def any bigger to support a corner case, and "test_hash_aref_fstring_identity" shows how contrived this is. [ruby-core:78783] [Bug #12855] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: reduce fdivnobu2016-12-281-0/+1
| | | | | | | * numeric.c (rb_int_fdiv_double): reduce first for more precise result. [ruby-core:78886] [Bug #13078] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* get rid of implicit signedness conversionsnobu2016-12-221-40/+50
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e