##// END OF EJS Templates
encoding: fix trim() to be O(n) instead of O(n^2)...
Martin von Zweigbergk -
r49518:f1ed5c30 default
parent child Browse files
Show More
@@ -511,17 +511,21 b" def trim(s, width, ellipsis=b'', leftsid"
511 if width <= 0: # no enough room even for ellipsis
511 if width <= 0: # no enough room even for ellipsis
512 return ellipsis[: width + len(ellipsis)]
512 return ellipsis[: width + len(ellipsis)]
513
513
514 chars = list(u)
514 if leftside:
515 if leftside:
515 uslice = lambda i: u[i:]
516 chars.reverse()
516 concat = lambda s: ellipsis + s
517 width_so_far = 0
517 else:
518 for i, c in enumerate(chars):
518 uslice = lambda i: u[:-i]
519 width_so_far += ucolwidth(c)
519 concat = lambda s: s + ellipsis
520 if width_so_far > width:
520 for i in pycompat.xrange(1, len(u)):
521 break
521 usub = uslice(i)
522 chars = chars[:i]
522 if ucolwidth(usub) <= width:
523 if leftside:
523 return concat(usub.encode(_sysstr(encoding)))
524 chars.reverse()
524 return ellipsis # no enough room for multi-column characters
525 u = u''.join(chars).encode(_sysstr(encoding))
526 if leftside:
527 return ellipsis + u
528 return u + ellipsis
525
529
526
530
527 class normcasespecs(object):
531 class normcasespecs(object):
General Comments 0
You need to be logged in to leave comments. Login now