[fb] Remove extraneous m_lines from scrollback

We have one big array of characters in scrollback, with lines of
constant width -- there's no reason to have an array of pointers when
offsets will do.
This commit is contained in:
Justin C. Miller
2021-02-04 20:55:56 -08:00
parent e4aafca7c3
commit c87563a520
2 changed files with 6 additions and 9 deletions

View File

@@ -12,10 +12,6 @@ scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
m_margin {margin} m_margin {margin}
{ {
m_data = reinterpret_cast<char*>(malloc(lines*cols)); m_data = reinterpret_cast<char*>(malloc(lines*cols));
m_lines = reinterpret_cast<char**>(malloc(lines*sizeof(char*)));
for (unsigned i = 0; i < lines; ++i)
m_lines[i] = &m_data[i*cols];
memset(m_data, ' ', lines*cols); memset(m_data, ' ', lines*cols);
} }
@@ -27,15 +23,17 @@ scrollback::add_line(const char *line, size_t len)
if (len > m_cols) if (len > m_cols)
len = m_cols; len = m_cols;
memcpy(m_lines[i], line, len); char *start = m_data + (i * m_cols);
memcpy(start, line, len);
if (len < m_cols) if (len < m_cols)
memset(m_lines[i]+len, ' ', m_cols - len); memset(start + len, ' ', m_cols - len);
} }
char * char *
scrollback::get_line(unsigned i) scrollback::get_line(unsigned i)
{ {
return m_lines[(i+m_count)%m_rows]; unsigned line = (i + m_count) % m_rows;
return &m_data[line*m_cols];
} }
void void
@@ -48,7 +46,7 @@ scrollback::render(screen &scr, font &fnt)
const unsigned ystride = (m_margin + fnt.height()); const unsigned ystride = (m_margin + fnt.height());
for (unsigned y = 0; y < m_rows; ++y) { for (unsigned y = 0; y < m_rows; ++y) {
char *line = get_line(y); char *line = &m_data[y*m_cols];
for (unsigned x = 0; x < m_cols; ++x) { for (unsigned x = 0; x < m_cols; ++x) {
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride); fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
} }

View File

@@ -17,7 +17,6 @@ public:
private: private:
char *m_data; char *m_data;
char **m_lines;
unsigned m_rows, m_cols; unsigned m_rows, m_cols;
unsigned m_start; unsigned m_start;
unsigned m_count; unsigned m_count;