summaryrefslogtreecommitdiff
path: root/src/wcwidth.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-03-09 04:56:53 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-03-09 04:56:53 +0100
commita516e78bcf76f07545310332290b6c5443d437a7 (patch)
treea6935bf25d6ff2344efc546fa8c4aed48693620e /src/wcwidth.py
parent1a2252b3e5f902eea19b5f295812c9f9a0686815 (diff)
downloadpoezio-a516e78bcf76f07545310332290b6c5443d437a7.tar.gz
poezio-a516e78bcf76f07545310332290b6c5443d437a7.tar.bz2
poezio-a516e78bcf76f07545310332290b6c5443d437a7.tar.xz
poezio-a516e78bcf76f07545310332290b6c5443d437a7.zip
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.
Diffstat (limited to 'src/wcwidth.py')
-rw-r--r--src/wcwidth.py16
1 files changed, 16 insertions, 0 deletions
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