Skip to content

Commit

Permalink
Cache empty soup to avoid biggest BS overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Feb 16, 2017
1 parent a33cae6 commit e529561
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion draftjs_exporter/dom.py
Expand Up @@ -21,6 +21,10 @@ def Soup(raw_str):
return BeautifulSoup(raw_str, 'html5lib')


# Cache empty soup so we can create tags in isolation without the performance overhead.
soup = Soup('')


class DOM(object):
"""
Wrapper around our HTML building library to facilitate changes.
Expand All @@ -30,7 +34,7 @@ def create_tag(type_, attributes=None):
if attributes is None:
attributes = {}

return Soup('').new_tag(type_, **attributes)
return soup.new_tag(type_, **attributes)

@staticmethod
def create_element(type_=None, props=None, *children):
Expand Down

0 comments on commit e529561

Please sign in to comment.