Skip to content

Commit

Permalink
Implement small performance improvements identified from #110 (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas authored May 28, 2019
1 parent ffabedf commit ad5280a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed

* Assume same block defaults as Draft.js would when attributes are missing: depth = 0, type = unstyled, no entities, no styles ([#110](https://github.com/springload/draftjs_exporter/pull/110)).
* Minor performance improvements for text-only blocks ([#111](https://github.com/springload/draftjs_exporter/pull/111)).

## [v2.1.5](https://github.com/springload/draftjs_exporter/releases/tag/v2.1.5)

Expand Down Expand Up @@ -404,7 +405,7 @@ KEYBOARD = 'kbd'

### Added

* Add support for decorators thanks to @su27 (#16, #17).
* Add support for decorators thanks to [@su27](https://github.com/su27) (#16, #17).
* Add support for configurable decorators and entities.
* Add support for decorators and entities in function form.

Expand All @@ -420,7 +421,7 @@ KEYBOARD = 'kbd'

### Added

* Add profiling tooling thanks to @su27 (#31).
* Add profiling tooling thanks to [@su27](https://github.com/su27) (#31).
* Add more common entity types in constants (#34).

### Fixed
Expand Down
7 changes: 3 additions & 4 deletions draftjs_exporter/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_command_groups(self, block):
"""
text = block['text']

commands = sorted(self.build_commands(block))
commands = self.build_commands(block)
grouped = groupby(commands, Command.key)
listed = list(groupby(commands, Command.key))
sliced = []
Expand All @@ -111,7 +111,7 @@ def build_command_groups(self, block):
stop_index = listed[i + 1][0]
sliced.append((text[start_index:stop_index], list(commands)))
else:
sliced.append((text[start_index:start_index], list(commands)))
sliced.append(('', list(commands)))
i += 1

return sliced
Expand All @@ -123,11 +123,10 @@ def build_commands(self, block):
- Multiple pairs for styles.
- Multiple pairs for entities.
"""
text_commands = Command.start_stop('text', 0, len(block['text']))
style_commands = self.build_style_commands(block)
entity_commands = self.build_entity_commands(block)

return text_commands + style_commands + entity_commands
return [Command('start_text', 0)] + sorted(style_commands + entity_commands) + [Command('stop_text', len(block['text']))]

def build_style_commands(self, block):
ranges = block['inlineStyleRanges']
Expand Down
8 changes: 4 additions & 4 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ def test_build_commands_multiple(self):
]
})), str([
Command('start_text', 0),
Command('stop_text', 19),
Command('start_inline_style', 0, 'ITALIC'),
Command('start_entity', 0, 1),
Command('stop_inline_style', 4, 'ITALIC'),
Command('stop_entity', 4, 1),
Command('start_entity', 5, 0),
Command('start_inline_style', 9, 'BOLD'),
Command('stop_inline_style', 12, 'BOLD'),
Command('start_entity', 5, 0),
Command('stop_entity', 14, 0),
Command('start_entity', 0, 1),
Command('stop_entity', 4, 1),
Command('stop_text', 19),
]))

def test_build_command_groups_empty(self):
Expand Down

0 comments on commit ad5280a

Please sign in to comment.