Skip to content

Commit fdbffe7

Browse files
committedAug 17, 2024
Use loop instead of recursive call for Element#namespace
It's for performance and avoiding stack level too deep.
1 parent 6422fa3 commit fdbffe7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎lib/rexml/element.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,12 @@ def namespace(prefix=nil)
624624
else
625625
prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
626626
end
627-
ns = attributes[ prefix ]
628-
ns = parent.namespace(prefix) if ns.nil? and parent
627+
ns = nil
628+
target = self
629+
while ns.nil? and target
630+
ns = target.attributes[prefix]
631+
target = target.parent
632+
end
629633
ns = '' if ns.nil? and prefix == 'xmlns'
630634
return ns
631635
end

0 commit comments

Comments
 (0)