diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-10-29 11:55:49 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-10-29 11:55:49 +0900 |
| commit | 34872e90d44bdde64e18b7774cf09495ec043e24 (patch) | |
| tree | de8df9b2c78fc2253373807720b4da177da60066 /mrblib/array.rb | |
| parent | dffa203d07aaeec4ea65669542a8ec2033559bdd (diff) | |
| download | mruby-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.rb | 11 |
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. |
