mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Re-implement Array#_inspect and Hash#_inspect without blocks.
To reduce the env object allocation; ref #4143
This commit is contained in:
+9
-2
@@ -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.
|
||||
|
||||
+10
-3
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user