From a516e78bcf76f07545310332290b6c5443d437a7 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 9 Mar 2011 04:56:53 +0100 Subject: Some optimizations in build_new_message. Also cleaned up. Added an optimized way to do "wcswidth(string) > n": wcsislonger. And should use less memory because the dict replacing Message and Lines object stores ONLY the needed attributes. --- src/wcwidth.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/wcwidth.py') diff --git a/src/wcwidth.py b/src/wcwidth.py index b72c3ca3..bb0c456e 100644 --- a/src/wcwidth.py +++ b/src/wcwidth.py @@ -233,6 +233,22 @@ def wcswidth(s): width += w return width +def wcsislonger(s, l): + """ + Returns the same result than "wcswidth(s) > l" but + is faster. + """ + width = 0 + for c in s: + w = wcwidth(c) + if w < 0: + return -1 + else: + width += w + if width > l: + return True + return False + def widthcut(s, m): """ Return the first characters of s that can be contained in -- cgit v1.2.3