Changed algorithm for compactPath() slightly.

Sat, 12 Jun 2010 16:37:20 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 12 Jun 2010 16:37:20 +0200
changeset 343
f23d1272de6b
parent 342
360c4eb76d6c
child 344
3a1d9835e46b

Changed algorithm for compactPath() slightly.

Utilities/__init__.py file | annotate | diff | comparison | revisions
--- a/Utilities/__init__.py	Sat Jun 12 15:24:53 2010 +0200
+++ b/Utilities/__init__.py	Sat Jun 12 16:37:20 2010 +0200
@@ -596,11 +596,16 @@
     ellipsis = '...'
     
     head, tail = os.path.split(path)
-    while head:
-        path = os.path.join("%s%s" % (head, ellipsis), tail)
+    mid = len(head) // 2
+    head1 = head[:mid]
+    head2 = head[mid:]
+    while head1:
+        # head1 is same size as head2 or one shorter
+        path = os.path.join("%s%s%s" % (head1, ellipsis, head2), tail)
         if measure(path) <= width:
             return path
-        head = head[:-1]
+        head1 = head1[:-1]
+        head2 = head2[1:]
     path = os.path.join(ellipsis, tail)
     if measure(path) <= width:
         return path

eric ide

mercurial