]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Make `is_complex_subscript()` ignore list literals
authorŁukasz Langa <lukasz@langa.pl>
Sat, 9 Jun 2018 22:40:39 +0000 (15:40 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Sat, 9 Jun 2018 23:04:09 +0000 (16:04 -0700)
This fixes catastrophically quadratic behavior on long lists.

README.md
black.py

index 533a1f82f89e746b7b6540908e44de7215313e04..440f42b19b20c97e0e5b6ee3460b8ef65196c787 100644 (file)
--- a/README.md
+++ b/README.md
@@ -812,6 +812,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 * fixed improper formatting of f-strings with quotes inside interpolated
   expressions (#322)
 
 * fixed improper formatting of f-strings with quotes inside interpolated
   expressions (#322)
 
+* fixed unnecessary slowdown when long list literals where found in a file
+
+
 ### 18.6b2
 
 * added `--config` (#65)
 ### 18.6b2
 
 * added `--config` (#65)
index 35daaa9d634fa0d0a278014df7277ef56d1af1fc..a405bada1358344db949664afd3e041432554b9f 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1256,18 +1256,18 @@ class Line:
 
     def is_complex_subscript(self, leaf: Leaf) -> bool:
         """Return True iff `leaf` is part of a slice with non-trivial exprs."""
 
     def is_complex_subscript(self, leaf: Leaf) -> bool:
         """Return True iff `leaf` is part of a slice with non-trivial exprs."""
-        open_lsqb = (
-            leaf if leaf.type == token.LSQB else self.bracket_tracker.get_open_lsqb()
-        )
+        open_lsqb = self.bracket_tracker.get_open_lsqb()
         if open_lsqb is None:
             return False
 
         subscript_start = open_lsqb.next_sibling
         if open_lsqb is None:
             return False
 
         subscript_start = open_lsqb.next_sibling
-        if (
-            isinstance(subscript_start, Node)
-            and subscript_start.type == syms.subscriptlist
-        ):
-            subscript_start = child_towards(subscript_start, leaf)
+
+        if isinstance(subscript_start, Node):
+            if subscript_start.type == syms.listmaker:
+                return False
+
+            if subscript_start.type == syms.subscriptlist:
+                subscript_start = child_towards(subscript_start, leaf)
         return subscript_start is not None and any(
             n.type in TEST_DESCENDANTS for n in subscript_start.pre_order()
         )
         return subscript_start is not None and any(
             n.type in TEST_DESCENDANTS for n in subscript_start.pre_order()
         )