diff --git a/lib/oga/xml/html_void_elements.rb b/lib/oga/xml/html_void_elements.rb index 4196407..2efbb6f 100644 --- a/lib/oga/xml/html_void_elements.rb +++ b/lib/oga/xml/html_void_elements.rb @@ -24,5 +24,7 @@ module Oga 'track', 'wbr' ]) + + HTML_VOID_ELEMENTS.merge(HTML_VOID_ELEMENTS.map { |name| name.upcase }) end # XML end # Oga diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index 3030be3..605e75a 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -322,7 +322,12 @@ module Oga # Called on the closing `>` of the open tag of an element. # def on_element_open_end - if html? and HTML_VOID_ELEMENTS.include?(current_element.downcase) + return unless html? + + # Only downcase the name if we can't find an all lower/upper version of + # the element name. This can save us a *lot* of String allocations. + if HTML_VOID_ELEMENTS.include?(current_element) \ + or HTML_VOID_ELEMENTS.include?(current_element.downcase) add_token(:T_ELEM_END) @elements.pop end