summaryrefslogtreecommitdiff
path: root/numeric.rb
diff options
context:
space:
mode:
authorS.H <gamelinks007@gmail.com>2021-06-05 13:57:21 +0900
committerGitHub <noreply@github.com>2021-06-04 21:57:21 -0700
commit3208a5df2dfb429752a130a36274464e9924cf44 (patch)
tree9fb96fe83aa888d54f9c57290c66c26ef4630d2e /numeric.rb
parent033e76e7602d06e037e1d9bb8527280a58d548da (diff)
downloadruby-3208a5df2dfb429752a130a36274464e9924cf44.tar.gz
Improve perfomance for Integer#size method [Feature #17135] (#3476)
* Improve perfomance for Integer#size method [Feature #17135] * re-run ci * Let MJIT frame skip work for Integer#size Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Diffstat (limited to 'numeric.rb')
-rw-r--r--numeric.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/numeric.rb b/numeric.rb
index be33c5b436..c892cbe6ef 100644
--- a/numeric.rb
+++ b/numeric.rb
@@ -167,6 +167,26 @@ class Integer
return self
end
+ #
+ # Document-method: Integer#size
+ # call-seq:
+ # int.size -> int
+ #
+ # Returns the number of bytes in the machine representation of +int+
+ # (machine dependent).
+ #
+ # 1.size #=> 8
+ # -1.size #=> 8
+ # 2147483647.size #=> 8
+ # (256**10 - 1).size #=> 10
+ # (256**20 - 1).size #=> 20
+ # (256**40 - 1).size #=> 40
+ #
+ def size
+ Primitive.attr! 'inline'
+ Primitive.cexpr! 'rb_int_size(self)'
+ end
+
# call-seq:
# int.to_i -> integer
#