Re-implement `Array#_inspect` and `Hash#_inspect` without blocks.

To reduce the env object allocation; ref #4143
parent dffa203d
...@@ -84,8 +84,15 @@ class Array ...@@ -84,8 +84,15 @@ class Array
end end
def _inspect def _inspect
return "[]" if self.size == 0 size = self.size
"["+self.map{|x|x.inspect}.join(", ")+"]" return "[]" if size == 0
ary=[]
i=0
while i<size
ary<<self[i].inspect
i+=1
end
"["+ary.join(", ")+"]"
end end
## ##
# Return the contents of this array as a string. # Return the contents of this array as a string.
......
...@@ -194,9 +194,16 @@ class Hash ...@@ -194,9 +194,16 @@ class Hash
# internal method for Hash inspection # internal method for Hash inspection
def _inspect def _inspect
return "{}" if self.size == 0 return "{}" if self.size == 0
"{"+self.map {|k,v| ary=[]
k._inspect + "=>" + v._inspect keys=self.keys
}.join(", ")+"}" size=keys.size
i=0
while i<size
k=keys[i]
ary<<(k._inspect + "=>" + self[k]._inspect)
i+=1
end
"{"+ary.join(", ")+"}"
end end
## ##
# Return the contents of this hash as a string. # Return the contents of this hash as a string.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment