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/hash.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/hash.rb')
| -rw-r--r-- | mrblib/hash.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 582cfbc6c..6b61218ff 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -194,9 +194,16 @@ class Hash # internal method for Hash inspection def _inspect return "{}" if self.size == 0 - "{"+self.map {|k,v| - k._inspect + "=>" + v._inspect - }.join(", ")+"}" + ary=[] + keys=self.keys + size=keys.size + i=0 + while i<size + k=keys[i] + ary<<(k._inspect + "=>" + self[k]._inspect) + i+=1 + end + "{"+ary.join(", ")+"}" end ## # Return the contents of this hash as a string. |
