summaryrefslogtreecommitdiffhomepage
path: root/mrblib/array.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-10-29 11:55:49 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-10-29 11:55:49 +0900
commit34872e90d44bdde64e18b7774cf09495ec043e24 (patch)
treede8df9b2c78fc2253373807720b4da177da60066 /mrblib/array.rb
parentdffa203d07aaeec4ea65669542a8ec2033559bdd (diff)
downloadmruby-34872e90d44bdde64e18b7774cf09495ec043e24.tar.gz
mruby-34872e90d44bdde64e18b7774cf09495ec043e24.zip
Re-implement `Array#_inspect` and `Hash#_inspect` without blocks.
To reduce the env object allocation; ref #4143
Diffstat (limited to 'mrblib/array.rb')
-rw-r--r--mrblib/array.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb
index ae0868410..53d880660 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -84,8 +84,15 @@ class Array
end
def _inspect
- return "[]" if self.size == 0
- "["+self.map{|x|x.inspect}.join(", ")+"]"
+ size = self.size
+ return "[]" if size == 0
+ ary=[]
+ i=0
+ while i<size
+ ary<<self[i].inspect
+ i+=1
+ end
+ "["+ary.join(", ")+"]"
end
##
# Return the contents of this array as a string.