buffer: Limit the number of lines we search when replacing lines.
This commit is contained in:
parent
11b960e22c
commit
3efd866052
1 changed files with 12 additions and 6 deletions
|
@ -807,11 +807,15 @@ class WeechatChannelBuffer(object):
|
||||||
def short_name(self, name):
|
def short_name(self, name):
|
||||||
W.buffer_set(self._ptr, "short_name", name)
|
W.buffer_set(self._ptr, "short_name", name)
|
||||||
|
|
||||||
def find_lines(self, predicate):
|
def find_lines(self, predicate, max_lines=None):
|
||||||
lines = []
|
lines = []
|
||||||
|
count = 0
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
if predicate(line):
|
if predicate(line):
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
|
count += 1
|
||||||
|
if max_lines is not None and count == max_lines:
|
||||||
|
return lines
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
@ -1457,11 +1461,7 @@ class RoomBuffer(object):
|
||||||
last_line.message = message
|
last_line.message = message
|
||||||
|
|
||||||
def replace_printed_line_by_uuid(self, uuid, new_message):
|
def replace_printed_line_by_uuid(self, uuid, new_message):
|
||||||
"""Replace already printed lines that are greyed out with real ones"""
|
"""Replace already printed lines that are greyed out with real ones."""
|
||||||
lines = self.weechat_buffer.find_lines(
|
|
||||||
partial(self._find_by_uuid_predicate, uuid)
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(new_message, OwnAction):
|
if isinstance(new_message, OwnAction):
|
||||||
displayed_nick = self.displayed_nicks[self.room.own_user_id]
|
displayed_nick = self.displayed_nicks[self.room.own_user_id]
|
||||||
user = self.weechat_buffer._get_user(displayed_nick)
|
user = self.weechat_buffer._get_user(displayed_nick)
|
||||||
|
@ -1473,6 +1473,12 @@ class RoomBuffer(object):
|
||||||
else:
|
else:
|
||||||
new_lines = new_message.formatted_message.to_weechat().split("\n")
|
new_lines = new_message.formatted_message.to_weechat().split("\n")
|
||||||
|
|
||||||
|
line_count = len(new_lines)
|
||||||
|
|
||||||
|
lines = self.weechat_buffer.find_lines(
|
||||||
|
partial(self._find_by_uuid_predicate, uuid), line_count
|
||||||
|
)
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
line.message = new_lines[i]
|
line.message = new_lines[i]
|
||||||
tags = line.tags
|
tags = line.tags
|
||||||
|
|
Loading…
Add table
Reference in a new issue