Skip to content

Commit dc3c7d5

Browse files
committed
Do not use a hash to determine if a window must be redrawn
Collision happens Fixes mawww#569
1 parent 3e0e32c commit dc3c7d5

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/window.cc

+28-12
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,38 @@ void Window::center_column(CharCount buffer_column)
7272
display_column_at(buffer_column, m_dimensions.column/2_char);
7373
}
7474

75-
size_t Window::compute_hash(const Context& context) const
75+
Window::Setup Window::build_setup(const Context& context) const
7676
{
77-
size_t res = hash_values(m_position, context.ui().dimensions(), context.buffer().timestamp());
78-
79-
auto& selections = context.selections();
80-
res = combine_hash(res, hash_value(selections.main_index()));
81-
for (auto& sel : selections)
82-
res = combine_hash(res, hash_values((const ByteCoord&)sel.cursor(), sel.anchor()));
83-
84-
return res;
77+
Vector<BufferRange> selections;
78+
for (auto& sel : context.selections())
79+
selections.push_back({sel.cursor(), sel.anchor()});
80+
81+
return { m_position,
82+
context.ui().dimensions(),
83+
context.buffer().timestamp(),
84+
context.selections().main_index(),
85+
std::move(selections) };
8586
}
8687

8788
bool Window::needs_redraw(const Context& context) const
8889
{
89-
size_t hash = compute_hash(context);
90-
return hash != m_hash;
90+
auto& selections = context.selections();
91+
92+
if (m_position != m_last_setup.position or
93+
context.ui().dimensions() != m_last_setup.dimensions or
94+
context.buffer().timestamp() != m_last_setup.timestamp or
95+
selections.main_index() != m_last_setup.main_selection or
96+
selections.size() != m_last_setup.selections.size())
97+
return true;
98+
99+
for (int i = 0; i < selections.size(); ++i)
100+
{
101+
if (selections[i].cursor() != m_last_setup.selections[i].begin or
102+
selections[i].anchor() != m_last_setup.selections[i].end)
103+
return true;
104+
}
105+
106+
return false;
91107
}
92108

93109
const DisplayBuffer& Window::update_display_buffer(const Context& context)
@@ -120,7 +136,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
120136
line.trim(m_position.column, m_dimensions.column, true);
121137
m_display_buffer.optimize();
122138

123-
m_hash = compute_hash(context);
139+
m_last_setup = build_setup(context);
124140

125141
return m_display_buffer;
126142
}

src/window.hh

+11-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public:
4141
Buffer& buffer() const { return *m_buffer; }
4242

4343
bool needs_redraw(const Context& context) const;
44-
void force_redraw() { m_hash = -1; }
44+
void force_redraw() { m_last_setup = Setup{}; }
4545

4646
ByteCoord offset_coord(ByteCoord coord, CharCount offset);
4747
ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset);
@@ -55,8 +55,6 @@ private:
5555

5656
void run_hook_in_own_context(StringView hook_name, StringView param);
5757

58-
size_t compute_hash(const Context& context) const;
59-
6058
SafePtr<Buffer> m_buffer;
6159

6260
CharCoord m_position;
@@ -66,8 +64,16 @@ private:
6664
HighlighterGroup m_highlighters;
6765
HighlighterGroup m_builtin_highlighters;
6866

69-
// hash used to determine if a redraw is necessary
70-
size_t m_hash = -1;
67+
struct Setup
68+
{
69+
CharCoord position;
70+
CharCoord dimensions;
71+
size_t timestamp;
72+
size_t main_selection;
73+
Vector<BufferRange> selections;
74+
};
75+
Setup build_setup(const Context& context) const;
76+
Setup m_last_setup;
7177
};
7278

7379
}

0 commit comments

Comments
 (0)