Improved HTML void element detection performance.
This ensures we only call String#downcase if we can't find an all lowercased *and* all uppercased version of the element name. This in turn can save as many object allocations as there are HTML opening tags. This fixes #52.
This commit is contained in:
parent
c89ac91f3a
commit
4469ffc5b1
|
@ -24,5 +24,7 @@ module Oga
|
|||
'track',
|
||||
'wbr'
|
||||
])
|
||||
|
||||
HTML_VOID_ELEMENTS.merge(HTML_VOID_ELEMENTS.map { |name| name.upcase })
|
||||
end # XML
|
||||
end # Oga
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue