Skip to content

Commit

Permalink
Use loop instead of recursive call for Element#namespace
Browse files Browse the repository at this point in the history
It's for performance and avoiding stack level too deep.
  • Loading branch information
kou committed Aug 17, 2024
1 parent 6422fa3 commit fdbffe7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rexml/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,12 @@ def namespace(prefix=nil)
else
prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
end
ns = attributes[ prefix ]
ns = parent.namespace(prefix) if ns.nil? and parent
ns = nil
target = self
while ns.nil? and target
ns = target.attributes[prefix]
target = target.parent
end
ns = '' if ns.nil? and prefix == 'xmlns'
return ns
end
Expand Down

0 comments on commit fdbffe7

Please sign in to comment.