diff options
author | S.H <gamelinks007@gmail.com> | 2021-11-18 13:26:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 20:26:40 -0800 |
commit | 05a3dc1a654c5e92200d994d0a51a2e159c88162 (patch) | |
tree | b541caea78b025bb36294eff3a68bd530e3baadb | |
parent | cb69c19e8ab540eda9de8a16a0f9479344a3a259 (diff) | |
download | ruby-05a3dc1a654c5e92200d994d0a51a2e159c88162.tar.gz |
Improve performance Kernel#Float with using Primitive.mandatory_only? method [Feature #18344] (#5133)
-rw-r--r-- | kernel.rb | 6 | ||||
-rw-r--r-- | object.c | 6 |
2 files changed, 11 insertions, 1 deletions
@@ -169,6 +169,10 @@ module Kernel # Float("123.0_badstring", exception: false) #=> nil # def Float(arg, exception: true) - Primitive.rb_f_float(arg, exception) + if Primitive.mandatory_only? + Primitive.rb_f_float1(arg) + else + Primitive.rb_f_float(arg, exception) + end end end @@ -3532,6 +3532,12 @@ rb_Float(VALUE val) } static VALUE +rb_f_float1(rb_execution_context_t *ec, VALUE obj, VALUE arg) +{ + return rb_convert_to_float(arg, TRUE); +} + +static VALUE rb_f_float(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts) { int exception = rb_bool_expected(opts, "exception"); |