mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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:
@@ -12,10 +12,6 @@ scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
|
||||
m_margin {margin}
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -27,15 +23,17 @@ scrollback::add_line(const char *line, size_t len)
|
||||
if (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)
|
||||
memset(m_lines[i]+len, ' ', m_cols - len);
|
||||
memset(start + len, ' ', m_cols - len);
|
||||
}
|
||||
|
||||
char *
|
||||
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
|
||||
@@ -48,7 +46,7 @@ scrollback::render(screen &scr, font &fnt)
|
||||
const unsigned ystride = (m_margin + fnt.height());
|
||||
|
||||
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) {
|
||||
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ public:
|
||||
|
||||
private:
|
||||
char *m_data;
|
||||
char **m_lines;
|
||||
unsigned m_rows, m_cols;
|
||||
unsigned m_start;
|
||||
unsigned m_count;
|
||||
|
||||
Reference in New Issue
Block a user