summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-12-30 14:54:54 +0100
committermathieui <mathieui@mathieui.net>2012-12-30 14:54:54 +0100
commit0f9b37b8a8ee9ec469426f425a6415269653ac5a (patch)
tree1c36fa9e180af62d8c79060ed1ec2340f3926324 /src
parent1313e7be3800d330824e1a8021e78bba5ddffe45 (diff)
downloadpoezio-0f9b37b8a8ee9ec469426f425a6415269653ac5a.tar.gz
poezio-0f9b37b8a8ee9ec469426f425a6415269653ac5a.tar.bz2
poezio-0f9b37b8a8ee9ec469426f425a6415269653ac5a.tar.xz
poezio-0f9b37b8a8ee9ec469426f425a6415269653ac5a.zip
Do not rebuild everything in order to modify a message
(should fix the “leak” on /correct, and make it faster)
Diffstat (limited to 'src')
-rw-r--r--src/tabs.py9
-rw-r--r--src/text_buffer.py3
-rw-r--r--src/windows.py64
3 files changed, 52 insertions, 24 deletions
diff --git a/src/tabs.py b/src/tabs.py
index d9dae765..f4e224f7 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -1639,10 +1639,11 @@ class MucTab(ChatTab):
def modify_message(self, txt, old_id, new_id, time=None, nickname=None):
self.log_message(txt, time, nickname)
highlight = self.do_highlight(txt, time, nickname)
- self._text_buffer.modify_message(txt, old_id, new_id, highlight=highlight, time=time)
- self.text_win.rebuild_everything(self._text_buffer)
- self.core.refresh_window()
- return highlight
+ message = self._text_buffer.modify_message(txt, old_id, new_id, highlight=highlight, time=time)
+ if message:
+ self.text_win.modify_message(old_id, message)
+ self.core.refresh_window()
+ return highlight
def matching_names(self):
return [safeJID(self.get_name()).user]
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 48de2b1c..f1c4eb24 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -82,8 +82,9 @@ class TextBuffer(object):
message = self.make_message(txt, time if time else msg.time, msg.nickname, msg.nick_color, None, msg.user, new_id, highlight=highlight, old_message=msg, revisions=msg.revisions + 1)
self.messages[i] = message
log.debug('Replacing message %s with %s.' % (old_id, new_id))
- return
+ return message
log.debug('Message %s not found in text_buffer, abort replacement.' % (old_id))
+ return
def del_window(self, win):
self.windows.remove(win)
diff --git a/src/windows.py b/src/windows.py
index d5239a09..1bab7777 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -781,12 +781,31 @@ class TextWin(Win):
Return the number of lines that are built for the given
message.
"""
- if message is None: # line separator
- self.built_lines.append(None)
+ lines = self.build_message(message, timestamp=timestamp)
+ if self.lock:
+ self.lock_buffer.extend(lines)
+ else:
+ self.built_lines.extend(lines)
+ if not lines or not lines[0]:
return 0
+ if highlight:
+ self.highlights.append(lines[0])
+ if clean:
+ while len(self.built_lines) > self.lines_nb_limit:
+ self.built_lines.pop(0)
+ return len(lines)
+
+ def build_message(self, message, timestamp=False):
+ """
+ Build a list of lines from a message, without adding it
+ to a list
+ """
+ if message is None: # line separator
+ return [None]
txt = message.txt
if not txt:
- return 0
+ return []
+ ret = []
nick = truncate_nick(message.nickname)
offset = 0
if nick:
@@ -803,22 +822,10 @@ class TextWin(Win):
if get_theme().CHAR_TIME_RIGHT and message.str_time:
offset += 1
lines = cut_text(txt, self.width-offset)
- if self.lock:
- for line in lines:
- self.lock_buffer.append(Line(msg=message,
- start_pos=line[0],
- end_pos=line[1]))
- else:
- for line in lines:
- saved_line = Line(msg=message, start_pos=line[0], end_pos=line[1])
- self.built_lines.append(saved_line)
- if highlight:
- highlight = False
- self.highlights.append(saved_line)
- if clean:
- while len(self.built_lines) > self.lines_nb_limit:
- self.built_lines.pop(0)
- return len(lines)
+ for line in lines:
+ saved = Line(msg=message, start_pos=line[0], end_pos=line[1])
+ ret.append(saved)
+ return ret
def refresh(self):
log.debug('Refresh: %s', self.__class__.__name__)
@@ -932,6 +939,25 @@ class TextWin(Win):
while len(self.built_lines) > self.lines_nb_limit:
self.built_lines.pop(0)
+ def modify_message(self, old_id, message):
+ """
+ Find a message, and replace it with a new one
+ (instead of rebuilding everything in order to correct a message)
+ """
+ with_timestamps = config.get("show_timestamps", 'true') != 'false'
+ for i in range(len(self.built_lines)-1, 0, -1):
+ if self.built_lines[i].msg.identifier == old_id:
+ index = i
+ while index > 0 and self.built_lines[index].msg.identifier == old_id:
+ self.built_lines.pop(index)
+ index -= 1
+ index += 1
+ lines = self.build_message(message, timestamp=with_timestamps)
+ for line in lines:
+ self.built_lines.insert(index, line)
+ index +=1
+ break
+
def __del__(self):
log.debug('** TextWin: deleting %s built lines', (len(self.built_lines)))
del self.built_lines