Skip to content

Commit ad5280a

Browse files
authored
Implement small performance improvements identified from #110 (#112)
1 parent ffabedf commit ad5280a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Changed
88

99
* 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)).
10+
* Minor performance improvements for text-only blocks ([#111](https://github.com/springload/draftjs_exporter/pull/111)).
1011

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

@@ -404,7 +405,7 @@ KEYBOARD = 'kbd'
404405

405406
### Added
406407

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

@@ -420,7 +421,7 @@ KEYBOARD = 'kbd'
420421

421422
### Added
422423

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

426427
### Fixed

draftjs_exporter/html.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def build_command_groups(self, block):
100100
"""
101101
text = block['text']
102102

103-
commands = sorted(self.build_commands(block))
103+
commands = self.build_commands(block)
104104
grouped = groupby(commands, Command.key)
105105
listed = list(groupby(commands, Command.key))
106106
sliced = []
@@ -111,7 +111,7 @@ def build_command_groups(self, block):
111111
stop_index = listed[i + 1][0]
112112
sliced.append((text[start_index:stop_index], list(commands)))
113113
else:
114-
sliced.append((text[start_index:start_index], list(commands)))
114+
sliced.append(('', list(commands)))
115115
i += 1
116116

117117
return sliced
@@ -123,11 +123,10 @@ def build_commands(self, block):
123123
- Multiple pairs for styles.
124124
- Multiple pairs for entities.
125125
"""
126-
text_commands = Command.start_stop('text', 0, len(block['text']))
127126
style_commands = self.build_style_commands(block)
128127
entity_commands = self.build_entity_commands(block)
129128

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

132131
def build_style_commands(self, block):
133132
ranges = block['inlineStyleRanges']

tests/test_html.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ def test_build_commands_multiple(self):
193193
]
194194
})), str([
195195
Command('start_text', 0),
196-
Command('stop_text', 19),
197196
Command('start_inline_style', 0, 'ITALIC'),
197+
Command('start_entity', 0, 1),
198198
Command('stop_inline_style', 4, 'ITALIC'),
199+
Command('stop_entity', 4, 1),
200+
Command('start_entity', 5, 0),
199201
Command('start_inline_style', 9, 'BOLD'),
200202
Command('stop_inline_style', 12, 'BOLD'),
201-
Command('start_entity', 5, 0),
202203
Command('stop_entity', 14, 0),
203-
Command('start_entity', 0, 1),
204-
Command('stop_entity', 4, 1),
204+
Command('stop_text', 19),
205205
]))
206206

207207
def test_build_command_groups_empty(self):

0 commit comments

Comments
 (0)