Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list building #8862

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions awscli/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ def _render_column_titles(self, section, max_width, stream):
# the width of each of the columns.
widths = section.calculate_column_widths(padding=4,
max_width=max_width)
# TODO: Built a list instead of +=, it's more efficient.
current = ''
current = []
length_so_far = 0
# The first cell needs both left and right edges '| foo |'
# while subsequent cells only need right edges ' foo |'.
Expand All @@ -283,12 +282,12 @@ def _render_column_titles(self, section, max_width, stream):
first = False
else:
left_edge = ''
current += center_text(text=stylized_header, length=width,
left_edge=left_edge, right_edge='|',
text_length=get_text_length(header))
current.append(center_text(text=stylized_header, length=width,
left_edge=left_edge, right_edge='|',
text_length=get_text_length(header)))
length_so_far += width
self._write_line_break(stream, widths)
stream.write(current + '\n')
stream.write(''.join(current) + '\n')

def _write_line_break(self, stream, widths):
# Write out something like:
Expand All @@ -313,9 +312,7 @@ def _render_rows(self, section, max_width, stream):
return
self._write_line_break(stream, widths)
for row in section.rows:
# TODO: Built the string in a list then join instead of using +=,
# it's more efficient.
current = ''
current = []
length_so_far = 0
first = True
for width, element in zip(widths, row):
Expand All @@ -325,12 +322,12 @@ def _render_rows(self, section, max_width, stream):
else:
left_edge = ''
stylized = self._styler.style_row_element(element)
current += align_left(text=stylized, length=width,
left_edge=left_edge,
right_edge=self._column_separator,
text_length=get_text_length(element))
current.append(align_left(text=stylized, length=width,
left_edge=left_edge,
right_edge=self._column_separator,
text_length=get_text_length(element)))
length_so_far += width
stream.write(current + '\n')
stream.write(''.join(current) + '\n')
self._write_line_break(stream, widths)


Expand Down